A sandbox 2D physics kinematics engine that simulates gravity, momentum, and collisions in real-time. Built with OCaml using the Core and Async libraries, with graphics rendering via OCaml Graphics.
The engine uses a timestep system that advances the simulation in discrete steps (default: 0.001s). Each timestep processes collision reactions, updates object velocities based on forces, and then updates positions. User interactions are handled through event-driven input listeners that asynchronously wait for mouse clicks and button events, allowing seamless object creation, dragging, and UI control without blocking the physics simulation loop.
Core Physics
vector.mli- 2D vector operations and transformationsunits.mli- conversions between pixel coordinates and physics unitsobjects.mli- object types (Ball, Box, Line, Cup) with position, velocity, and physics propertiesforce.mli- force representation for applying physics effects to objectscollisions.mli- collision detection between objects (ball-ball, ball-line, ball-cup, etc.)reactions.mli- collision response handling and reaction effectsstep.mli- physics simulation time step execution
User Interface
click_state.mli- tracks user interaction state (creating objects, dragging, selecting)click_interactions.mli- handles mouse click events and user inputpanel.mli- UI components (buttons and text boxes)canvas.mli- bounded area for managing and rendering physics objectsinterface.mli- combines panel and canvas into a unified interface
Simulation Runtime
world_state.mli- simulation status tracking (In_progress, Paused, Clear, Failure)world_graphics.mli- graphics initialization and rendering systemworld.mli- main world container combining state, interface, and interaction handlingrun.mli- main entry point that starts the simulation





