Loops question
in
Programming Questions
•
6 months ago
I'm in an intro to programming class and I'm having a difficult time figuring this out. The question reads,
"Make a window that is 200 by 200 with a white background. Set the frame rate to 15 frames per second. Your program will draw an “X” made of circles, centered atmust may use either a
"Make a window that is 200 by 200 with a white background. Set the frame rate to 15 frames per second. Your program will draw an “X” made of circles, centered at
(mouseX, mouseY)
, as shown in the diagram below at the left. Each square in the diagram represents ten pixels. The gray circle represents the mouse position. In your program, make all the circles the same color (white is a reasonable choice). You
while
loop or a
for
loop for this program. Save this sketch with the name
circles."
- void setup(){
size(200,200);
frameRate(15);
}
void draw(){
background(255);
int x = mouseX;
int y = mouseY;
int space = 10;
ellipseMode(CENTER);
for(int circle = -30; circle <= 30; circle++)
{
ellipse(x - 30,y - 30,10,10);
ellipse(x,y,10,10);
x = x + space;
y = y + space;
}
}
I'm not quite sure on how to create the X and to make it follow the mouse at the same time. All I get is a diagonal row of circles that extend endlessly that follow the mouse.
1