bouncing ball
in
Programming Questions
•
2 years ago
I'm stumped in trying to tweak this code into returning the ball from the left edge of the screen, instead of the middle of the ball off screen. Can anyone point me in the right direction of how manipulate the x variable to make that happen?
int diam = 30; // the diameter of our ellipse
int diam2 = 15;
int x = 0; //center the ellipse
int y = 0; //center the ellipse
int speed = 5;
void setup(){
size(300, 300);
smooth();
noStroke();
}
void draw(){
background(255);
fill(255, 0, 0);
ellipse(x, 150, diam, diam);
x = x + speed;
if((x + 15 > width) || (x < 5)){
speed = speed * -1;
}
}
1