Generating an ellipse once per section instead of every draw loop.
in
Programming Questions
•
2 years ago
I'm trying to make it so that the ellipse jumps to a random spot (within its constraints) when mouseX is within a certain location, although a new ellipse is generated every draw loop. I'm sure it's probably something simple that I'm missing, but is there some way to have it so that it only generates one ellipse when mouseX is within that section rather than one for every draw loop?
Here's the code, and thanks a ton for the help!
- float x1, y1;
- void setup()
- {
- size(960,640);
- smooth();
- ellipseMode(CENTER);
- }
- void draw()
- {
- background(0);
- noStroke();
- fill(255);
- ellipse(x1,y1,10,10);
- if(mouseX > 0 && mouseX < 73)
- {
- x1 = random(0,220);
- y1 = random(140,504);
- }
- else if(mouseX > 73 && mouseX < 147)
- {
- x1 = random(73,294);
- y1 = random(140,504);
- }
- }
1