Random circles controlled by keypress

Hey guys, I am working on a code and I am stuck. The idea is for the random circles to stop when you press a key if not continue working until it stops. There’s an image running in the background. Eventually I want to turn it into a video game. but for now I just need help with this simple code.

PImage desert;

boolean button = false; 
float r;
float g;
float b;
float a;

float diam;
float x;
float y;



void setup() {
  size(987, 496);
  smooth();
  desert = loadImage ("desert.jpg");
}



void draw () {
  
  
  
  image (desert, 0, 0);
  tint (258,142);

  r = random(235);
  g = random(255);
  b = random (255);
  a = random (255);
  diam = random (125);
  x = random (width);
  x = random (width);
  y = random (height);
  y = random (height);
  noStroke();
  fill(r, g, b, a);
  ellipse(x, y, diam, diam);
}

hi, good start

-a- please edit your title to something meaningful
-b- please put you code in the code tag

</>

-c- yes, you need to use your

boolean button = false;

like

boolean button = true;
//...
void draw(){
  if ( button ) random_circles();
//...
}

void keyPressed() {
 if ( key == 'h' ) button = !button; 
}
2 Likes

Thank you for the help! I’m new to the forum so I’ll make sure I do better at posting

1 Like

Hi Jon,

I edited your post to format the code and title – in the future when somebody asks you to make changes or provide more information, you can just click the pencil icon to do it yourself.

Were you able to get it working? If not, what, specifically, is not working for you – what step are you stuck on?