Slowing down the while loop
in
Programming Questions
•
1 year ago
Hi, I'm relatively new to processing (ok, I'm completely new) and I'm not even sure that that is how you would word that question. Anyhow, I am wanting to draw the rectangles in my program at a slower rate in the while loop, instead of instantaneously (or so it looks to the naked eye) Is there a way to do that? I have been reading the forums for a couple of hours trying to find a solution to no avail. Thank you for any help you can give me!
Here is my code. (sorry it doesn't have notes yet...)
//Kat
int w, h, x, y;
color black;
color white;
void setup()
{
black = color(0);
white = color(255);
background(black);
w=800;
h=800;
x=10;
y=10;
size (w,h);
}
void draw()
{
noFill();
strokeWeight(2);
stroke(white);
rect (x, y, w-20, h-20);
}
void keyPressed()
{
if (keyPressed){
if (key == CODED){
if (keyCode == DOWN){
while(x<400)
{
x=x+10;
y=y+10;
w=w-20;
h=h-20;
noFill();
strokeWeight(2);
stroke(white);
rect(x,y,w-20, h-20);
x=x+10;
y=y+10;
w=w-20;
h=h-20;
x++;
y++;
w--;
h--;
}
}
else{
fill(black);
}
}
}
}
1