-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
85 lines (67 loc) · 2.33 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>WebGL 3D Scene</title>
<style>
body {
margin: 0;
overflow: hidden;
}
canvas {
display: block;
}
</style>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/110/three.min.js"></script>
<script>
// Setup scene, camera, and renderer
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x808082); // Gray background
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.z = 4;
camera.position.x = 0;
camera.position.y = 1;
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// Lights
const blueLight = new THREE.DirectionalLight(0x87c8e8, 1);
blueLight.position.set(-1, 322, 1);
scene.add(blueLight);
// Create a black sphere in the center
const sphereGeometry = new THREE.SphereGeometry(0.5, 32, 32);
const sphereMaterial = new THREE.MeshBasicMaterial({ color: 0x000000 }); // Black
const sphere = new THREE.Mesh(sphereGeometry, sphereMaterial);
scene.add(sphere);
// Create three colored cubes at different Z-levels
const createCube = (color, x, y, z) => {
const geometry = new THREE.BoxGeometry();
const material = new THREE.MeshBasicMaterial({ color });
const cube = new THREE.Mesh(geometry, material);
cube.position.set(x, y, z);
scene.add(cube);
};
createCube(0x0000ff, -2, 0, -1); // Blue cube
createCube(0xff000f, 2, 0, 0); // Red cube
createCube(0xffa500, 0, 2, 1); // Orange cube
createCube(0xf4a5f0, 2, 2, 1); // Orange cube
// Animation loop
function animate() {
requestAnimationFrame(animate);
// Add some rotation to make the scene dynamic
sphere.rotation.y += 0.01;
renderer.render(scene, camera);
}
animate();
// Adjust canvas on window resize
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
</script>
</body>
</html>