Back

Show HN: Vanilla JavaScript refinery simulator built to explain job to my kids

39 points2 hoursfuelingcuriosity.com

Hi HN, I’m a chemical engineer and I manage logistics at a refinery down in Texas. Whenever I try to explain downstream operations to people outside the industry (including my kids), I usually get blank stares. I wanted to build something that visualizes the concepts and chemistry of a plant without completely dumbing down the science, so I put together this 5-minute browser game.

Here's a simple runthrough: https://www.youtube.com/watch?v=is-moBz6upU. I pushed to get through a full product pathway to show the V-804 replay.

I am not a software developer by trade, so I relied heavily on LLMs (Claude, Copilot, Gemini) to help write the code. What started as a simple concept turned into a 9,000-line single-page app built with vanilla HTML, CSS, and JavaScript. I used Matter.js for the 2D physics minigames.

A few technical takeaways from building this as a non-dev: * Managing the LLM workflow: Once the script.js file got large, letting the models output full file rewrites was a disaster (truncations, hallucinations, invisible curly-quote replacements that broke the JS). I started forcing them to act like patch files, strictly outputting "Find this exact block" and "Replace with this exact block." This was the only way to maintain improvements without breaking existing logic.

* Mapping physics to CSS: I wanted the minigames to visually sit inside circular CSS containers (border-radius: 50%). Matter.js doesn't natively care about your CSS. Getting the rigid body physics to respect a dynamic, responsive DOM boundary across different screen sizes required running an elliptical boundary equation (dx * dx) / (rx * rx) + (dy * dy) / (ry * ry) > 1 on every single frame. Maybe this was overkill to try to handle the resizing between phones and PCs.

* Mobile browser events: Forcing iOS Safari to ignore its default behaviors (double-tap zoom, swipe-to-scroll) while still allowing the user to tap and drag Matter.js objects required a ridiculous amount of custom event listener management and CSS (touch-action: manipulation; user-select: none;). I also learned that these actions very easily kill the mouse scroll making it very frustrating for PC users. I am hoping I hit a good middle ground.

* State management: Since I didn't use React or any frameworks, I had to rely on a global state object. Because the game jumps between different phases/minigames, I ran into massive memory leaks from old setInterval loops and Matter.js bodies stacking up. I had to build strict teardown functions to wipe the slate clean on every map transition.

The game walks through electrostatic desalting, fractional distillation, hydrotreating, catalytic cracking, and gasoline blending (hitting specific Octane and RVP specs).

It’s completely free, runs client-side, and has zero ads or sign-ups. I'd appreciate any feedback on the mechanics, or let me know if you manage to break the physics engine. Happy to answer any questions about the chemical engineering side of things as well.

For some reason the URL box is not getting recognized, maybe someone can help me feel less dumb there too. https://fuelingcuriosity.com/game

ecshafer6 minutes ago

Great little education game. Sulpher particles move really fast, might be worth slowing them down 20%. I was basically random clicking to get them.

fuelingcurious4 minutes ago

Fair point, I have a rebound energy and terminal velocity set, still lower the top speed! Thanks for the feedback.

fuelingcurious2 hours ago

Hello y’all as the post says, certainly a novice stepping into y’all’s space, but I am passionate that we can use the newest form of coding to allow us to change the way we teach. I think it’s a different way to use AI to teach, not having it explicitly do the teaching, but a way to extract context from different backgrounds into more fun learning tools.

insin2 hours ago

Phase 1b: The Desalter doesn't show anything on the grid in Firefox (v148.0.2), so you automatically lose.

fuelingcurious2 hours ago

Ah interesting, I have playtested on safari, chrome, and edge. I’ll have to look into what’s unique there. Thank you!

cameron_b1 hour ago

Up-to-date Firefox on Linux allowed me to complete certification of a shipment of Jet fuel, no trouble all the way through.

Great concept and execution.

fuelingcurious1 hour ago

Hurray! Thank you for the update note. I was going to get after it tonight after I put the kids to bed otherwise.

superxpro127 minutes ago

On Win11 Firefox latest (148.0.2), I still cant see them :\

You owe me nothing! I just wanted to let you know!

zbuttram2 hours ago

Great to see a spiritual successor to SimRefinery[1] after all these years!

[1] https://en.wikipedia.org/wiki/SimRefinery

fuelingcurious2 hours ago

I’ll take the compliment! My goal was to keep each unit to simple tap and drag play dynamics. If there’s another curiosity, mechanical, electrical, another unit, I can add it to the development plans. It’s fun for our family!

Tacite2 hours ago

It's very good and you can be proud. Your kids should be too!

fuelingcurious2 hours ago

Thank you! They call themselves my play testers and ask to see if I have added anything new almost daily for the last week or so. I have a bonus level for the SRU I’m trying to perfect.

TheGamerUncle2 hours ago

Hi sorry do you have the code for this I have been delaying to work on something like this but would love to use this as boilerplate.

fuelingcurious1 hour ago

Hello! Thank you for the vote of confidence! I deliberately left the client-side JavaScript un-obfuscated (AI showed me how to do it, but then I undid it for posting here). A colleague of mine started talking about selling it as a training tool, but ha I don’t know if that is in the cards. If you send me an email, we can talk about helping you get a head start!

bcze56bbn85423 minutes ago

Thanks I really liked it and it taught me a lot

fuelingcurious20 minutes ago

Great! Anything uniquely unexpected?

sealthedeal1 hour ago

This is awesome

fuelingcurious1 hour ago

Love it! Hopefully you learned something too!

bcze56bbn85423 minutes ago

Great jobb!