I have a sketch (see below) where a ball moves. When I tested it, everything seems to work but now the ball has gone off the screen to the right somewhere. How do I get my ball back?
Ball[] balls = new Ball[1];
void setup() {
size(400, 400);
balls[0] = new Ball(40, 127); // diameter and colour
}
void draw() {
background(255);
for (int i = 0; i < balls.length; i++) {
balls[i].display();
balls[i].move();
}
}
class Ball {
float dia;
float x;
float y;
float col;
float xspeed;
float yspeed;
float r;
Ball (float tempD, float tempC) {
x = random(0+dia, width-dia);
y = random(0+dia, height-dia);
dia = tempD;
col = tempC;
r = dia/2;
xspeed = 1.0;
yspeed = 0.0;
}
void display() {
noStroke();
fill(col);
ellipse(x, y, dia, dia);
}
void move() {
x = x + xspeed;
y = y + yspeed;
}
}