

2.
// Bolita
float x = 0;
float y = 0;
float xspeed = 2.2;
float yspeed = 5.5;
float r = 50;
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 < 0)) {
// If the object reaches either edge, multiply speed by -1 to turn it around.
xspeed = xspeed * -1;
r = 50;
}
// Remember, || means "or."
if ((y > height) || (y < 0)) {
// If the object reaches either edge, multiply speed by -1 to turn it around.
yspeed = yspeed * -1;
r = 50;
}
// Display circle at x location
noStroke();
fill (128,0,255);
ellipse(x,y,r,r);
r = constrain(r-2,32,64);
}
No hay comentarios:
Publicar un comentario