kfahn commited on
Commit
555839d
1 Parent(s): c40c3fd

Create js/sketch.js

Browse files

Add p5 sketch.js to files

Files changed (1) hide show
  1. js/sketch.js +111 -0
js/sketch.js ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ let diameter = 15;
2
+ let joints = [];
3
+ let draggedJoint = null;
4
+
5
+ // function preload() {
6
+ // img = loadImage("keypoints.jpg");
7
+ // }
8
+
9
+ function setup() {
10
+ createCanvas(512, 512);
11
+ joints = createJoints();
12
+ }
13
+
14
+ function draw() {
15
+ background(29);
16
+ // background(img);
17
+
18
+ // add connections
19
+ strokeWeight(3);
20
+ stroke(127, 104, 127);
21
+ line(joints[0].x, joints[0].y, joints[1].x, joints[1].y);
22
+ stroke(0, 94, 255);
23
+ line(joints[0].x, joints[0].y, joints[2].x, joints[2].y);
24
+ stroke(255, 184, 0);
25
+ line(joints[1].x, joints[1].y, joints[2].x, joints[2].y);
26
+ stroke(255, 137, 0);
27
+ line(joints[0].x, joints[0].y, joints[3].x, joints[3].y);
28
+ stroke(255, 57, 38);
29
+ line(joints[3].x, joints[3].y, joints[4].x, joints[4].y);
30
+ stroke(255, 57, 38);
31
+ line(joints[3].x, joints[3].y, joints[4].x, joints[4].y);
32
+ stroke(0, 212, 255);
33
+ line(joints[4].x, joints[4].y, joints[5].x, joints[5].y);
34
+ stroke(0, 245, 240);
35
+ line(joints[5].x, joints[5].y, joints[6].x, joints[6].y);
36
+ stroke(100, 245, 240);
37
+ line(joints[3].x, joints[3].y, joints[7].x, joints[7].y);
38
+ stroke(200, 245, 240);
39
+ line(joints[7].x, joints[7].y, joints[8].x, joints[8].y);
40
+ stroke(0, 255, 178);
41
+ line(joints[8].x, joints[8].y, joints[9].x, joints[9].y);
42
+ stroke(127, 127, 104);
43
+ line(joints[3].x, joints[3].y, joints[10].x, joints[10].y);
44
+ stroke(150, 127, 126);
45
+ line(joints[10].x, joints[10].y, joints[11].x, joints[11].y);
46
+ stroke(197, 0, 254);
47
+ line(joints[11].x, joints[11].y, joints[12].x, joints[12].y);
48
+ stroke(122, 127, 221);
49
+ line(joints[12].x, joints[12].y, joints[13].x, joints[13].y);
50
+ stroke(104, 255, 0);
51
+ line(joints[13].x, joints[13].y, joints[14].x, joints[14].y);
52
+ stroke(198, 255, 0);
53
+ line(joints[11].x, joints[11].y, joints[15].x, joints[15].y);
54
+ stroke(198, 255, 100);
55
+ line(joints[15].x, joints[15].y, joints[16].x, joints[16].y);
56
+ stroke(198, 255, 200);
57
+ line(joints[15].x, joints[15].y, joints[16].x, joints[16].y);
58
+ stroke(198, 255, 255);
59
+ line(joints[16].x, joints[16].y, joints[17].x, joints[17].y);
60
+
61
+
62
+ // draw the joints
63
+ for (let i = 0; i < joints.length; i++) {
64
+ let j = joints[i];
65
+ strokeWeight(2);
66
+ stroke(0);
67
+ fill(255);
68
+ ellipse(j.x, j.y, diameter, diameter);
69
+
70
+ if (dist(j.x, j.y, mouseX, mouseY) < diameter / 2 && mouseIsPressed) {
71
+ fill(50);
72
+ j.x = mouseX;
73
+ j.y = mouseY;
74
+ }
75
+ }
76
+ // console.log(mouseX, mouseY);
77
+ }
78
+
79
+ function mouseDragged() {
80
+ if (draggedJoint) {
81
+ draggedJoint.x = mouseX;
82
+ draggedJoint.y = mouseY;
83
+ }
84
+ }
85
+
86
+ function mouseReleased() {
87
+ draggedJoint = null; // reset the draggedJoint variable
88
+ }
89
+
90
+ function createJoints() {
91
+ let points = [];
92
+ points.push(createVector(97, 114)); // 0
93
+ points.push(createVector(76, 84)); // 1
94
+ points.push(createVector(116, 86));
95
+ points.push(createVector(108, 220));
96
+ points.push(createVector(127, 282));
97
+ points.push(createVector(117, 373));
98
+ points.push(createVector(125, 438));
99
+ points.push(createVector(146, 299)); //7
100
+ points.push(createVector(133, 392));
101
+ points.push(createVector(147, 453)); // 9
102
+ points.push(createVector(136, 139));
103
+ points.push(createVector(425, 158)); // 11
104
+ points.push(createVector(382, 288));
105
+ points.push(createVector(392, 384)); // 13
106
+ points.push(createVector(392, 444)); // 14
107
+ points.push(createVector(408, 271));
108
+ points.push(createVector(416, 369));
109
+ points.push(createVector(417, 428));
110
+ return points;
111
+ }