-
Notifications
You must be signed in to change notification settings - Fork 952
/
Mover.pde
49 lines (40 loc) · 840 Bytes
/
Mover.pde
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
// The Nature of Code
// Daniel Shiffman
// http://natureofcode.com
class Mover {
PVector position;
PVector velocity;
PVector acceleration;
float topspeed;
Mover() {
position = new PVector(width/2, height/2);
velocity = new PVector(0, 0);
acceleration = new PVector(-0.001, 0.01);
topspeed = 10;
}
void update() {
velocity.add(acceleration);
velocity.limit(topspeed);
position.add(velocity);
}
void display() {
stroke(0);
strokeWeight(2);
fill(127);
ellipse(position.x, position.y, 48, 48);
}
void checkEdges() {
if (position.x > width) {
position.x = 0;
}
else if (position.x < 0) {
position.x = width;
}
if (position.y > height) {
position.y = 0;
}
else if (position.y < 0) {
position.y = height;
}
}
}