Spaces:
Sleeping
Sleeping
Update static/script.js
Browse files- static/script.js +26 -38
static/script.js
CHANGED
@@ -95,20 +95,13 @@ function init() {
|
|
95 |
scene.add(gridHelper);
|
96 |
|
97 |
// Event listeners for controls
|
98 |
-
document.getElementById('start-btn').addEventListener('click',
|
99 |
-
|
100 |
-
|
101 |
-
});
|
102 |
-
|
103 |
-
document.getElementById('reset-btn').addEventListener('click', () => {
|
104 |
-
simulationRunning = false;
|
105 |
-
resetSimulation();
|
106 |
-
});
|
107 |
-
|
108 |
document.getElementById('save-btn').addEventListener('click', saveSettings);
|
109 |
document.getElementById('load-btn').addEventListener('click', loadSettings);
|
110 |
|
111 |
-
// Update
|
112 |
['sun', 'earth', 'mars'].forEach(body => {
|
113 |
document.getElementById(`${body}-mass`).addEventListener('input', updateParams);
|
114 |
document.getElementById(`${body}-x`).addEventListener('input', updateParams);
|
@@ -178,7 +171,25 @@ function updateParams() {
|
|
178 |
FLUID_DEFLECTION = parseFloat(document.getElementById('fluid-deflection').value);
|
179 |
}
|
180 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
181 |
function resetSimulation() {
|
|
|
|
|
|
|
|
|
182 |
fluidParticles.forEach(particle => {
|
183 |
particle.position.set(
|
184 |
(Math.random() - 0.5) * SPACE_SIZE,
|
@@ -192,36 +203,13 @@ function resetSimulation() {
|
|
192 |
);
|
193 |
});
|
194 |
|
195 |
-
// Reset positions and velocities
|
196 |
-
spheres[1].position.set(149.6e6 * DISTANCE_SCALE, 0, 0);
|
197 |
-
spheres[1].userData.velocity.set(0, 0, 29.8 * VELOCITY_SCALE);
|
198 |
-
spheres[2].position.set(227.9e6 * DISTANCE_SCALE, 0, 0);
|
199 |
-
spheres[2].userData.velocity.set(0, 0, 24.1 * VELOCITY_SCALE);
|
200 |
-
|
201 |
-
// Reset sliders to default values
|
202 |
-
document.getElementById('sun-mass').value = 1.989e30;
|
203 |
-
document.getElementById('sun-x').value = 0;
|
204 |
-
document.getElementById('sun-y').value = 0;
|
205 |
-
document.getElementById('sun-z').value = 0;
|
206 |
-
document.getElementById('earth-mass').value = 5.972e24;
|
207 |
-
document.getElementById('earth-x').value = 149.6e6;
|
208 |
-
document.getElementById('earth-y').value = 0;
|
209 |
-
document.getElementById('earth-z').value = 0;
|
210 |
-
document.getElementById('earth-orbital-velocity').value = 29.8;
|
211 |
-
document.getElementById('earth-centripetal').value = 1;
|
212 |
-
document.getElementById('mars-mass').value = 6.417e23;
|
213 |
-
document.getElementById('mars-x').value = 227.9e6;
|
214 |
-
document.getElementById('mars-y').value = 0;
|
215 |
-
document.getElementById('mars-z').value = 0;
|
216 |
-
document.getElementById('mars-orbital-velocity').value = 24.1;
|
217 |
-
document.getElementById('mars-centripetal').value = 1;
|
218 |
-
document.getElementById('fluid-friction').value = 0.9;
|
219 |
-
document.getElementById('fluid-deflection').value = 0.1;
|
220 |
-
|
221 |
updateParams();
|
|
|
|
|
|
|
222 |
}
|
223 |
|
224 |
-
// static/script.js (relevant excerpts for error handling)
|
225 |
function saveSettings() {
|
226 |
const settings = {
|
227 |
sun: {
|
|
|
95 |
scene.add(gridHelper);
|
96 |
|
97 |
// Event listeners for controls
|
98 |
+
document.getElementById('start-btn').addEventListener('click', startSimulation);
|
99 |
+
document.getElementById('stop-btn').addEventListener('click', stopSimulation);
|
100 |
+
document.getElementById('reset-btn').addEventListener('click', resetSimulation);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
document.getElementById('save-btn').addEventListener('click', saveSettings);
|
102 |
document.getElementById('load-btn').addEventListener('click', loadSettings);
|
103 |
|
104 |
+
// Update parameters when sliders change
|
105 |
['sun', 'earth', 'mars'].forEach(body => {
|
106 |
document.getElementById(`${body}-mass`).addEventListener('input', updateParams);
|
107 |
document.getElementById(`${body}-x`).addEventListener('input', updateParams);
|
|
|
171 |
FLUID_DEFLECTION = parseFloat(document.getElementById('fluid-deflection').value);
|
172 |
}
|
173 |
|
174 |
+
function startSimulation() {
|
175 |
+
// Update parameters to ensure the simulation uses the latest values
|
176 |
+
updateParams();
|
177 |
+
simulationRunning = true;
|
178 |
+
document.getElementById('status-message').textContent = 'Simulation started';
|
179 |
+
document.getElementById('status-message').style.color = '#4CAF50';
|
180 |
+
}
|
181 |
+
|
182 |
+
function stopSimulation() {
|
183 |
+
simulationRunning = false;
|
184 |
+
document.getElementById('status-message').textContent = 'Simulation stopped';
|
185 |
+
document.getElementById('status-message').style.color = '#F44336';
|
186 |
+
}
|
187 |
+
|
188 |
function resetSimulation() {
|
189 |
+
// Stop the simulation
|
190 |
+
simulationRunning = false;
|
191 |
+
|
192 |
+
// Reset fluid particles
|
193 |
fluidParticles.forEach(particle => {
|
194 |
particle.position.set(
|
195 |
(Math.random() - 0.5) * SPACE_SIZE,
|
|
|
203 |
);
|
204 |
});
|
205 |
|
206 |
+
// Reset sphere positions and velocities using current control values
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
207 |
updateParams();
|
208 |
+
|
209 |
+
document.getElementById('status-message').textContent = 'Simulation reset';
|
210 |
+
document.getElementById('status-message').style.color = '#2196F3';
|
211 |
}
|
212 |
|
|
|
213 |
function saveSettings() {
|
214 |
const settings = {
|
215 |
sun: {
|