1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| void setup()
{
size(300, 300);
stroke(255);
framerate(30);
}
float y = 100;
float x = 100;
float x1 = 115;
float y1 = 100;
float x2 = 100;
float y2 = 115;
float x3 = 115;
float y3 = 115;
float sensX = 1;
float sensY = 2;
void draw()
{
background(25);
y = y + (2*sensY);
x = x + (2*sensX);
y1 = y1 + (2*sensY);
x1= x1 + (2*sensX);
y2 = y2 + (2*sensY);
x2 = x2 + (2*sensX);
y3 = y3 + (2*sensY);
x3 = x3 + (2*sensX);
if ((x > width -15) || (x < 15)){
//inversion de la vitesse en x
sensX = -sensX;
}
if ((y > height - 15) || (y <15)){
//inversion de la vitesse en y
sensY = -sensY;
}
pushMatrix();
ellipse(x, y, 30, 30);
fill (68);
triangle(x1,y1, x2, y2, x3, y3);
popMatrix();
} |
Partager