forked from nature-of-code/noc-examples-p5.js-archived
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
56 lines (43 loc) · 850 Bytes
/
sketch.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
// The Nature of Code
// Daniel Shiffman
// http://natureofcode.com
// Bobs
let b1;
let b2;
let b3;
let s1;
let s2;
let s3;
function setup() {
createCanvas(640, 360);
// Create objects at starting position
// Note third argument in Spring constructor is "rest length"
b1 = new Bob(width / 2, 100);
b2 = new Bob(width / 2, 200);
b3 = new Bob(width / 2, 300);
s1 = new Spring(b1, b2, 100);
s2 = new Spring(b2, b3, 100);
s3 = new Spring(b1, b3, 100);
}
function draw() {
background(200);
s1.update();
s2.update();
s3.update();
s1.display();
s2.display();
s3.display();
b1.update();
b1.display();
b2.update();
b2.display();
b3.update();
b3.display();
b1.handleDrag(mouseX, mouseY);
}
function mousePressed() {
b1.handleClick(mouseX, mouseY);
}
function mouseReleased() {
b1.stopDragging();
}