Update index.html
Browse files- index.html +67 -67
index.html
CHANGED
@@ -1,88 +1,88 @@
|
|
1 |
<!DOCTYPE html>
|
2 |
<html lang="en">
|
3 |
-
|
4 |
-
<meta charset="UTF-8"
|
5 |
-
<
|
|
|
6 |
<style>
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
12 |
</style>
|
13 |
-
|
14 |
-
|
15 |
<!-- Load Three.js -->
|
16 |
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/
|
17 |
<!-- Load OrbitControls -->
|
18 |
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/
|
|
|
19 |
<script>
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
window.innerWidth / window.innerHeight,
|
27 |
-
0.1,
|
28 |
-
1000
|
29 |
-
);
|
30 |
-
camera.position.set(0, 50, 150);
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
document.body.appendChild(renderer.domElement);
|
36 |
|
37 |
-
|
38 |
-
|
|
|
|
|
|
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
|
|
|
|
|
43 |
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
const earth = new THREE.Mesh(earthGeometry, earthMaterial);
|
52 |
-
scene.add(earth);
|
53 |
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
const rocket = new THREE.Mesh(rocketGeometry, rocketMaterial);
|
58 |
-
scene.add(rocket);
|
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 |
</script>
|
87 |
-
|
88 |
</html>
|
|
|
1 |
<!DOCTYPE html>
|
2 |
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Rocket Orbiting Earth</title>
|
7 |
<style>
|
8 |
+
body {
|
9 |
+
margin: 0;
|
10 |
+
overflow: hidden;
|
11 |
+
background-color: black;
|
12 |
+
}
|
13 |
+
canvas {
|
14 |
+
display: block;
|
15 |
+
}
|
16 |
</style>
|
17 |
+
</head>
|
18 |
+
<body>
|
19 |
<!-- Load Three.js -->
|
20 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
|
21 |
<!-- Load OrbitControls -->
|
22 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/examples/js/controls/OrbitControls.js"></script>
|
23 |
+
|
24 |
<script>
|
25 |
+
// Create scene, camera, and renderer
|
26 |
+
const scene = new THREE.Scene();
|
27 |
+
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
|
28 |
+
const renderer = new THREE.WebGLRenderer();
|
29 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
30 |
+
document.body.appendChild(renderer.domElement);
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
+
// Add OrbitControls for interaction
|
33 |
+
const controls = new THREE.OrbitControls(camera, renderer.domElement);
|
34 |
+
controls.enableDamping = true; // Smooth movement
|
|
|
35 |
|
36 |
+
// Create Earth
|
37 |
+
const earthGeometry = new THREE.SphereGeometry(10, 32, 32);
|
38 |
+
const earthMaterial = new THREE.MeshStandardMaterial({ color: 0x2233ff });
|
39 |
+
const earth = new THREE.Mesh(earthGeometry, earthMaterial);
|
40 |
+
scene.add(earth);
|
41 |
|
42 |
+
// Create Rocket (small red sphere representing the spacecraft)
|
43 |
+
const rocketGeometry = new THREE.SphereGeometry(1, 16, 16);
|
44 |
+
const rocketMaterial = new THREE.MeshStandardMaterial({ color: 0xff0000 });
|
45 |
+
const rocket = new THREE.Mesh(rocketGeometry, rocketMaterial);
|
46 |
+
scene.add(rocket);
|
47 |
|
48 |
+
// Orbit parameters
|
49 |
+
const orbitRadius = 25; // Distance from Earth
|
50 |
+
const orbitSpeed = 0.002; // Orbit speed
|
51 |
|
52 |
+
// Lighting
|
53 |
+
const ambientLight = new THREE.AmbientLight(0xffffff, 0.3);
|
54 |
+
scene.add(ambientLight);
|
|
|
|
|
55 |
|
56 |
+
const pointLight = new THREE.PointLight(0xffffff, 1.2);
|
57 |
+
pointLight.position.set(50, 50, 50);
|
58 |
+
scene.add(pointLight);
|
|
|
|
|
59 |
|
60 |
+
// Set initial camera position
|
61 |
+
camera.position.set(0, 30, 50);
|
62 |
+
camera.lookAt(earth.position);
|
63 |
|
64 |
+
// Animation loop
|
65 |
+
function animate() {
|
66 |
+
requestAnimationFrame(animate);
|
67 |
|
68 |
+
// Update rocket position
|
69 |
+
const time = Date.now() * orbitSpeed;
|
70 |
+
rocket.position.x = orbitRadius * Math.cos(time);
|
71 |
+
rocket.position.z = orbitRadius * Math.sin(time);
|
72 |
+
rocket.position.y = 0; // Keep it at the same altitude
|
73 |
|
74 |
+
controls.update();
|
75 |
+
renderer.render(scene, camera);
|
76 |
+
}
|
77 |
|
78 |
+
animate();
|
79 |
|
80 |
+
// Handle window resizing
|
81 |
+
window.addEventListener("resize", () => {
|
82 |
+
camera.aspect = window.innerWidth / window.innerHeight;
|
83 |
+
camera.updateProjectionMatrix();
|
84 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
85 |
+
});
|
86 |
</script>
|
87 |
+
</body>
|
88 |
</html>
|