Now make a simulation of how a steam locomotive work. Make it interactive, fun and in a…
- User
Now make a simulation of how a steam locomotive work. Make it interactive, fun and in a way that can teach someone how it works, with parameters that they can change and see the difference
Assistant
Okay, let's create an interactive HTML simulation of a steam locomotive's workings. This will be a 2D diagram focus, as a realistic 3D simulation would be significantly more complex and beyond the scope of a simple HTML response.
We'll use HTML for the structure, CSS for styling and basic animations, and JavaScript to handle user interaction, simulation logic, and updating the visuals.
Key Concepts to Illustrate:
- Boiling Water: Heat (from fire) turns water into steam.
- Steam Pressure: Steam expands, creating pressure in the boiler.
- Throttle: Controls steam flow to the cylinders.
- Cylinders & Piston: Steam pushes the piston.
- Connecting Rods: Piston movement turns the wheels.
- Valve Gear (Simplified): Controls steam entry/exit to push the piston back and forth and change direction.
- Cutoff: Controls how long steam pushes the piston, affecting efficiency and power.
- Resource Management: Need fuel for fire and water for steam.
Interactive Parameters:
- Fire Intensity (Fuel): Controls heat output.
- Water Input: Controls water level.
- Throttle: Controls steam flow to cylinders.
- Cutoff: Controls steam expansion/efficiency.
- Direction: Forward/Reverse.
Visuals:
- Diagram showing boiler, firebox, cylinder, piston, rods, wheels.
- Animation of fire glow, piston movement, connecting rods, wheel rotation.
- Gauges for Boiler Pressure, Water Level, Speed.
- Visual effects for steam release (safety valve, chimney).
Here is the complete HTML code with embedded CSS and JavaScript:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Steam Locomotive Simulation</title> <style> :root { --gauge-color: #4CAF50; /* Green */ --danger-color: #f44336; /* Red */ --warning-color: #ff9800; /* Orange */ --safe-color: #2196F3; /* Blue */ --steam-color: rgba(255, 255, 255, 0.8); --fire-color: #ff5722; } body { font-family: 'Arial', sans-serif; margin: 0; padding: 0; background-color: #f0f0f0; color: #333; display: flex; min-height: 100vh; overflow-x: hidden; } .container { display: flex; width: 100%; max-width: 1400px; margin: 20px auto; background-color: #fff; box-shadow: 0 0 20px rgba(0, 0, 0, 0.1); border-radius: 8px; overflow: hidden; } .panel { width: 25%; padding: 20px; box-sizing: border-box; display: flex; flex-direction: column; border-right: 1px solid #ddd; background-color: #fafafa; } .right-panel { border-right: none; border-left: 1px solid #ddd; } .diagram-container { width: 50%; position: relative; background-color: #b0c4de; /* Sky blue background */ overflow: hidden; /* Hide parts that move outside */ } h2 { color: #555; border-bottom: 1px solid #ddd; padding-bottom: 10px; margin-bottom: 20px; text-align: center; } .control-group, .gauge-group { margin-bottom: 25px; } label { display: block; margin-bottom: 8px; font-weight: bold; color: #555; } input[type="range"] { width: 100%; -webkit-appearance: none; appearance: none; height: 8px; background: var(--safe-color); outline: none; opacity: 0.7; transition: opacity .2s; border-radius: 4px; } input[type="range"]:hover { opacity: 1; } input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 20px; height: 20px; background: var(--gauge-color); cursor: pointer; border-radius: 50%; } input[type="range"]::-moz-range-thumb { width: 20px; height: 20px; background: var(--gauge-color); cursor: pointer; border-radius: 50%; } select { width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 4px; font-size: 1em; background-color: white; } button { display: block; width: 100%; padding: 12px; background-color: var(--safe-color); color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 1em; transition: background-color 0.3s ease; } button:hover { background-color: #1a7bb9; } button:active { background-color: #1565c0; } /* Gauges and readouts */ .gauge { margin-bottom: 15px; background-color: #fff; border: 1px solid #ddd; padding: 10px; border-radius: 4px; } .gauge label { margin-bottom: 5px; font-size: 0.9em; color: #666; font-weight: normal; } .gauge-bar { width: 100%; height: 20px; background-color: #eee; border-radius: 4px; overflow: hidden; } .gauge-fill { height: 100%; width: 0%; /* controlled by JS */ background-color: var(--gauge-color); transition: width 0.1s linear; } .gauge-bar[data-level="warning"] .gauge-fill { background-color: var(--warning-color); } .gauge-bar[data-level="danger"] .gauge-fill { background-color: var(--danger-color); } .gauge-bar[data-level="safe"] .gauge-fill { background-color: var(--safe-color); } .gauge-value { margin-top: 5px; font-weight: bold; text-align: right; color: #555; } /* Diagram Elements */ .loco-part { position: absolute; transform-origin: center center; /* Default pivot */ } .boiler { width: 80%; height: 150px; background-color: #a9a9a9; /* Dark grey */ border: 5px solid #808080; border-radius: 75px / 150px; top: 80px; left: 10%; z-index: 5; } .firebox { width: 15%; height: 100px; background-color: #654321; /* Brown */ border: 5px solid #553311; border-bottom-left-radius: 15px; border-bottom-right-radius: 15px; bottom: 0px; left: calc(10% + 80% * 0.7); /* Position near rear of boiler */ z-index: 4; } .fire { position: absolute; bottom: 0; left: 5%; width: 90%; height: 30px; background: radial-gradient(circle, var(--fire-color) 0%, transparent 80%); animation: fire-glow 1s ease-in-out infinite alternate; opacity: 0; /* Controlled by JS */ } @keyframes fire-glow { 0% { transform: scaleY(1); opacity: 0.5; } 100% { transform: scaleY(1.5); opacity: 0.8; } } .smokestack { width: 8%; height: 70px; background-color: #444; border: 3px solid #333; border-bottom: none; border-top-left-radius: 10px; border-top-right-radius: 10px; top: 20px; left: calc(10% + 80% * 0.15); /* Position near front of boiler */ z-index: 6; } .steam-puff { position: absolute; width: 30px; height: 20px; background: var(--steam-color); border-radius: 50%; pointer-events: none; animation: steam-rise 3s ease-out forwards; opacity: 0; /* Controlled by JS */ z-index: 7; } @keyframes steam-rise { 0% { transform: translateY(0) scale(0.5); opacity: 1; } 100% { transform: translateY(-100px) scale(2); opacity: 0; } } .safety-valve-steam { position: absolute; width: 20px; height: 15px; background: var(--steam-color); border-radius: 50%; pointer-events: none; animation: safety-steam-burst 1s ease-out forwards; opacity: 0; /* Controlled by JS */ z-index: 7; top: 75px; /* Position near top of boiler */ left: calc(10% + 80% * 0.5); transform: translateX(-50%); } @keyframes safety-steam-burst { 0% { transform: translate(-50%, 0) scale(0.5); opacity: 1; } 100% { transform: translate(-50%, -50px) scale(1.5); opacity: 0; } } .cylinder { width: 12%; height: 60px; background-color: #777; border: 4px solid #555; border-radius: 10px; top: 190px; left: 5%; z-index: 8; transform-origin: right center; /* Pivot point for visual connection */ } .piston { width: 10%; /* Relative to cylinder width */ height: 40px; /* Relative to cylinder height */ background-color: #bbb; border: 2px solid #999; border-radius: 5px; position: absolute; /* Positioned within or relative to cylinder's logical space */ top: 10px; /* Relative to cylinder top */ left: 5px; /* Start position within cylinder */ transform-origin: center center; z-index: 9; /* Piston position is dynamic based on animation/JS */ } .connecting-rod { width: 40%; /* Example length */ height: 15px; background-color: #444; border: 2px solid #333; position: absolute; top: 220px; /* Align with piston rod */ left: calc(5% + 12% - 4px); /* Connects from cylinder end */ transform-origin: 0% 50%; /* Pivot at cylinder end */ z-index: 9; } .drive-rod { width: 25%; /* Example length */ height: 15px; background-color: #444; border: 2px solid #333; position: absolute; top: 220px; /* Align with connecting rod */ left: calc(5% + 12% - 4px + 40% * 0.9); /* Connects from connecting rod pin */ transform-origin: 0% 50%; /* Pivot at conn rod pin */ z-index: 9; } .wheel { width: 100px; height: 100px; background-color: #333; border: 5px solid #111; border-radius: 50%; bottom: 10px; z-index: 10; transform-origin: center center; /* Pivot at center */ } .front-wheel { left: 25%; } .rear-wheel { left: calc(25% + 100px + 50px); /* Example spacing */ } /* Animation classes */ .is-moving .connecting-rod { animation: connect-rod-motion var(--animation-duration) linear infinite; } .is-moving .drive-rod { animation: drive-rod-motion var(--animation-duration) linear infinite; } .is-moving .wheel { animation: wheel-spin var(--animation-duration) linear infinite; } .is-moving .piston { animation: piston-motion var(--animation-duration) linear infinite; } @keyframes wheel-spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } } /* Piston, Rod animations are complex 2D kinematics. Simplifying for visual effect. Realistically, needs calculated positions based on wheel angle. Using basic translation for piston and rotation for rods tied to speed. */ @keyframes piston-motion { 0%, 100% { transform: translateX(0); } /* Start/End of stroke */ 50% { transform: translateX(calc(12% - 10% - 10px)); } /* End/Start of stroke (Piston moves within Cylinder width minus its own width and padding) */ } /* Rod motion is even more complex. Let's tie their *visibility* and *basic rotation* to the speed and maybe direction, but not accurate kinematics in pure CSS. We'll let the JS handle basic rotation based on speed. */ .instructions { margin-top: 20px; padding-top: 15px; border-top: 1px solid #ddd; font-size: 0.9em; color: #666; } .instructions p { margin-bottom: 5px; } .simulation-message { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); background: rgba(0, 0, 0, 0.7); color: white; padding: 20px; border-radius: 8px; font-size: 1.2em; text-align: center; z-index: 20; pointer-events: none; opacity: 0; transition: opacity 0.5s ease-in-out; } .simulation-message.show { opacity: 1; } .gauge .value-text { font-weight: bold; margin-left: 5px; } </style> </head> <body> <div class="container"> <!-- Left Panel: Controls --> <div class="panel left-panel"> <h2>Locomotive Controls</h2> <div class="control-group"> <label for="fire-intensity">Fire Intensity (Fuel Input):</label> <input type="range" id="fire-intensity" min="0" max="100" value="20"> </div> <div class="control-group"> <label for="water-input">Water Input (Add Water):</label> <input type="range" id="water-input" min="0" max="100" value="0"> </div> <div class="control-group"> <label for="throttle">Throttle:</label> <input type="range" id="throttle" min="0" max="100" value="0"> </div> <div class="control-group"> <label for="cutoff">Cutoff:</label> <input type="range" id="cutoff" min="20" max="80" value="80"> <p style="font-size:0.8em; color:#777; margin-top:5px;">Lower % = More Efficient, Less Power at low speeds. Higher % = More Power, Less Efficient.</p> </div> <div class="control-group"> <label for="direction">Direction:</label> <select id="direction"> <option value="forward">Forward</option> <option value="reverse">Reverse</option> </select> </div> <div class="control-group"> <button id="whistle-button">Blow Whistle</button> </div> <div class="instructions"> <p><strong>How it Works:</strong></p> <p>1. Burn fuel (Fire Intensity) to heat water.</p> <p>2. Water turns to steam, increasing Boiler Pressure.</p> <p>3. Open Throttle to send steam to cylinders.</p> <p>4. Steam pushes Piston, turning wheels (Speed).</p> <p>5. Manage Water Level - too low = DANGER! (Simulation ends).</p> <p>6. Too much pressure? Safety valve will open automatically.</p> </div> </div> <!-- Center: Locomotive Diagram --> <div class="diagram-container" id="diagram-container"> <!-- Background and static parts --> <div class="loco-part boiler"></div> <div class="loco-part firebox"> <div class="fire"></div> </div> <div class="loco-part smokestack"></div> <div class="loco-part cylinder"> <!-- Piston is logically inside the cylinder --> <div class="loco-part piston" id="piston"></div> </div> <div class="loco-part wheel front-wheel"></div> <div class="loco-part wheel rear-wheel"></div> <!-- Moving parts (positioned and rotated by JS/CSS) --> <div class="loco-part connecting-rod" id="connecting-rod"></div> <div class="loco-part drive-rod" id="drive-rod"></div> <!-- Dynamic effects --> <div class="simulation-message" id="sim-message"></div> </div> <!-- Right Panel: Gauges --> <div class="panel right-panel"> <h2>Gauges & Status</h2> <div class="gauge-group"> <div class="gauge"> <label>Boiler Pressure:</label> <div class="gauge-bar" id="pressure-gauge-bar"> <div class="gauge-fill"></div> </div> <div class="gauge-value"><span id="pressure-value">0</span> PSI</div> </div> <div class="gauge"> <label>Water Level:</label> <div class="gauge-bar" id="water-gauge-bar"> <div class="gauge-fill"></div> </div> <div class="gauge-value"><span id="water-level-value">100</span> %</div> </div> <div class="gauge"> <label>Speed:</label> <div class="gauge-bar" id="speed-gauge-bar"> <div class="gauge-fill"></div> </div> <div class="gauge-value"><span id="speed-value">0</span> MPH</div> </div> <div class="gauge"> <label>Status:</label> <div class="gauge-value" id="status-message" style="text-align: center; font-weight: normal;">Ready</div> </div> </div> </div> </div> <script> // --- Simulation State Variables --- let simulationRunning = true; // Can be stopped on failure let fireIntensity = 20; // 0-100 let waterInput = 0; // 0-100 (rate of adding water) let waterLevel = 100; // 0-100 % let pressure = 0; // 0-Max PSI (simplified units) let throttle = 0; // 0-100 % let cutoff = 80; // 20-80 % let speed = 0; // 0-Max MPH (simplified units) let direction = 'forward'; // 'forward' or 'reverse' // --- Simulation Constants (Adjust for feel) --- const MAX_PRESSURE = 200; const SAFETY_VALVE_PRESSURE = 180; const BOILER_VOLUME = 100; // Arbitrary unit const WATER_CONSUMPTION_RATE = 0.005; // per steam flow unit const PRESSURE_GAIN_RATE = 0.005; // per fire intensity unit const MAX_SPEED = 60; const POWER_FACTOR = 0.02; // relates pressure/throttle/cutoff to power const FRICTION = 0.05; // Constant speed decay const WATER_INPUT_RATE = 0.1; // per water input slider value const MIN_WATER_LEVEL = 10; // % below which it's danger // --- DOM Elements --- const fireInput = document.getElementById('fire-intensity'); const waterInputSlider = document.getElementById('water-input'); const throttleInput = document.getElementById('throttle'); const cutoffInput = document.getElementById('cutoff'); const directionSelect = document.getElementById('direction'); const whistleButton = document.getElementById('whistle-button'); const pressureValueSpan = document.getElementById('pressure-value'); const waterLevelValueSpan = document.getElementById('water-level-value'); const speedValueSpan = document.getElementById('speed-value'); const statusMessageDiv = document.getElementById('status-message'); const pressureGaugeFill = document.querySelector('#pressure-gauge-bar .gauge-fill'); const waterGaugeFill = document.querySelector('#water-gauge-bar .gauge-fill'); const speedGaugeFill = document.querySelector('#speed-gauge-bar .gauge-fill'); const pressureGaugeBar = document.getElementById('pressure-gauge-bar'); const waterGaugeBar = document.getElementById('water-gauge-bar'); const speedGaugeBar = document.getElementById('speed-gauge-bar'); const diagramContainer = document.getElementById('diagram-container'); const fireElement = diagramContainer.querySelector('.fire'); const pistonElement = document.getElementById('piston'); const connectingRodElement = document.getElementById('connecting-rod'); const driveRodElement = document.getElementById('drive-rod'); const wheels = diagramContainer.querySelectorAll('.wheel'); const simMessageDiv = document.getElementById('sim-message'); // --- Event Listeners --- fireInput.addEventListener('input', (e) => fireIntensity = parseInt(e.target.value)); waterInputSlider.addEventListener('input', (e) => waterInput = parseInt(e.target.value)); throttleInput.addEventListener('input', (e) => throttle = parseInt(e.target.value)); cutoffInput.addEventListener('input', (e) => cutoff = parseInt(e.target.value)); directionSelect.addEventListener('change', (e) => direction = e.target.value); whistleButton.addEventListener('click', blowWhistle); // --- Simulation Logic --- function updateSimulation() { if (!simulationRunning) return; // --- Physics Simulation Steps --- // 1. Fire heats boiler -> Pressure increases if (fireIntensity > 0) { pressure += fireIntensity * PRESSURE_GAIN_RATE; } // 2. Steam flow depends on Pressure, Throttle, and Cutoff const steamFlow = (pressure / MAX_PRESSURE) * (throttle / 100) * (cutoff / 100) * BOILER_VOLUME * POWER_FACTOR; // 3. Steam flow -> Power and Water Consumption if (steamFlow > 0) { const power = steamFlow * pressure * POWER_FACTOR; speed += power; waterLevel -= steamFlow * WATER_CONSUMPTION_RATE; // Simulate steam puff from chimney proportional to steam flow (simplified) if (Math.random() < steamFlow / 50) { // Higher steam flow, more puffs createSteamPuff(); } } else { // If no steam flow, only friction slows down speed -= FRICTION; } // 4. Add Water Input waterLevel += waterInput * WATER_INPUT_RATE; // 5. Apply Friction (slows down even with power) speed -= FRICTION; // Apply friction constantly // --- Constraints & Safety --- // Cap pressure if (pressure > SAFETY_VALVE_PRESSURE) { // Safety valve opens, release excess pressure const excessPressure = pressure - SAFETY_VALVE_PRESSURE; pressure = SAFETY_VALVE_PRESSURE; // Cap pressure // Simulate pressure release - loses steam const releasedSteam = excessPressure * 0.1; // Releases 10% of 'excess' as steam waterLevel -= releasedSteam * WATER_CONSUMPTION_RATE; createSafetyValveSteam(); // Visual effect } if (pressure > MAX_PRESSURE) { // Hard cap/failure point if safety valve fails (simplified) pressure = MAX_PRESSURE; // Or trigger explosion logic } if (pressure < 0) pressure = 0; // Pressure can't be negative // Cap speed if (speed > MAX_SPEED) speed = MAX_SPEED; if (speed < 0) speed = 0; // Can't go backwards unless direction is reverse // Cap water level if (waterLevel > 100) waterLevel = 100; // --- Failure Conditions --- if (waterLevel < MIN_WATER_LEVEL && fireIntensity > 10) { triggerFailure("Low Water! Boiler Explosion!"); return; // Stop simulation } // Add other failure conditions (e.g., extreme pressure, components breaking) if desired // --- Update UI --- updateGauges(); updateDiagramAnimations(); updateStatus(); // Schedule next frame requestAnimationFrame(updateSimulation); } // --- UI Update Functions --- function updateGauges() { const pressurePercent = (pressure / MAX_PRESSURE) * 100; pressureGaugeFill.style.width = pressurePercent + '%'; pressureValueSpan.textContent = Math.round(pressure); if (pressure > SAFETY_VALVE_PRESSURE * 0.9) pressureGaugeBar.dataset.level = 'warning'; if (pressure >= SAFETY_VALVE_PRESSURE) pressureGaugeBar.dataset.level = 'danger'; else pressureGaugeBar.dataset.level = 'safe'; waterGaugeFill.style.width = waterLevel + '%'; waterLevelValueSpan.textContent = Math.round(waterLevel); if (waterLevel < MIN_WATER_LEVEL * 2) waterGaugeBar.dataset.level = 'warning'; if (waterLevel < MIN_WATER_LEVEL) waterGaugeBar.dataset.level = 'danger'; else waterGaugeBar.dataset.level = 'safe'; const speedPercent = (speed / MAX_SPEED) * 100; speedGaugeFill.style.width = speedPercent + '%'; speedValueSpan.textContent = Math.round(speed); speedGaugeBar.dataset.level = speed > MAX_SPEED * 0.5 ? 'warning' : 'safe'; // Example levels } function updateDiagramAnimations() { const currentSpeed = speed; // MPH const animationSpeedFactor = currentSpeed / 20; // Adjust divisor to map MPH to animation speed const animationDuration = animationSpeedFactor > 0 ? (1 / animationSpeedFactor) : 1000; // Shorter duration = faster animation diagramContainer.style.setProperty('--animation-duration', `${animationDuration}s`); // Toggle moving class const isMoving = currentSpeed > 1; diagramContainer.classList.toggle('is-moving', isMoving); fireElement.style.opacity = fireIntensity / 100; // Make fire visible based on intensity fireElement.style.animationDuration = `${1 + (100 - fireIntensity) / 50}s`; // Fire glows slower if less intense // Simple rod rotation tied to speed (kinematics are hard in plain CSS/JS) // Just rotate slightly based on speed for visual effect const rodRotation = currentSpeed * (direction === 'reverse' ? -0.5 : 0.5); // Arbitrary rotation based on speed/direction connectingRodElement.style.transform = `rotate(${rodRotation}deg)`; driveRodElement.style.transform = `rotate(${rodRotation}deg)`; // Piston position based on a simple sine wave tied to speed (very simplified) // A real piston position depends on wheel rotation angle and rod geometry const pistonPosition = Math.sin(Date.now() * animationSpeedFactor * 0.01) * (12/2 - 10/2 - 5/2); // Oscillate within cylinder space pistonElement.style.transform = `translateX(${pistonPosition}px)`; } function updateStatus() { if (waterLevel < MIN_WATER_LEVEL) { statusMessageDiv.textContent = "CRITICAL LOW WATER!"; statusMessageDiv.style.color = var('--danger-color'); } else if (pressure >= SAFETY_VALVE_PRESSURE) { statusMessageDiv.textContent = "Safety Valve Open!"; statusMessageDiv.style.color = var('--warning-color'); } else if (speed > 0) { statusMessageDiv.textContent = `Running ${direction.toUpperCase()}`; statusMessageDiv.style.color = var('--safe-color'); } else if (pressure > 0) { statusMessageDiv.textContent = "Steam Up"; statusMessageDiv.style.color = '#333'; } else { statusMessageDiv.textContent = "Cold"; statusMessageDiv.style.color = '#666'; } } // --- Effects --- function createSteamPuff() { const puff = document.createElement('div'); puff.classList.add('steam-puff'); const smokestack = diagramContainer.querySelector('.smokestack'); const stackRect = smokestack.getBoundingClientRect(); const containerRect = diagramContainer.getBoundingClientRect(); // Position puff at the top center of the smokestack relative to diagram container puff.style.left = `${(stackRect.left + stackRect.width / 2 - containerRect.left)}px`; puff.style.top = `${(stackRect.top - containerRect.top - 10)}px`; // Slightly above stack diagramContainer.appendChild(puff); // Remove puff after animation puff.addEventListener('animationend', () => { puff.remove(); }); } function createSafetyValveSteam() { const puff = document.createElement('div'); puff.classList.add('safety-valve-steam'); diagramContainer.appendChild(puff); // Remove puff after animation puff.addEventListener('animationend', () => { puff.remove(); }); } function blowWhistle() { if (pressure > 50) { // Only if enough pressure // In a real simulation, this would drain pressure/steam console.log("Whistle blown!"); // Add sound effect here // new Audio('whistle.mp3').play(); // Example requires audio file // Optionally, create a larger steam puff effect near the whistle location } else { console.log("Not enough pressure for whistle."); showMessage("Not enough pressure for whistle!", 1500); } } function showMessage(msg, duration) { simMessageDiv.textContent = msg; simMessageDiv.classList.add('show'); setTimeout(() => { simMessageDiv.classList.remove('show'); }, duration); } function triggerFailure(message) { simulationRunning = false; console.error("Simulation Failed:", message); showMessage(message, 5000); statusMessageDiv.textContent = "SIMULATION FAILED!"; statusMessageDiv.style.color = var('--danger-color'); // Stop animations more forcefully if needed diagramContainer.classList.remove('is-moving'); fireElement.style.opacity = 0; // Disable controls? } // --- Initial Setup --- function initSimulation() { // Start the simulation loop requestAnimationFrame(updateSimulation); updateGauges(); // Initial gauge update updateStatus(); // Initial status } initSimulation(); // Start everything when the page loads </script> </body> </html>How to Use:
- Save: Save the entire code block as an HTML file (e.g.,
loco_sim.html). - Open: Open the file in a modern web browser.
- Interact:
- Use the Fire Intensity slider to add fuel. See the fire glow in the firebox and watch the Boiler Pressure rise.
- Use the Water Input slider to add water. Maintain the Water Level! If it gets too low while the fire is hot, the simulation will stop with a "Boiler Explosion" message.
- Increase the Throttle. If there's enough pressure, steam will flow to the cylinder, the piston will move, and the wheels will start spinning, increasing Speed.
- Change the Cutoff. See how it affects speed gain at different throttle/pressure levels (the visual effect on the piston/rod movement is simplified, but the speed calculation reflects the efficiency/power change). Lower cutoff is more efficient (less water/steam used for the same power at higher speeds), higher cutoff provides more torque/power at lower speeds but is less efficient overall.
- Change the Direction. The wheels and piston animation should visually reverse.
- Click Blow Whistle (requires pressure).
- Watch the Gauges and Status message to monitor the locomotive's condition. See the safety valve steam puff if pressure gets too high.
Educational Aspects:
- Energy Flow: Fire -> Heat -> Steam Pressure -> Mechanical Movement (Piston/Wheels).
- Resource Management: Need fuel and water. Running out of water with a hot fire is dangerous.
- Control Valves: Throttle (flow rate) and Cutoff (expansion/efficiency) are key to controlling power and speed.
- Safety: The safety valve prevents over-pressurization.
Limitations (as a simple HTML/CSS/JS demo):
- 2D Diagram: Not a 3D model.
- Simplified Physics: The simulation uses simplified mathematical models for pressure gain, steam flow, power, friction, etc., not a precise thermodynamic/mechanical simulation.
- Simplified Animations: The piston and rod movements are approximations (using CSS
transformand basic JS control) rather than accurate kinematic linkages. The wheel rotation is a simple loop. - No Sound Effects: Added a placeholder for sound, but requires external audio files and more JS.
- No Complex Failures: Only a basic low-water explosion is included.
This simulation should be a fun and visual way for someone to grasp the fundamental principles behind how a steam locomotive converts heat into motion!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.