eaglelandsonce commited on
Commit
aa87502
·
verified ·
1 Parent(s): e4cc7ca

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +35 -11
index.html CHANGED
@@ -3,7 +3,7 @@
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>2D Rocket Launch and Orbit Simulation</title>
7
  <style>
8
  body { margin: 0; background-color: black; overflow: hidden; }
9
  canvas { display: block; }
@@ -34,23 +34,37 @@
34
  y: earth.y - earth.radius - 10, // Start above Earth
35
  radius: 5,
36
  velocityY: 0,
37
- velocityX: 0,
38
  isLaunching: false,
39
  inOrbit: false,
40
- orbitAngle: 0
 
41
  };
42
 
43
- // Launch Parameters
44
- const launchSpeed = -2.5; // Initial launch speed
45
  const gravity = 0.05; // Simulated gravity pulling rocket down
46
  const orbitSpeed = 0.02; // Speed in orbit
 
47
 
48
- // Listen for spacebar press to launch
 
 
49
  document.addEventListener("keydown", (event) => {
50
  if (event.code === "Space" && !rocket.isLaunching && !rocket.inOrbit) {
51
  rocket.isLaunching = true;
52
  rocket.velocityY = launchSpeed;
53
  }
 
 
 
 
 
 
 
 
 
 
 
54
  });
55
 
56
  // Animation loop
@@ -63,10 +77,10 @@
63
  ctx.arc(earth.x, earth.y, earth.radius, 0, Math.PI * 2);
64
  ctx.fill();
65
 
66
- // Rocket Launching Phase
67
  if (rocket.isLaunching && !rocket.inOrbit) {
68
  rocket.y += rocket.velocityY;
69
- rocket.velocityY += gravity; // Simulate gravity
70
 
71
  // Check if rocket reaches orbit height
72
  if (rocket.y < earth.y - 150) {
@@ -75,11 +89,21 @@
75
  rocket.orbitAngle = 0; // Reset angle for orbit
76
  }
77
  }
78
- // Orbit Phase
79
  else if (rocket.inOrbit) {
80
  rocket.orbitAngle += orbitSpeed;
81
- rocket.x = earth.x + 150 * Math.cos(rocket.orbitAngle);
82
- rocket.y = earth.y - 150 * Math.sin(rocket.orbitAngle);
 
 
 
 
 
 
 
 
 
 
83
  }
84
 
85
  // Draw Rocket
 
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>2D Rocket Launch with Expanding Orbit</title>
7
  <style>
8
  body { margin: 0; background-color: black; overflow: hidden; }
9
  canvas { display: block; }
 
34
  y: earth.y - earth.radius - 10, // Start above Earth
35
  radius: 5,
36
  velocityY: 0,
 
37
  isLaunching: false,
38
  inOrbit: false,
39
+ orbitAngle: 0,
40
+ orbitRadius: 80 // Initial small orbit
41
  };
42
 
43
+ // Launch & Orbit Parameters
44
+ const launchSpeed = -3.0; // Initial launch speed
45
  const gravity = 0.05; // Simulated gravity pulling rocket down
46
  const orbitSpeed = 0.02; // Speed in orbit
47
+ const orbitExpansionRate = 0.05; // Gradual orbit increase
48
 
49
+ let boosting = false; // Boost flag
50
+
51
+ // Listen for spacebar to launch
52
  document.addEventListener("keydown", (event) => {
53
  if (event.code === "Space" && !rocket.isLaunching && !rocket.inOrbit) {
54
  rocket.isLaunching = true;
55
  rocket.velocityY = launchSpeed;
56
  }
57
+
58
+ // Press "B" to boost the orbit distance
59
+ if (event.code === "KeyB" && rocket.inOrbit) {
60
+ boosting = true;
61
+ }
62
+ });
63
+
64
+ document.addEventListener("keyup", (event) => {
65
+ if (event.code === "KeyB") {
66
+ boosting = false;
67
+ }
68
  });
69
 
70
  // Animation loop
 
77
  ctx.arc(earth.x, earth.y, earth.radius, 0, Math.PI * 2);
78
  ctx.fill();
79
 
80
+ // 🚀 Launch Phase
81
  if (rocket.isLaunching && !rocket.inOrbit) {
82
  rocket.y += rocket.velocityY;
83
+ rocket.velocityY += gravity; // Apply gravity
84
 
85
  // Check if rocket reaches orbit height
86
  if (rocket.y < earth.y - 150) {
 
89
  rocket.orbitAngle = 0; // Reset angle for orbit
90
  }
91
  }
92
+ // 🛰️ Orbit Phase
93
  else if (rocket.inOrbit) {
94
  rocket.orbitAngle += orbitSpeed;
95
+
96
+ // Gradually increase orbit radius over time
97
+ rocket.orbitRadius += orbitExpansionRate;
98
+
99
+ // Apply boost for faster orbit increase
100
+ if (boosting) {
101
+ rocket.orbitRadius += 0.5;
102
+ }
103
+
104
+ // Calculate new position based on updated orbit
105
+ rocket.x = earth.x + rocket.orbitRadius * Math.cos(rocket.orbitAngle);
106
+ rocket.y = earth.y - rocket.orbitRadius * Math.sin(rocket.orbitAngle);
107
  }
108
 
109
  // Draw Rocket