CodeRigor

COURSE / REAL PRACTICE

Simulation

Build small physics and agent simulations in NumPy: stable integrators, flocking, slime trails, a spatial hash, particle fluid, smoke on a grid, cloth and rigid bodies. Every build is checked against conserved quantities, closed forms or brute force. Lessons pair with public videos by Sebastian Lague and Ten Minute Physics. Unofficial practice material, not affiliated with the videos’ authors.

Free to useLessons & exercises8 authored lessons3 units
Start with the first lesson.

Read the explanation and diagrams, then work through the practice. Your browser profile supplies your saved progress.

What you’ll work toward

Write simulations whose energy, momentum, density or constraints you can measure, and tell a stable method from one that only looks right.

Read an explanation, inspect the diagrams and work through the available checks, debugging exercises and builds. Feedback and prerequisite links guide the next step.

Before you start

This course builds on these skills:

Individual lessons can add prerequisites. Your lesson progress shows your actual readiness.

A look inside the first lesson

Integrators and energy

Python
def energy(x, v):
    return 0.5 * v * v + 0.5 * x * x       # k = m = 1

x, v, dt = 1.0, 0.0, 0.5
a = -x
v_new = v + a * dt
verlet_x = x + v * dt + 0.5 * a * dt * dt
verlet_v = v + 0.5 * (a + -verlet_x) * dt
print("explicit ", x + v * dt, v_new, energy(x + v * dt, v_new))
print("symplectic", x + v_new * dt, v_new, energy(x + v_new * dt, v_new))
print("verlet   ", verlet_x, verlet_v, round(energy(verlet_x, verlet_v), 5))

Your lesson sequence

Follow the same units and lessons in either view. Prerequisite links and your practice progress stay with each lesson.

UNIT 013 lessons Motion and agents
  1. LESSON 01.01

    Integrators and energy

    Step a spring with explicit Euler, symplectic Euler and velocity Verlet, watch their energy, measure their order, and run them from a fixed timestep.

    Open lesson
  2. LESSON 01.02

    Flocking from three rules

    Steer a flock with separation, alignment and cohesion, update every boid from the same old state, and test it on a wrapping torus.

    Open lesson
  3. LESSON 01.03

    Slime trails on a grid

    Agents sense a trail, steer toward it, move, deposit and let it diffuse and fade. Build each piece on a wrapping grid and test it against brute force.

    Open lesson
UNIT 023 lessons Fluids
  1. LESSON 02.01

    A spatial hash for neighbor search

    Sort points into a hashed grid with a counting sort, then answer radius queries and list every close pair by looking only at the cells around a point.

    Open lesson
  2. LESSON 02.02

    A particle fluid

    Turn particles into a fluid: smoothing kernels, density, pressure and viscosity forces that cancel in pairs, and a stepper with walls.

    Open lesson
  3. LESSON 02.03

    Smoke on a grid

    Make a staggered velocity grid divergence free with Gauss-Seidel around solid cells, carry smoke along it by tracing backward, and check the result against a direct pressure solve.

    Open lesson
UNIT 032 lessons Constraints and bodies
  1. LESSON 03.01

    Cloth with position constraints

    Hang a grid of particles on distance constraints, solve them by moving positions (XPBD), and prove the solver with exact single-edge, momentum and hanging-spring checks.

    Open lesson
  2. LESSON 03.02

    Capstone: rigid bodies that collide

    Build a small 2D rigid body engine: shoelace mass properties, separating axis contacts and impulses with spin and friction, checked by conservation laws.

    Open lesson

WATCH ALONG

Videos for these lessons

One hand-picked talk, lecture or tutorial per lesson, in course order. They play here when you press play; nothing loads from the video provider before that.

8 videos· 2 h 44 min

  1. 01Integrators and energy

  2. 02Flocking from three rules

    The video this lesson is paired with: the three rules of a boid, then obstacle avoidance and speeding the simulation up. Watch it first, then build the rules and the update step here and test them against a brute-force oracle.

  3. 03Slime trails on a grid

  4. 04A spatial hash for neighbor search

  5. 05A particle fluid

    A long build of a smoothed-particle fluid, from gravity and collisions through density, the pressure force, neighbour lookup, viscosity and a third dimension. Watch it first, then write a small 2D version of the same ideas here.

  6. 06Smoke on a grid

    A long walk through an Eulerian smoke simulation, with chapters on divergence, solving for pressure, Gauss-Seidel iteration, solid cells and semi-Lagrangian advection. Watch it first, then build the same pieces here and compare against a direct solve.

  7. 07Cloth with position constraints

    A short video on simulating cloth as particles joined by stretch constraints that are solved by moving positions, with chapters on stretchability and on finding neighbors. Watch it first for the overall picture.

  8. 08Capstone: rigid bodies that collide

    Covers rigid body properties and a position-based solver for contacts. This lesson uses velocity impulses instead, so watch it for the vocabulary of mass, inertia and contacts, then compare the two ways of resolving an overlap.