Ajout de deux exercices
This commit is contained in:
parent
43a6ffeac9
commit
27565541bc
41
boucing_ball_with_vector/boucing_ball_with_vector.pde
Normal file
41
boucing_ball_with_vector/boucing_ball_with_vector.pde
Normal file
@ -0,0 +1,41 @@
|
||||
class PVector {
|
||||
float x, y;
|
||||
|
||||
PVector(float x_, float y_) {
|
||||
x = x_;
|
||||
y = y_;
|
||||
}
|
||||
|
||||
void add(PVector other) {
|
||||
x += other.x;
|
||||
y += other.y;
|
||||
}
|
||||
}
|
||||
|
||||
PVector location;
|
||||
PVector velocity;
|
||||
|
||||
void setup() {
|
||||
size(640, 360);
|
||||
background(255);
|
||||
location = new PVector(100, 100);
|
||||
velocity = new PVector(1, 3.3);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(255);
|
||||
|
||||
location.add(velocity);
|
||||
|
||||
if ((location.x > width) || (location.x <= 0)) {
|
||||
velocity.x *= -1;
|
||||
}
|
||||
if ((location.y > height) || (location.y <= 0)) {
|
||||
velocity.y *= -1;
|
||||
}
|
||||
|
||||
stroke(0);
|
||||
fill(175);
|
||||
ellipse(location.x, location.y, 16, 16);
|
||||
|
||||
}
|
29
bouncing_ball/bouncing_ball.pde
Normal file
29
bouncing_ball/bouncing_ball.pde
Normal file
@ -0,0 +1,29 @@
|
||||
float x = 100;
|
||||
float y = 100;
|
||||
|
||||
float xspeed = 1;
|
||||
float yspeed = 3.3;
|
||||
|
||||
void setup() {
|
||||
size(640, 360);
|
||||
background(255);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(255);
|
||||
|
||||
x += xspeed;
|
||||
y += yspeed;
|
||||
|
||||
if ((x > width) || (x <= 0)) {
|
||||
xspeed *= -1;
|
||||
}
|
||||
if ((y > height) || (y <= 0)) {
|
||||
yspeed *= -1;
|
||||
}
|
||||
|
||||
stroke(0);
|
||||
fill(175);
|
||||
ellipse(x, y, 16, 16);
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user