forked from pouretrebelle/painting
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDot.pde
More file actions
68 lines (51 loc) · 1.3 KB
/
Dot.pde
File metadata and controls
68 lines (51 loc) · 1.3 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
class Dot {
PVector pos;
PVector vel;
color c;
float rotate;
float size;
float speed;
boolean righting;
Dot(int x, int y) {
// make position vector based on x,y coordinates
pos = new PVector(x, y);
// pick a random color
// take a random pretty hue
int hue = (hues[int(random(0, hues.length-1))])%360;
float sat = random(30, 50);
float bri = random(90, 100);
c = color(hue, sat, bri);
// pick a random size
size = random(50, 100);
// pick random rotation strength
rotate = random(0.05);
// pick a random speed or movement
speed = random(2, 5);
// create random velocity vector and set its speed
vel = PVector.random2D().setMag(speed);
// randomly chose left/right leaning
righting = (Math.random() < 0.5);
}
void update() {
// randomly change direction of rotation
if (Math.random() < 0.01) {
righting = !righting;
}
// rotate left or right based on righting
if (righting) {
vel.rotate(rotate);
} else {
vel.rotate(-rotate);
}
// add the velocity to the vector
pos.add(vel);
}
void render() {
fill(c);
ellipse(pos.x, pos.y, size, size);
}
void draw() {
update();
render();
}
}