-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
190 lines (170 loc) · 7.59 KB
/
Copy pathindex.html
File metadata and controls
190 lines (170 loc) · 7.59 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
```html
<!DOCTYPE html>
<html>
<head>
<title>Gymnast High Bar Animation</title>
<style>
body { margin: 0; overflow: hidden; }
#controls {
position: absolute;
top: 10px;
left: 10px;
background: rgba(255, 255, 255, 0.8);
padding: 10px;
}
canvas { width: 100%; height: 100%; }
</style>
</head>
<body><br><br>
<div id="controls">
<select id="moveSelect" multiple size="5">
<option value="swing">Basic Swing</option>
<option value="kip">Kip Up</option>
<option value="giant">Giant Swing</option>
<option value="release">Release Move</option>
</select>
<button onclick="playSequence()">Play Sequence</button>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r134/three.min.js"></script>
<script>
// Scene setup
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// Lighting
const ambientLight = new THREE.AmbientLight(0xffffff, 0.5);
scene.add(ambientLight);
const directionalLight = new THREE.DirectionalLight(0xffffff, 0.5);
directionalLight.position.set(0, 1, 1);
scene.add(directionalLight);
// High bar
const barGeometry = new THREE.CylinderGeometry(0.1, 0.1, 4, 32);
const barMaterial = new THREE.MeshBasicMaterial({ color: 0x808080 });
const bar = new THREE.Mesh(barGeometry, barMaterial);
bar.position.y = 3;
scene.add(bar);
// Gymnast body parts with muscle groups
const gymnast = new THREE.Group();
const defaultMaterial = new THREE.MeshPhongMaterial({ color: 0xaaaaaa });
const activeMaterial = new THREE.MeshPhongMaterial({ color: 0xff0000 });
// Torso
const torsoGeometry = new THREE.BoxGeometry(0.5, 1, 0.3);
const torso = new THREE.Mesh(torsoGeometry, defaultMaterial);
gymnast.add(torso);
// Arms
const armGeometry = new THREE.BoxGeometry(0.2, 0.8, 0.2);
const leftArm = new THREE.Mesh(armGeometry, defaultMaterial);
leftArm.position.set(-0.35, 0.3, 0);
gymnast.add(leftArm);
const rightArm = new THREE.Mesh(armGeometry, defaultMaterial);
rightArm.position.set(0.35, 0.3, 0);
gymnast.add(rightArm);
// Legs
const legGeometry = new THREE.BoxGeometry(0.2, 1, 0.2);
const leftLeg = new THREE.Mesh(legGeometry, defaultMaterial);
leftLeg.position.set(-0.15, -0.5, 0);
gymnast.add(leftLeg);
const rightLeg = new THREE.Mesh(legGeometry, defaultMaterial);
rightLeg.position.set(0.15, -0.5, 0);
gymnast.add(rightLeg);
scene.add(gymnast);
gymnast.position.y = 1.5;
// Camera controls
camera.position.set(0, 3, 5);
let isDragging = false;
let previousMousePosition = { x: 0, y: 0 };
renderer.domElement.addEventListener('mousedown', (e) => {
isDragging = true;
});
renderer.domElement.addEventListener('mousemove', (e) => {
if (isDragging) {
const deltaMove = {
x: e.clientX - previousMousePosition.x,
y: e.clientY - previousMousePosition.y
};
const rotationSpeed = 0.005;
gymnast.rotation.y += deltaMove.x * rotationSpeed;
camera.position.y += deltaMove.y * rotationSpeed;
previousMousePosition = { x: e.clientX, y: e.clientY };
}
});
renderer.domElement.addEventListener('mouseup', () => {
isDragging = false;
});
renderer.domElement.addEventListener('mousemove', (e) => {
previousMousePosition = { x: e.clientX, y: e.clientY };
});
// Animation sequences
const animations = {
swing: (t) => {
gymnast.rotation.z = Math.sin(t) * Math.PI/2;
leftArm.material = rightArm.material = Math.sin(t) > 0 ? activeMaterial : defaultMaterial; // Arms active
torso.material = defaultMaterial;
leftLeg.material = rightLeg.material = defaultMaterial;
},
kip: (t) => {
gymnast.rotation.z = Math.sin(t) * Math.PI;
torso.material = Math.sin(t) > 0 ? activeMaterial : defaultMaterial; // Core active
leftArm.material = rightArm.material = activeMaterial; // Arms always active
leftLeg.material = rightLeg.material = defaultMaterial;
},
giant: (t) => {
gymnast.rotation.z = t * Math.PI * 2;
leftArm.material = rightArm.material = activeMaterial; // Arms always active
torso.material = Math.abs(Math.sin(t)) > 0.5 ? activeMaterial : defaultMaterial; // Core intermittent
leftLeg.material = rightLeg.material = defaultMaterial;
},
release: (t) => {
gymnast.rotation.z = t * Math.PI * 4;
gymnast.position.y = 1.5 + Math.sin(t * Math.PI) * 2;
leftArm.material = rightArm.material = activeMaterial; // Arms always active
torso.material = activeMaterial; // Core always active
leftLeg.material = rightLeg.material = Math.sin(t) > 0 ? activeMaterial : defaultMaterial; // Legs intermittent
}
};
// Animation control
let sequence = [];
let currentMove = 0;
let time = 0;
let isPlaying = false;
function playSequence() {
sequence = Array.from(document.getElementById('moveSelect').selectedOptions).map(opt => opt.value);
currentMove = 0;
time = 0;
isPlaying = true;
resetMaterials();
}
function resetMaterials() {
torso.material = leftArm.material = rightArm.material =
leftLeg.material = rightLeg.material = defaultMaterial;
}
function animate() {
requestAnimationFrame(animate);
if (isPlaying && sequence.length > 0) {
time += 0.02;
const move = sequence[currentMove];
animations[move](time);
if (time >= 1) {
time = 0;
currentMove++;
if (currentMove >= sequence.length) {
isPlaying = false;
resetMaterials();
}
}
}
renderer.render(scene, camera);
}
animate();
// Window resize handler
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
</script>
</body>
</html>
```