Growing Circle

edited March 2017 in Questions about Code

Hey, I want a circle to grow per second and reach a limit. I don't want to set the framrate down, because it seems to affect the mousePressed section, which I also want to use. How can I make the circle grow step by step and then reset the count variable? Maybe I messed up a little..

int startTime;
float a=30;
float count;
boolean start=false;

void setup()
{
  size(800,800);
  background(0);
  startTime=millis()/1000;
}

void draw()
{
  println(count);
  if(start)
  {
      count=millis()/1000 - startTime;
      a=a+count*10;
  }
      if(a>=290);
    {
      start=false;
      //startTime=millis()/1000;

    }
ellipse(width/2,height/2,a,a);
 // println(a);
}

void mousePressed()
{
      start=true;
}
Tagged:

Answers

  • Edit your post and format your code selecting it and hitting ctrl+o. Also make sure there is an empty line above and below your code.

    Kf

  • aah thanks a lot

  • Answer ✓

    When do you want to reset your count variable? After the circle reaches certain size?

    CHECK you line 21... bug bug bug

    Kf

    final int initradius=30;
    final int endradius=600;
    
    int startTime;
    int rad=initradius;
    boolean start=false;
    
    void setup()
    {
      size(800, 800);
      startTime=millis();
    }
    
    void draw() {
      background(0);
    
      if (start) {
        if ((millis() - startTime) >=1000 ) {
          startTime=millis();
          rad=rad+10;
        }
      }
    
      if (rad>=endradius)
      {
        start=false;
      }
      ellipse(width/2, height/2, rad, rad);
    }
    
    void mousePressed()
    {
      start=!start;
    }
    
    void keyPressed() {
      rad=initradius;
    }
    
  • thank you soooo much. can you also explain me, how to resest the radius with a second click instead of a key after the endradius is reached?

  • Answer ✓

    First click stops. Second click reset radius and restarts the effect.

    void mousePressed() { start=!start;

    if(start==true) rad=initradius; }

    Kf

Sign In or Register to comment.