# Random circles controlled by keypress

**URL:** <https://discourse.processing.org/t/random-circles-controlled-by-keypress/6580>\
**Category:** Coding Questions\
**Created:** [December 13, 2018, 10:22pm UTC](https://discourse.processing.org/t/random-circles-controlled-by-keypress/6580 "2018-12-13T22:22:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonzamarripa](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jonzamarripa/32/3358_2.png) [@jonzamarripa](https://discourse.processing.org/u/jonzamarripa)\
**Post date:** [December 13, 2018, 10:22pm UTC](https://discourse.processing.org/t/random-circles-controlled-by-keypress/6580/1 "2018-12-13T22:22:39Z")

</div>

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.

```auto
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);
}

```

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [December 14, 2018, 2:15am UTC](https://discourse.processing.org/t/random-circles-controlled-by-keypress/6580/2 "2018-12-14T02:15:05Z")

</div>

hi, good start

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

```auto
</>

```

-c- yes, you need to use your

```auto
boolean button = false;

```

like

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

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

```

---

<div class="post-metadata">

**Author:** ![jonzamarripa](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jonzamarripa/32/3358_2.png) [@jonzamarripa](https://discourse.processing.org/u/jonzamarripa)\
**Post date:** [December 14, 2018, 2:56pm UTC](https://discourse.processing.org/t/random-circles-controlled-by-keypress/6580/3 "2018-12-14T14:56:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [December 17, 2018, 7:01pm UTC](https://discourse.processing.org/t/random-circles-controlled-by-keypress/6580/4 "2018-12-17T19:01:50Z")

</div>

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.

> [@jonzamarripa](#):
>
> but for now I just need help with this simple code.

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