I am trying to make the xspeed, and yspeed random, please help.
in
Programming Questions
•
1 month ago
int x;
int xspeed;
int y;
int yspeed;
void setup(){
size(500,500);
x=25;
y=250;
}
void draw() {
int r=random (-2,2);
yspeed=r;
xspeed=r;
if(x > width-25){
xspeed = xspeed*(-1);
}
if(x < width-475){
xspeed = xspeed *(-1);
}
if(y > height-25){
yspeed = yspeed *(-1);
}
if(y <height-475){
yspeed = yspeed *(-1);
}
x = x+xspeed;
y = y+yspeed;
background(255);
fill(#AA7DFE);
stroke(#0EE31A);
ellipse(x,y, 50,50);
}
1