Newer
Older
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
class Particle
{
PVector center;
PVector velocity;
float size;
float hue;
Particle(float x, float y)
{
center = new PVector(x, y);
velocity = new PVector(0, 0);
size = height * 0.7;
hue = random(255);
}
void damp(float factor)
{
velocity.mult(factor);
}
void integrate()
{
center.add(velocity);
}
void draw(float opacity)
{
tint(hue, 80, opacity);
blendMode(ADD);
image(dot, center.x - size/2, center.y - size/2, size, size);
}
void attract(PVector v, float coefficient)
{
PVector d = PVector.sub(v, center);
d.mult(coefficient / max(1, d.magSq()));
velocity.add(d);
}
}