-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdancingmonkey.html
More file actions
347 lines (310 loc) · 11.1 KB
/
dancingmonkey.html
File metadata and controls
347 lines (310 loc) · 11.1 KB
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>🐒 Dancing Monkey</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { background: #1a0a2e; overflow: hidden; font-family: sans-serif; }
canvas { display: block; }
#label {
position: fixed; bottom: 2rem; left: 50%; transform: translateX(-50%);
color: rgba(255,255,255,0.5); font-size: 0.85rem; letter-spacing: 0.15em;
text-transform: uppercase; pointer-events: none;
}
</style>
</head>
<body>
<div id="label">🐒 get down monkey</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<script>
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(60, innerWidth/innerHeight, 0.1, 100);
camera.position.set(0, 2, 6);
camera.lookAt(0, 1.5, 0);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.setPixelRatio(devicePixelRatio);
document.body.appendChild(renderer.domElement);
// Lights
const ambient = new THREE.AmbientLight(0xffffff, 0.4);
scene.add(ambient);
const spot = new THREE.SpotLight(0xff88ff, 2, 20, Math.PI/5, 0.3);
spot.position.set(3, 6, 4);
spot.castShadow = true;
scene.add(spot);
const spot2 = new THREE.SpotLight(0x88ffff, 1.5, 20, Math.PI/5, 0.3);
spot2.position.set(-3, 4, 2);
scene.add(spot2);
const disco = new THREE.PointLight(0xff2200, 3, 10);
scene.add(disco);
// Floor
const floorGeo = new THREE.CircleGeometry(4, 64);
const floorMat = new THREE.MeshStandardMaterial({ color: 0x220033, metalness: 0.6, roughness: 0.3 });
const floor = new THREE.Mesh(floorGeo, floorMat);
floor.rotation.x = -Math.PI/2;
floor.receiveShadow = true;
scene.add(floor);
// Helper: capsule-like limb from cylinder + spheres
function limb(rx, ry, rz, height, color) {
const g = new THREE.Group();
const mat = new THREE.MeshStandardMaterial({ color, roughness: 0.5, metalness: 0.1 });
const cyl = new THREE.Mesh(new THREE.CylinderGeometry(rx, rz, height, 12), mat);
g.add(cyl);
const top = new THREE.Mesh(new THREE.SphereGeometry(rx, 12, 12), mat);
top.position.y = height/2; g.add(top);
const bot = new THREE.Mesh(new THREE.SphereGeometry(rz, 12, 12), mat);
bot.position.y = -height/2; g.add(bot);
return g;
}
const FUR = 0x8B4513;
const FACE = 0xD2691E;
const DARK = 0x5C2D0A;
// ── BUILD MONKEY ──
const monkey = new THREE.Group();
scene.add(monkey);
// Body
const bodyGeo = new THREE.SphereGeometry(0.55, 16, 16);
bodyGeo.scale(1, 1.2, 0.9);
const body = new THREE.Mesh(bodyGeo, new THREE.MeshStandardMaterial({ color: FUR, roughness: 0.7 }));
body.position.y = 1.1;
body.castShadow = true;
monkey.add(body);
// Belly
const bellyGeo = new THREE.SphereGeometry(0.32, 12, 12);
bellyGeo.scale(1, 1.1, 0.7);
const belly = new THREE.Mesh(bellyGeo, new THREE.MeshStandardMaterial({ color: FACE, roughness: 0.8 }));
belly.position.set(0, 1.08, 0.35);
monkey.add(belly);
// Head
const head = new THREE.Group();
head.position.set(0, 1.85, 0);
monkey.add(head);
const headMesh = new THREE.Mesh(
new THREE.SphereGeometry(0.42, 16, 16),
new THREE.MeshStandardMaterial({ color: FUR, roughness: 0.7 })
);
head.add(headMesh);
// Face plate
const faceGeo = new THREE.SphereGeometry(0.28, 12, 12);
faceGeo.scale(1, 0.85, 0.6);
const faceMesh = new THREE.Mesh(faceGeo, new THREE.MeshStandardMaterial({ color: FACE, roughness: 0.8 }));
faceMesh.position.set(0, -0.06, 0.3);
head.add(faceMesh);
// Eyes
[-0.14, 0.14].forEach(x => {
const eye = new THREE.Mesh(new THREE.SphereGeometry(0.065, 10, 10),
new THREE.MeshStandardMaterial({ color: 0x111111 }));
eye.position.set(x, 0.1, 0.38);
head.add(eye);
const shine = new THREE.Mesh(new THREE.SphereGeometry(0.025, 8, 8),
new THREE.MeshStandardMaterial({ color: 0xffffff, emissive: 0xffffff }));
shine.position.set(x + 0.025, 0.12, 0.44);
head.add(shine);
});
// Nose
const nose = new THREE.Mesh(new THREE.SphereGeometry(0.07, 10, 10),
new THREE.MeshStandardMaterial({ color: DARK, roughness: 0.9 }));
nose.position.set(0, -0.03, 0.43);
nose.scale.set(1.2, 0.7, 0.8);
head.add(nose);
// Mouth (smile arc from torus)
const mouth = new THREE.Mesh(
new THREE.TorusGeometry(0.1, 0.018, 8, 16, Math.PI),
new THREE.MeshStandardMaterial({ color: DARK })
);
mouth.position.set(0, -0.16, 0.42);
mouth.rotation.z = Math.PI;
head.add(mouth);
// Ears
[-1, 1].forEach(side => {
const ear = new THREE.Mesh(new THREE.SphereGeometry(0.12, 10, 10),
new THREE.MeshStandardMaterial({ color: FUR, roughness: 0.7 }));
ear.position.set(side * 0.42, 0.05, 0);
ear.scale.set(0.6, 1, 0.5);
head.add(ear);
const innerEar = new THREE.Mesh(new THREE.SphereGeometry(0.07, 10, 10),
new THREE.MeshStandardMaterial({ color: FACE, roughness: 0.9 }));
innerEar.position.set(side * 0.46, 0.05, 0.04);
innerEar.scale.set(0.5, 0.8, 0.3);
head.add(innerEar);
});
// Hair tuft
for (let i = 0; i < 5; i++) {
const tuft = new THREE.Mesh(
new THREE.ConeGeometry(0.05, 0.18, 6),
new THREE.MeshStandardMaterial({ color: DARK })
);
tuft.position.set((i - 2) * 0.09, 0.42, 0.05);
tuft.rotation.z = (i - 2) * 0.15;
head.add(tuft);
}
// Arms (pivot at shoulder)
const leftArm = new THREE.Group();
leftArm.position.set(-0.55, 1.6, 0);
monkey.add(leftArm);
const lUpperArm = limb(0.1, 0.09, 0.09, 0.45, FUR);
lUpperArm.position.y = -0.22;
leftArm.add(lUpperArm);
const lForeArm = new THREE.Group();
lForeArm.position.y = -0.45;
leftArm.add(lForeArm);
const lFA = limb(0.09, 0.08, 0.08, 0.4, FUR);
lFA.position.y = -0.2;
lForeArm.add(lFA);
// Hand
const lHand = new THREE.Mesh(new THREE.SphereGeometry(0.1, 10, 10),
new THREE.MeshStandardMaterial({ color: FACE }));
lHand.position.set(0, -0.42, 0);
lForeArm.add(lHand);
const rightArm = new THREE.Group();
rightArm.position.set(0.55, 1.6, 0);
monkey.add(rightArm);
const rUpperArm = limb(0.1, 0.09, 0.09, 0.45, FUR);
rUpperArm.position.y = -0.22;
rightArm.add(rUpperArm);
const rForeArm = new THREE.Group();
rForeArm.position.y = -0.45;
rightArm.add(rForeArm);
const rFA = limb(0.09, 0.08, 0.08, 0.4, FUR);
rFA.position.y = -0.2;
rForeArm.add(rFA);
const rHand = new THREE.Mesh(new THREE.SphereGeometry(0.1, 10, 10),
new THREE.MeshStandardMaterial({ color: FACE }));
rHand.position.set(0, -0.42, 0);
rForeArm.add(rHand);
// Legs
const leftLeg = new THREE.Group();
leftLeg.position.set(-0.28, 0.7, 0);
monkey.add(leftLeg);
const lThigh = limb(0.13, 0.11, 0.11, 0.45, FUR);
lThigh.position.y = -0.22;
leftLeg.add(lThigh);
const lShin = new THREE.Group();
lShin.position.y = -0.45;
leftLeg.add(lShin);
const lS = limb(0.11, 0.09, 0.09, 0.4, FUR);
lS.position.y = -0.2;
lShin.add(lS);
const lFoot = new THREE.Mesh(new THREE.SphereGeometry(0.12, 10, 10),
new THREE.MeshStandardMaterial({ color: DARK }));
lFoot.scale.set(1.3, 0.7, 1.8);
lFoot.position.set(0, -0.42, 0.08);
lShin.add(lFoot);
const rightLeg = new THREE.Group();
rightLeg.position.set(0.28, 0.7, 0);
monkey.add(rightLeg);
const rThigh = limb(0.13, 0.11, 0.11, 0.45, FUR);
rThigh.position.y = -0.22;
rightLeg.add(rThigh);
const rShin = new THREE.Group();
rShin.position.y = -0.45;
rightLeg.add(rShin);
const rS = limb(0.11, 0.09, 0.09, 0.4, FUR);
rS.position.y = -0.2;
rShin.add(rS);
const rFoot = new THREE.Mesh(new THREE.SphereGeometry(0.12, 10, 10),
new THREE.MeshStandardMaterial({ color: DARK }));
rFoot.scale.set(1.3, 0.7, 1.8);
rFoot.position.set(0, -0.42, 0.08);
rShin.add(rFoot);
// Tail
const tailCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(0, 1.0, -0.5),
new THREE.Vector3(-0.4, 0.8, -0.8),
new THREE.Vector3(-0.7, 1.2, -0.6),
new THREE.Vector3(-0.6, 1.7, -0.3),
new THREE.Vector3(-0.3, 1.9, -0.1),
]);
const tailGeo = new THREE.TubeGeometry(tailCurve, 20, 0.055, 8, false);
const tail = new THREE.Mesh(tailGeo, new THREE.MeshStandardMaterial({ color: FUR, roughness: 0.8 }));
monkey.add(tail);
// Disco ball
const disco_ball = new THREE.Group();
disco_ball.position.set(0, 5, 0);
scene.add(disco_ball);
const dbGeo = new THREE.SphereGeometry(0.5, 16, 16);
const dbMat = new THREE.MeshStandardMaterial({ color: 0xffffff, metalness: 1, roughness: 0.1 });
disco_ball.add(new THREE.Mesh(dbGeo, dbMat));
// Tile lines
for (let i = 0; i < 12; i++) {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.5, 0.01, 4, 32),
new THREE.MeshStandardMaterial({ color: 0xdddddd, metalness: 1 })
);
ring.rotation.x = (i / 12) * Math.PI;
disco_ball.add(ring);
}
// Particles
const partGeo = new THREE.BufferGeometry();
const partCount = 300;
const positions = new Float32Array(partCount * 3);
const colors = new Float32Array(partCount * 3);
for (let i = 0; i < partCount; i++) {
positions[i*3] = (Math.random()-0.5) * 12;
positions[i*3+1] = Math.random() * 8;
positions[i*3+2] = (Math.random()-0.5) * 12;
const c = new THREE.Color().setHSL(Math.random(), 1, 0.6);
colors[i*3] = c.r; colors[i*3+1] = c.g; colors[i*3+2] = c.b;
}
partGeo.setAttribute('position', new THREE.BufferAttribute(positions, 3));
partGeo.setAttribute('color', new THREE.BufferAttribute(colors, 3));
const parts = new THREE.Points(partGeo, new THREE.PointsMaterial({ size: 0.06, vertexColors: true }));
scene.add(parts);
// Background stars
const bgGeo = new THREE.BufferGeometry();
const bgPos = new Float32Array(600 * 3);
for (let i = 0; i < 600; i++) {
bgPos[i*3] = (Math.random()-0.5) * 40;
bgPos[i*3+1] = Math.random() * 20;
bgPos[i*3+2] = (Math.random()-0.5) * 40 - 5;
}
bgGeo.setAttribute('position', new THREE.BufferAttribute(bgPos, 3));
scene.add(new THREE.Points(bgGeo, new THREE.PointsMaterial({ size: 0.04, color: 0xffffff, opacity: 0.5, transparent: true })));
window.addEventListener('resize', () => {
camera.aspect = innerWidth/innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
});
let t = 0;
function animate() {
requestAnimationFrame(animate);
t += 0.04;
// Body bounce
monkey.position.y = Math.abs(Math.sin(t * 2)) * 0.18;
monkey.position.x = Math.sin(t * 1.3) * 0.15;
// Body wiggle
monkey.rotation.y = Math.sin(t * 1.5) * 0.35;
body.rotation.z = Math.sin(t * 2) * 0.12;
// Head bobbing & side-to-side
head.rotation.z = Math.sin(t * 2.5) * 0.25;
head.rotation.y = Math.sin(t * 1.8) * 0.3;
head.position.y = 1.85 + Math.sin(t * 3) * 0.04;
// Arms dancing
leftArm.rotation.z = -0.3 + Math.sin(t * 2) * 0.9;
leftArm.rotation.x = Math.sin(t * 1.7 + 1) * 0.5;
lForeArm.rotation.z = Math.sin(t * 2.5) * 0.8;
rightArm.rotation.z = 0.3 - Math.sin(t * 2) * 0.9;
rightArm.rotation.x = Math.sin(t * 1.7) * 0.5;
rForeArm.rotation.z = -Math.sin(t * 2.5) * 0.8;
// Legs kicking
leftLeg.rotation.x = Math.sin(t * 2 + Math.PI) * 0.55;
lShin.rotation.x = Math.max(0, Math.sin(t * 2 + 1) * 0.7);
rightLeg.rotation.x = Math.sin(t * 2) * 0.55;
rShin.rotation.x = Math.max(0, Math.sin(t * 2 + 1 + Math.PI) * 0.7);
// Disco ball spin + color
disco_ball.rotation.y += 0.012;
const hue = (t * 0.1) % 1;
disco.color.setHSL(hue, 1, 0.5);
disco.position.set(Math.sin(t*0.8)*3, 1.5, Math.cos(t*0.8)*2);
spot.color.setHSL((hue + 0.33) % 1, 1, 0.5);
spot2.color.setHSL((hue + 0.66) % 1, 1, 0.5);
// Rotate particles slowly
parts.rotation.y += 0.003;
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>