-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
145 lines (125 loc) · 4.31 KB
/
index.html
File metadata and controls
145 lines (125 loc) · 4.31 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>3D Spinning Shapes</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Arial', sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
overflow: hidden;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
#canvas-container {
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
#info {
position: absolute;
top: 20px;
left: 50%;
transform: translateX(-50%);
color: white;
text-align: center;
z-index: 10;
text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
}
h1 {
font-size: 2.5rem;
margin-bottom: 10px;
font-weight: 300;
letter-spacing: 2px;
}
p {
font-size: 1rem;
opacity: 0.9;
}
</style>
</head>
<body>
<div id="info">
<h1>3D Animation</h1>
<p>Spinning Cube & Sphere</p>
</div>
<div id="canvas-container"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/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({ antialias: true, alpha: true });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x000000, 0);
document.getElementById('canvas-container').appendChild(renderer.domElement);
// Create cube
const cubeGeometry = new THREE.BoxGeometry(2, 2, 2);
const cubeMaterial = new THREE.MeshPhongMaterial({
color: 0x00ff88,
shininess: 100,
specular: 0x222222
});
const cube = new THREE.Mesh(cubeGeometry, cubeMaterial);
cube.position.x = -3;
scene.add(cube);
// Create sphere
const sphereGeometry = new THREE.SphereGeometry(1.5, 32, 32);
const sphereMaterial = new THREE.MeshPhongMaterial({
color: 0xff6b6b,
shininess: 100,
specular: 0x222222
});
const sphere = new THREE.Mesh(sphereGeometry, sphereMaterial);
sphere.position.x = 3;
scene.add(sphere);
// Add wireframe to cube
const cubeEdges = new THREE.EdgesGeometry(cubeGeometry);
const cubeLines = new THREE.LineSegments(
cubeEdges,
new THREE.LineBasicMaterial({ color: 0xffffff, linewidth: 2 })
);
cube.add(cubeLines);
// Lighting
const ambientLight = new THREE.AmbientLight(0xffffff, 0.5);
scene.add(ambientLight);
const pointLight1 = new THREE.PointLight(0xffffff, 1);
pointLight1.position.set(5, 5, 5);
scene.add(pointLight1);
const pointLight2 = new THREE.PointLight(0xffffff, 0.5);
pointLight2.position.set(-5, -5, -5);
scene.add(pointLight2);
// Camera position
camera.position.z = 8;
// Animation loop
function animate() {
requestAnimationFrame(animate);
// Rotate cube
cube.rotation.x += 0.01;
cube.rotation.y += 0.01;
// Rotate sphere
sphere.rotation.x += 0.005;
sphere.rotation.y += 0.01;
renderer.render(scene, camera);
}
// Handle window resize
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
// Start animation
animate();
</script>
</body>
</html>