Question on how to define a boolean

Hi, I am very new to coding and have a question regarding the code below. I’d like it to grow the circle with the count_up, but when one of the circles reaches the max width to go back again (in a way to loop the action) I was trying to make this happen witjh if…else but I don’t know how I should define the if so that it’s working.
Thank you so much in advance!!

int count_up = 0;
int count_down = 500;

void setup() 
{
  size(500, 500);
}

void draw() { 

  if ( count_up < width/2) {
  
fill(170, 172, 204, 150);
  circle(width/2, height/2, count_up);
  count_up += 1;
  
  fill(250, 191, 171, 100);
  circle(width/2, height/2, count_down);
  count_down -= 2;
  }
 else {
    fill(170, 172, 204, 150);
  circle(width/2, height/2, count_up);
  count_up -= 1;
  
  fill(250, 191, 171, 100);
  circle(width/2, height/2, count_down);
  count_down += 2;
  }
}

This is what the code is supposed to do but without growing indefinetly:

int count_up = 0;
int count_down = 500;

void setup() 
{
  size(500, 500);
}

void draw() { 
  background (233);
fill(170, 172, 204, 150);
  circle(width/2, height/2, count_up);
  count_up += 1;
 
  fill(250, 191, 171, 100);
  circle(width/2, height/2, count_down);
  count_down -= 2;
 
 }

You have two states: the count going up and the count going down. You need a variable to define these states, then you have to check for it to either count up or down.
Finally when your count reaches the minimum and the maximum of your counting, you have to switch.

You can use a boolean, which is just true or false, to record the two states.

1 Like