-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSegment.pde
More file actions
50 lines (42 loc) · 845 Bytes
/
Segment.pde
File metadata and controls
50 lines (42 loc) · 845 Bytes
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
/**********************************************\
*
* Andrey A. Ugolnik
* http://www.ugolnik.info
* andrey@ugolnik.info
*
\**********************************************/
class Segment
{
PVector a;
PVector b;
color col = color(55, 255, 55, 255);
float r = 5;
Segment(PVector v, color segColor)
{
a = new PVector(v.x, v.y);
b = new PVector(v.x, v.y);
col = segColor;
}
void follow(PVector target)
{
a.set(target);
float len = PVector.dist(a, b);
final float dist = r / sqrt(2);
if (len >= dist)
{
PVector v = PVector.sub(a, b);
v.setMag(dist);
v.mult(-1);
b = PVector.add(a, v);
}
}
void draw()
{
noStroke();
ellipseMode(RADIUS);
fill(0, 0, 0, 100);
ellipse(a.x, a.y, r * 1.3, r * 1.3);
fill(col);
ellipse(a.x, a.y, r, r);
}
}