Balle b1;
Balle b2;
void settings()
{
size(500,500);
}
void setup()
{
b1=new Balle();
b2 = new Balle();
}
void draw()
{
background(0,255,0);
b1.deplacer();
b1.rebondir();
b1.afficher();
b2.deplacer();
b2.rebondir();
b2.afficher();
}
class Balle
{
int rayon;
int x;
int y;
int dx;
int dy;
color couleur;
Balle()
{
rayon=20;
couleur=color(0, 0, 255);
x=width/2;
y=height/2;
dx=3;
dy=4;
}
Balle (int _dx, int _dy) {
rayon=20;
couleur=color(0, 0, 255);
x=width/2;
y=height/2;
dx=_dx;
dy= _dy;
}
void afficher()
{
fill(couleur);
ellipse(x, y, rayon*2, rayon*2);
}
void deplacer()
{
x=x+dx;
y=y+dy;
}
void rebondir()
{
if (x>= width-rayon)
{
dx=-dx;
}
if (x<=rayon)
{
dx=-dx;
}
if (y>= height-rayon)
{
dy=-dy;
}
if (y<=rayon)
{
dy=-dy;
}
}
}