-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcircle.pde
More file actions
70 lines (56 loc) · 1.25 KB
/
circle.pde
File metadata and controls
70 lines (56 loc) · 1.25 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
class Circle {
float x;
float y;
float r;
final float startSnapSpeed = 0.1;
float snapSpeed = 0.1;
final float snapAcc = 1.2;
float dX;
float dY;
final float momentumDecay = 0.98;
final float momentumMultiplier = 0.5;
boolean moveToDest;
float destX;
float destY;
Circle(float _x, float _y) {
x = _x;
y = _y;
r = 50;
moveToDest = false;
}
void show() {
fill(255);
ellipse(x,y,r*2,r*2);
fill(255,0,0);
ellipse(destX, destY, 5, 5);
}
void move() {
if (moveToDest) {
x -= (x - destX)*snapSpeed - dX*momentumMultiplier;
y -= (y - destY)*snapSpeed - dY*momentumMultiplier;
if (snapSpeed + snapAcc < 1) {
snapSpeed *= snapAcc;
}
dX *= momentumDecay;
dY *= momentumDecay;
if (dist(x, y, destX, destY) < 0.1) {
moveToDest = false;
snapSpeed = startSnapSpeed;
}
}
}
void setDestination(float _x, float _y) {
destX = _x;
destY = _y;
moveToDest = true;
}
void set(float _x, float _y) {
dX = _x-x;
dY = _y-y;
x = _x;
y = _y;
}
boolean within(float mx, float my) {
return (mx <= x + r) && (mx >= x - r) && (my <= y + r) && (my >= y - r);
}
}