-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNode.js
74 lines (63 loc) · 2.08 KB
/
Node.js
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
71
72
73
74
class Node {
// =============================================================
// /* constructor */
constructor(args) {
this.p = args.p || createVector(width / 2, height / 2);
this.r = args.r || 30;
this.id = args.id;
}
// =============================================================
// -------------------------------------------------------------
// /* setup */
// -------------------------------------------------------------
// /* draw loop */
draw() {
// draw node
push();
translate(this.p.x, this.p.y);
fill(0, 0, 255);
stroke(100);
circle(0, 0, 20);
// draw circle
stroke(70);
noFill();
circle(0, 0, this.r * 2);
// draw text of index
textSize(10);
noStroke()
fill(180);
textAlign(CENTER, CENTER);
text(this.id, 0, -18);
pop();
}
// -------------------------------------------------------------
// /* run loop */
run() {
}
// =============================================================
// -------------------------------------------------------------
// /* circle packing */
checkIntersec(pts) {
let p2pts = createVector(this.p.x - pts.p.x, this.p.y - pts.p.y, this.p.z - pts.p.z);
let distance = p2pts.mag();
if (distance < this.r + pts.r) {
let moveStep = -(distance - this.r - pts.r) / 7.0;
p2pts.normalize();
p2pts.mult(moveStep);
this.p = createVector(this.p.x + p2pts.x, this.p.y + p2pts.y, this.p.z + p2pts.z)
}
}
// /* if location inside node */
ifInside(x, y) {
let ifinside = false;
let dis = dist(this.p.x, this.p.y, x, y);
if (dis < 20) ifinside = true;
return ifinside;
}
// =============================================================
// /* mouse drag */
setPosition(mousex, mousey) {
this.p.x = mousex;
this.p.y = mousey;
}
}