Skip to content

Combustion engine: 41 parts, driven from the browser - #81

Merged
hovsep merged 1 commit into
mainfrom
claude/visual-combustion-engine-ke4peg
Oct 8, 2026
Merged

hovsep merged 1 commit into
mainfrom
claude/visual-combustion-engine-ke4peg

Conversation

@hovsep

@hovsep hovsep commented Oct 5, 2026

Copy link
Copy Markdown
Owner

Requested by ovsep · project thread

Before: the combustion engine was 12 components printing a dashboard line to the terminal while a scripted driver floored it until the tank ran dry.

After: it is 41 components, one per real part (camshaft and eight valves, fuel rail with injectors, throttle body, intake and exhaust manifolds, oxygen sensor, oil pump and pressure sensor, water pump, thermostat, radiator, cooling fan and coolant sensor, alternator, battery, fuse box, AC compressor, headlights, starter, ECU, cockpit, instrument cluster), and go run . serves a game-like page at http://localhost:8080. On the page pistons move, valves open, injectors spray, cylinders burn, the belt and fan spin and the exhaust glows. It also has gauges and warning lamps. You drive it yourself: hold ↑/W for the throttle or Space to floor it, I to start and stop, A for the AC, L for the lights, F to refuel, 1/2/3 for real time, ¼ speed or slow motion, and M for sound. Every control is also a button, and a hand throttle slider makes it work on a phone.

screenshot

The mesh is still the whole model. One trip around it is one stroke, the crankshaft's turn drives the next one, and the mesh still stops by itself when the engine does: key off, tank dry, stall, or a flat battery that only clicks.

How

  • One file per system (mechanical.go, breathing.go, cooling.go, electrical.go, control.go). Parts that need several flows per stroke wait for all of them with RequireInputs. Sensors arrive late in the stroke, so the ECU and the instrument cluster listen instead: they keep the latest reading in state. The accessory belt and the fuse box each work in two beats of one stroke. The fuse box tells the battery the load before the battery answers with volts, so a weak battery sags under the starter in the same stroke.
  • The outside world enters through one place. The page changes a mutex-guarded Driver, and the cockpit component reads it once per stroke. An AfterCycle hook paces the run to the wall clock and streams every part's State() as server-sent events. Only the standard library is used.
  • The page is a single web/index.html embedded with go:embed. It uses vanilla JS on an HTML5 canvas, with no build step and nothing loaded from the internet.
  • Tests cover: starting cold, fast idle, the rev limiter, warm idle at lambda 1, firing order 1-3-4-2, key-off spin-down, a flat battery that only clicks, a half-charged battery that starts, running out of fuel, the fan and thermostat holding a hot engine below overheat, and the AC raising the idle. A test hook also asserts that no input port ever holds two signals, so no part falls a stroke behind. Checked under -race and in Chromium at desktop and phone widths.
  • README rewritten; mesh graph regenerated.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Ggt9ptDN59sQDzu9a21DJP


Generated by Claude Code

The engine grows from 12 components to 41, one per real part: camshaft
and eight valves, fuel rail and injectors, throttle body and intake
manifold, exhaust manifold and oxygen sensor, oil pump, water pump,
thermostat, radiator, cooling fan and its sensor, alternator, battery,
fuse box, AC compressor, headlights, ECU, cockpit and instrument cluster.
The crankshaft's turn still drives every stroke, and the mesh still
stops by itself when the engine does.

The program now serves a self-contained canvas page (go:embed, standard
library only): the driver's pedal and switches go in over HTTP, every
part's state comes back as server-sent events. Throttle on the keyboard
(hold Up/W, Space to floor it), with on-screen buttons and a hand
throttle slider for touch.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ggt9ptDN59sQDzu9a21DJP
@hovsep hovsep self-assigned this Oct 5, 2026
@hovsep
hovsep merged commit 9252cde into main Oct 8, 2026
2 checks passed
@hovsep
hovsep deleted the claude/visual-combustion-engine-ke4peg branch October 8, 2026 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants