Help with moving rectangles
Answered
- Need more info
- Answered
- Working on it
in
Programming Questions
•
3 years ago
In my code i have several rectangles that run down the screen.
Each cycle increasing speed by 1 and randomly changing the color
id like the rectangles speed to slow down by 1 when it reaches a certain speed,
then speed back up once slowed to certain speed.
im having a lot of trouble and this is as far as ive gotten.
void setup() {
fill(0);
size(390,300);
}
void draw() {
background(c);
move();
display();
}
void move(){
x = x+speed;
if(x>height){
x=0;
fill(random(255),random(225),random(230));
}
x = x+speed;
if(x>height){
x=0;
speed=speed+1;
}
}
void display(){
noStroke();
rect(y,x-11,w,x1);
rect(y+32,x+1,w,x1);
rect(y+64,x+11,w,x1);
rect(y+96,x+21,w,x1);
rect(y+128,x+31,w,x1);
rect(y+160,x+41,w,x1);
rect(y+192,x+51,w,x1);
rect(y+224,x+61,w,x1);
rect(y+256,x+71,w,x1);
rect(y+288,x+81,w,x1);
rect(y+320,x+91,w,x1);
rect(y+352,x+101,w,x1);
}
Each cycle increasing speed by 1 and randomly changing the color
id like the rectangles speed to slow down by 1 when it reaches a certain speed,
then speed back up once slowed to certain speed.
im having a lot of trouble and this is as far as ive gotten.
- color c =(255);
- float x = 120;
- float y = 2;
- float speed = 3;
- float w = 30;
void setup() {
fill(0);
size(390,300);
}
void draw() {
background(c);
move();
display();
}
void move(){
x = x+speed;
if(x>height){
x=0;
fill(random(255),random(225),random(230));
}
x = x+speed;
if(x>height){
x=0;
speed=speed+1;
}
}
void display(){
noStroke();
rect(y,x-11,w,x1);
rect(y+32,x+1,w,x1);
rect(y+64,x+11,w,x1);
rect(y+96,x+21,w,x1);
rect(y+128,x+31,w,x1);
rect(y+160,x+41,w,x1);
rect(y+192,x+51,w,x1);
rect(y+224,x+61,w,x1);
rect(y+256,x+71,w,x1);
rect(y+288,x+81,w,x1);
rect(y+320,x+91,w,x1);
rect(y+352,x+101,w,x1);
}
1