-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask-dance.js
175 lines (120 loc) Β· 4.55 KB
/
task-dance.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
ALL_TASKS["dance"] = {
desc: "This does too many things, but is an example of what you could do",
// Add classifier options to do classification,
// or comment out for 5 sliders for continuous values
classifierOptions: ["π¦", "π¦π΄πΎ", "π¦π΅πΎ", "π"],
// How long you want to train for
// Find an accuracy that works for you
epochCount: 20,
modelDetails: {
model: "dance/model.json",
metadata: "dance/model_meta.json",
weights:
"https://cdn.glitch.global/94c4b6a1-03c7-41bb-b579-aa6780e9a47d/model.weights.bin?v=1670445397805",
},
preload(p) {
// Any extra asset loading
// free sound effects: https://freesound.org/
// Be sure to cite in your .md!
this.img = p.loadImage("https://cdn.glitch.global/94c4b6a1-03c7-41bb-b579-aa6780e9a47d/sharks.png?v=1670451985918");
this.reaction1 = p.loadImage("https://cdn.glitch.global/94c4b6a1-03c7-41bb-b579-aa6780e9a47d/dedtvm6-c376a50c-4cbd-4eb5-855e-2424e39762a4.png?v=1670457595094");
this.sharksong = p.loadSound("https://cdn.glitch.global/94c4b6a1-03c7-41bb-b579-aa6780e9a47d/PINKFONG_Baby_Shark_Dance_(thinkNews%20(mp3cut.net).mp3?v=1670454406023");
},
setup(p) {
// Do any setup work here
this.osc = new p5.Oscillator('sine');
// this.osc.start()
// this.osc.stop()
this.songtime = 0;
this.color = [100, 100, 80]
this.points = 10
this.timestamps= [10,18, 26,34,42];
},
onChangeLabel(hand, newLabel, oldLabel) {
console.log(this.sharksong.currentTime());
if (this.sharksong.currentTime() < this.timestamps[0] && newLabel == "π¦"){
p.image(this.reaction1,p.width/2-500,p.height/2-400);
}
if (this.sharksong.currentTime() < this.timestamps[1] && newLabel == "π¦π΄πΎ"){
console.log("great moves")
}
if (this.sharksong.currentTime() < this.timestamps[2] && newLabel == "π¦π΅πΎ"){
console.log("great moves")
}
if (this.sharksong.currentTime() < this.timestamps[3] && newLabel == "π"){
console.log("great moves")
}
// An event happened!
console.log(`Changed from ${oldLabel} to ${newLabel}` )
// Lots of options
// Change some state, play a sound,
// change some value....
// Make a theremin!
//this.sharksong.play()
// Play a sound
//Play a pitch-shifted sound
// if (newLabel === "π"){
// let pitch = (400 - hand.center[1])*.002 + 1
// this.pianoNote.play()
// this.pianoNote.rate(pitch)
// }
// Random color?
this.color = [360*Math.random(), 100, 50]
this.points++
},
draw(p, hands, face) {
this.sharksong.play()
p.background(240, 30, 60);
p.noStroke();
let t = p.millis()*.001;
for (var j = 0; j < 5; j++) {
p.fill(170 + j * 10, 70, 40, 0.3);
p.beginShape();
let y = 100;
p.vertex(0, 0);
p.vertex(0, 0);
p.vertex(0, y);
// Ripply vertices
let waveCount = 10;
for (var i = 0; i < waveCount; i++) {
let x = (i + 0.5) * (p.width / waveCount);
let y2 = y + 100 * p.noise(i, t + j * 10);
p.curveVertex(x, y2);
}
p.vertex(p.width, y);
p.vertex(p.width, 0);
p.vertex(p.width, 0);
p.endShape();}
p.image(this.img,p.width/2-250,p.height/2-200);
hands.forEach((hand) => {
p.stroke('white');
// Draw each hand
if (hand.isActive) {
// Test drawing
hand.points.forEach((pt) => p.circle(...pt, 10));
// hand.points.forEach((pt, index) => p.text(index, ...pt))
p.circle(...hand.center, 20);
hand.fingers.forEach((f, index) => {
let fingertip = f[3]
p.fill(index*40, 100, 50)
p.circle(...fingertip, 20)
})
let pitch = 400 - hand.center[1]
// console.log("Pitch", pitch)
this.osc.freq(pitch);
if (hand.prediction) {
// Use the label and uncertainty to draw
// console.log(hand.prediction);
let pred = hand.prediction;
p.textSize(pred.certainty ** 2 * 70);
p.text(pred.label, ...hand.center);
}
}
});
// Show text if you want!
p.fill("green");
p.text(this.points + " points", 350, 250);
},
track: "HAND",
// Options: "HAND", "HANDS", "HANDS AND FACE", "FACE"
};