Disclaimer: This simulation and its documentation were created with assistance from an AI coding agent.
Have you ever been sitting on a train, a freshly opened energy drink on the table, shaking back and forth, and wondered, "How much do I have to sip for this thing to become most resistant to the train’s lurches?" This project dives into that exact moment, simulating how different beverage fill levels change a can's resistance to side forces.
Showcase: A preview of the simulator is hosted at https://tipping-can.6A31.com.
This repository contains an interactive 2D physics playground (built with p5.js) that visualizes how the center of mass, train acceleration, and can geometry interact to determine when a can tips over. You can experiment with:
- Red Bull, Monster, and Cola can presets.
- Fill level, can dimensions, and empty-can mass.
- Train acceleration (horizontal force).
- Visualization layers such as force vectors, center of mass markers, and a stability graph.
- Auto-computed optimal fill level for maximum stability.
MathJax renders the governing formulas directly on the page so you can explore the physics in detail.
No special backend or build tooling is required—the experience is entirely static. If you want to run it locally, any static file server will do. One easy option (already used during development) is Python's built-in HTTP server:
# From the project root
python3 -m http.server 8000Then open your browser to http://localhost:8000 and enjoy tipping cans without the sticky cleanup.
.
├── index.html # Main UI markup and styles
├── sketch.js # p5.js physics + rendering code
├── README.md # You are here
- Center of Mass: Weighted average of the can and liquid mass distributions.
- Tipping Angle: Threshold angle where the center of mass passes over the can’s base edge.
- Critical Acceleration: Horizontal acceleration that aligns the net force with the pivot, triggering tip-over.
The simulator visualizes each of these elements so you can see exactly why certain fill levels are safer than others.
Issues and ideas are welcome, submit a pull request or open an issue describing the improvement you have in mind. Whether you want to add more beverage presets, extend the physics, or polish the visuals, your contributions are appreciated.
Enjoy experimenting, and keep those drinks upright! 🍾


