eaglelandsonce commited on
Commit
961c0dd
·
verified ·
1 Parent(s): f9393f0

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +67 -67
index.html CHANGED
@@ -1,88 +1,88 @@
1
  <!DOCTYPE html>
2
  <html lang="en">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <title>Rocket Orbiting Earth - Three.js Simulation</title>
 
6
  <style>
7
- body {
8
- margin: 0;
9
- overflow: hidden;
10
- background-color: black;
11
- }
 
 
 
12
  </style>
13
- </head>
14
- <body>
15
  <!-- Load Three.js -->
16
- <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r152/three.min.js"></script>
17
  <!-- Load OrbitControls -->
18
- <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r152/examples/js/controls/OrbitControls.js"></script>
 
19
  <script>
20
- // Initialize the scene
21
- const scene = new THREE.Scene();
22
-
23
- // Create camera
24
- const camera = new THREE.PerspectiveCamera(
25
- 75,
26
- window.innerWidth / window.innerHeight,
27
- 0.1,
28
- 1000
29
- );
30
- camera.position.set(0, 50, 150);
31
 
32
- // Create renderer
33
- const renderer = new THREE.WebGLRenderer({ antialias: true });
34
- renderer.setSize(window.innerWidth, window.innerHeight);
35
- document.body.appendChild(renderer.domElement);
36
 
37
- // Add OrbitControls for interactivity
38
- const controls = new THREE.OrbitControls(camera, renderer.domElement);
 
 
 
39
 
40
- // Add lighting
41
- const ambientLight = new THREE.AmbientLight(0xffffff, 0.3);
42
- scene.add(ambientLight);
 
 
43
 
44
- const pointLight = new THREE.PointLight(0xffffff, 1.2);
45
- pointLight.position.set(50, 50, 50);
46
- scene.add(pointLight);
47
 
48
- // Create Earth
49
- const earthGeometry = new THREE.SphereGeometry(30, 32, 32);
50
- const earthMaterial = new THREE.MeshPhongMaterial({ color: 0x2233ff });
51
- const earth = new THREE.Mesh(earthGeometry, earthMaterial);
52
- scene.add(earth);
53
 
54
- // Create Rocket (represented as a small red sphere)
55
- const rocketGeometry = new THREE.SphereGeometry(2, 16, 16);
56
- const rocketMaterial = new THREE.MeshPhongMaterial({ color: 0xff0000 });
57
- const rocket = new THREE.Mesh(rocketGeometry, rocketMaterial);
58
- scene.add(rocket);
59
 
60
- // Orbit parameters
61
- const orbitRadius = 50; // Distance from Earth
62
- const orbitSpeed = 0.005; // Speed of orbit
63
 
64
- // Animation loop
65
- function animate() {
66
- requestAnimationFrame(animate);
67
 
68
- // Update rocket position
69
- const time = Date.now() * 0.001; // Time in seconds
70
- rocket.position.x = orbitRadius * Math.cos(time * orbitSpeed);
71
- rocket.position.z = orbitRadius * Math.sin(time * orbitSpeed);
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>
 
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>