float x = 0;
float y = 0;
float xspeed = 2.2;
float yspeed = 1.5;
float r = 32;
void setup() {
size(200,200);
smooth();
}
void draw() {
background(255);
// Add the current speed to the x location.
x = x + xspeed;
y = y + yspeed;
// Remember, || means “or.”
if ((x > width) || (x height) || (y < 0)) {
// If the object reaches either edge, multiply speed by -1 to turn it around.
yspeed = yspeed * -1;
r = 64;
}
// Display circle at x location
stroke(0);
fill(175);
ellipse(x,y,r,r);
r = constrain(r-2,32,64);