Labs

Free interactive simulations of forces, flocking boids, fractals, cellular automata, genetic algorithms and neural networks. Play with them, evolve them, or build your own.

Randomness

  • Random Walkers — A random walk is the simplest model of motion: every frame the walker takes a step chosen by chance. Changing the probability distribution o
  • Distributions — Gather thousands of random numbers into a histogram and the shape of their distribution appears. Uniform comes out flat. Gaussian makes the
  • Perlin Noise Landscapes — Perlin noise gives a smooth sequence of pseudo-random values: nearby inputs give nearby outputs. Sampling it in 2D makes cloud-like textures
  • Self-Avoiding Walk — A random walker on a grid with one extra rule: it may never visit the same spot twice. That small constraint changes the statistics complete
  • Monte Carlo π — Randomness can compute things. Throw darts uniformly at a square that contains a circle. The fraction that lands inside approaches the ratio
  • Flying Over Noise Terrain — 2D Perlin noise read as a height map becomes a landscape. Each grid point's height is noise(x, z), and the grid is drawn in perspective: scr
  • Brownian Motion & Diffusion — Release thousands of random walkers from one point and the cloud diffuses. No walker is going anywhere, yet the cloud grows, and it grows in
  • Paint Your Own Distribution — The accept–reject method can sample any shape you like. Draw a curve in the top panel with the mouse. That curve is a probability density. E
  • Domain-Warped Noise — Noise can bend other noise. Instead of sampling noise(p), sample noise(p + 4·noise(p + 4·noise(p))): the coordinates themselves are pushed a
  • Maze Generation & Solving — The backtracking self-avoiding walk carves a perfect maze: every cell is reachable and there is exactly one path between any two cells. Here
  • Buffon's Needle — Another way to find π by chance, first posed in 1777. Drop needles of length l onto a floor of parallel lines spaced d apart. The probabilit
  • Procedural Noise Planet — Wrap noise around a sphere and you get a world. For each pixel of the disc we work out the 3D point on the sphere's surface, rotate it, and

Vectors

  • Vector Math Playground — A vector has a magnitude and a direction, stored as an (x, y) pair. Nearly every simulation in this lab is built on a few vector operations.
  • Motion 101: Acceleration — The core motion algorithm: velocity += acceleration, then position += velocity. Each object stores these three vectors, and velocity is capp
  • Reflection off Walls — The dot product in action. When a ball hits a wall with unit normal n, its velocity reflects: v′ = v − (1 + e)(v · n) n v · n measures how m
  • Matrices: Transforming Space — A 2×2 matrix [a b; c d] transforms every vector at once. The basis vector î = (1,0) lands on (a, c) (red) and ĵ = (0,1) lands on (b, d) (gre
  • Spaceship: Thrust & Rotation — Fly with the keyboard: ←/→ or A/D rotate, ↑ or W fires the engine, ↓ or S brakes. Thrust only adds an acceleration vector (cos θ, sin θ) × t
  • Laser & Mirrors (Ray Tracing) — Bouncing balls used the reflection formula once per collision. A light ray applies it again and again. From the laser we cast a ray, find th

Forces

  • Forces: Gravity, Wind, Friction & Drag — By Newton's second law, acceleration = force / mass. Each frame every force is added into the acceleration, then it is cleared. Gravity is s
  • Gravitational Attraction — Newton's law of universal gravitation: F = G·m₁·m₂ / d². Every body pulls on every other body (an n-body simulation), so orbits, slingshots
  • Elastic Collisions & Momentum — When two balls collide, the impulse acts along the line between their centres. Solving for it so that momentum Σ m·v is conserved (and kinet
  • The Three-Body Problem — Two bodies under gravity follow neat ellipses. Add a third and there is, in general, no closed-form solution, and the motion is often chaoti
  • Terminal Velocity & Parachutes — Falling objects speed up until air drag (which grows with v²) balances their weight. From then on they fall at a constant terminal velocity
  • Colliding Galaxies — A full n-body simulation of a galaxy is far too slow, but a classic trick from 1972 (the Toomre brothers) captures the essentials. Treat eac
  • Ideal Gas & Maxwell–Boltzmann — Give every particle in a box exactly the same speed. After a few collisions the speeds spread out into the Maxwell–Boltzmann distribution, t
  • Gravity Field & Potential — Instead of tracking bodies, look at the field they create. Every point in space has a gravitational potential (the colour map, dark = deep w

Oscillation

  • Pendulum Wave — A pendulum is angular motion driven by gravity: α = −(g / L)·sin(θ). Longer pendulums swing more slowly. Here every pendulum hangs from the
  • Springs (Hooke's Law) — Hooke's law: a spring pulls with force F = −k·x, where x is how far it is stretched past its rest length. Chain several springs together and
  • Oscillation & Waves — Simple harmonic motion follows a sine: y = A·sin(2π·x / λ + φ). Amplitude A sets the height, wavelength λ sets the spacing, and advancing th
  • Double Pendulum & Chaos — Hang a pendulum from a pendulum and the motion becomes chaotic: fully deterministic, yet impossible to predict over the long run. This exper
  • Pressure Soft Bodies (Jelly) — A soft body is a ring of point masses joined by springs, with a twist: the gas inside pushes outward. Each frame the enclosed area is comput
  • Fourier Epicycles — The previous demo added two sine waves. Fourier showed that any periodic signal is a sum of sines. In 2D that means any closed drawing can b
  • Harmonograph — A Victorian drawing machine. One pendulum moves the pen left–right, another moves it up–down (each is really two pendulums added together).
  • Coupled Oscillators & Normal Modes — Connect a row of masses with springs between two walls. Pluck one and the motion looks messy, but it is secretly a sum of normal modes: spec
  • Ripple Tank (2D Wave Equation) — The 1D waves earlier were drawn from a formula. Here they emerge from a rule applied to every cell of a grid, the wave equation: each cell a
  • Phase Space & Strange Attractors — Plot a pendulum not in space but in phase space: angle θ horizontally, angular velocity ω vertically. Each point is a complete state, and th
  • Soft-Body Lattices — The jelly blobs were hollow rings held up by pressure. A different approach fills the body with a lattice: a grid of point masses with struc
  • Fourier Series: Building Waves — The 1D version of epicycles. A square wave is the sum of odd harmonics (4/π)·[sin t + sin 3t/3 + sin 5t/5 + …]. Each harmonic is a rotating

Particle Systems

  • Particle Emitters — A particle system manages many short-lived objects. Each frame an emitter spawns new particles, applies forces to all of them, and removes t
  • Fireworks: Systems of Systems — A firework is a particle system of particle systems. Each rocket is a particle that, at the top of its arc, is replaced by a new system of h
  • Particle Text — Particles don't have to fly off and die. Give each one a home and the arrive steering behaviour, and they assemble into shapes. Here the hom
  • Rain, Splashes & Ripples — Like fireworks, this is a system that spawns systems. Each raindrop is a particle, and when it hits the ground (or your umbrella) it dies an

Autonomous Agents

  • Steering Behaviors — An autonomous agent picks its own forces. Craig Reynolds' formula is the core of it: steering = desired velocity − current velocity, capped
  • Flow Field Following — A flow field is a grid of vectors covering the canvas. Each vehicle looks up the cell it is in and uses that arrow as its desired velocity.
  • Flocking (Boids) — Craig Reynolds' boids: each bird follows three local rules and only sees neighbours within its perception radius. Separation: steer away fro
  • Path Following — Reynolds' path following combines seek with a bit of geometry. Each vehicle: predicts where it will be a short time ahead, finds the closest
  • Predators & Prey — Flocking boids now share the world with predators. Prey flock and flee any predator nearby. Predators chase the nearest prey they can see, g
  • Ant Colony & Pheromone Trails — In the flow field demo the field was given. Here the agents write their own field. Ants leaving the nest lay a "home" pheromone (blue). Ants
  • Obstacle Avoidance — A wandering vehicle needs to look ahead. Each frame it projects a feeler along its velocity (longer when moving faster) and checks whether t
  • Physarum Slime Mould — A single-celled slime mould can find the shortest path through a maze. Jeff Jones' 2010 model captures it with very simple agents. Each one
  • Crowd Evacuation — Flocking used separation to keep birds apart. In a crowd that same force becomes personal space, and when everyone heads for one exit it pro
  • Phantom Traffic Jams — Cars on a ring road follow the car ahead using the Intelligent Driver Model. Each driver accelerates toward a desired speed and brakes to ke
  • Wolves, Sheep & Grass — Add a third level to the food chain. Grass grows back on a timer, sheep wander and eat grass for energy, and wolves wander and eat sheep. Ev
  • Termites Building Piles — Mitchel Resnick's termites follow two rules. (1) If you're empty-handed and bump into a wood chip, pick it up. (2) If you're carrying a chip

Physics

  • Verlet Physics: Cloth & Ropes — Physics libraries usually split the work into bodies and constraints. This is a small engine written from scratch using Verlet integration:
  • Rigid Circles & the Galton Board — The cloth demo used distance constraints between connected points. Collisions work the same way, with "stay at least r₁ + r₂ apart" as a con
  • Verlet Ragdolls — The cloth was a grid of points and sticks. Rearrange those same parts into a skeleton and you get a ragdoll: 13 points (head, shoulders, elb
  • Granular Hourglass — Sand flows strangely. Unlike water, an hourglass drains at a constant rate regardless of how much sand is above the neck (the Beverloo law).

Cellular Automata

  • Elementary Cellular Automata — Stephen Wolfram's elementary CA is a single row of cells, each on or off. A cell's next state depends only on itself and its two neighbours,
  • Game of Life & Friends — John Conway's Game of Life is a 2D cellular automaton. Each cell counts its 8 neighbours. A dead cell with exactly 3 live neighbours is born
  • Reaction–Diffusion (Gray–Scott) — A cellular automaton with continuous states. Every cell holds amounts of two chemicals, A and B. Each step they diffuse to neighbouring cell
  • Langton's Ant & Turmites — Instead of every cell updating at once, a single ant walks the grid. It reads the colour under it, turns according to a rule string (R right
  • Atlas of All 256 Rules — Every elementary CA rule at once. Each thumbnail is one rule from 0 to 255, run from the same start. Seen side by side, Wolfram's four class
  • Cyclic Cellular Automaton — Each cell holds one of N states arranged in a cycle, like rock-paper-scissors with many hands. A cell advances to the next state if at least
  • Forest Fire Model — A probabilistic cellular automaton (Drossel & Schwabl, 1992). Each step, empty ground sprouts a tree with probability p, lightning ignites a
  • Abelian Sandpile — Drop grains of sand one at a time onto a grid. A cell holding 4 or more grains topples, passing one grain to each of its four neighbours, wh

Fractals

  • Recursive Tree — A fractal is a shape built from smaller copies of itself. The tree is drawn by recursion: draw a branch, then at its tip call the same funct
  • L-Systems — Aristid Lindenmayer invented L-systems to model how plants grow. You start from an axiom string and rewrite every character in parallel usin
  • Space Colonization Trees — The recursive tree was drawn top-down from a rule. Real trees grow toward light and space. Adam Runions' space colonization algorithm scatte
  • Mandelbrot & Julia Explorer — The most famous fractal comes from one line: z → z² + c. Start at z = 0 and repeat. If |z| stays bounded, the complex number c is in the Man
  • Chaos Game & IFS Fractals — Randomness can also draw perfect order. In the chaos game you pick a random corner of a polygon and jump a fixed fraction of the way toward
  • Pythagoras Tree — Another recursive tree, this time built from squares. On top of each square sits a right triangle, and on each of the triangle's two short s
  • Stochastic L-System Garden — A deterministic L-system grows the same plant every time. Make the rules stochastic and every plant becomes an individual. Here F is rewritt
  • Diffusion-Limited Aggregation — Space colonization grew branches toward targets. DLA grows them by pure chance. Particles wander randomly (Brownian motion) until they touch
  • Burning Ship, Tricorn & Newton — Tweak the Mandelbrot formula and whole new worlds appear. The Burning Ship takes absolute values before squaring, the Tricorn squares the co
  • Fractal Flames — Scott Draves' fractal flame algorithm (1992) extends the chaos game in three ways. Each affine map is followed by a nonlinear variation (a s

Evolutionary Computing

  • Evolving a Phrase — The infinite monkey problem solved by evolution. Random typing would take longer than the age of the universe to produce a sentence. A genet
  • Smart Rockets — Each rocket's DNA is a list of thrust vectors, one for every frame of its life. At the end of a generation, rockets are scored on how close
  • Traveling Salesperson (GA) — The phrase GA evolved strings of letters. Here the DNA is an ordering: the sequence in which to visit every city, and fitness rewards shorte
  • Interactive Selection: Breed Flowers — Sometimes the best fitness function is you. In interactive selection a person rates each individual, and the GA breeds the next generation f
  • Evolving a Picture from Triangles — The phrase GA matched letters. This one matches pixels. The genome is a list of semi-transparent coloured triangles. Each iteration mutates
  • Evolving Steering: Food vs Poison — Each vehicle's DNA holds four numbers: how strongly it is attracted to food, how strongly to poison (negative = repelled), and how far it ca
  • Simulated Annealing — A different way to search a huge space, borrowed from metallurgy. Keep one route and repeatedly try a small change (reverse a section). Alwa
  • Biomorphs — Richard Dawkins invented biomorphs for The Blind Watchmaker (1986) to show how cumulative selection creates complex forms. Each one is a rec

Neural Networks

  • The Perceptron — The perceptron (Rosenblatt, 1958) is the simplest neural network: one neuron. It multiplies each input by a weight, adds them up together wi
  • Neural Network Playground — A multilayer perceptron stacks layers of neurons with nonlinear activation functions (tanh here). With hidden layers it can learn curved dec
  • Neural Network Curve Fitting — The perceptron could only draw a straight line. A network with hidden layers can approximate any smooth function (the universal approximatio
  • Gradient Descent Optimizers — Training a neural network means rolling downhill on a loss landscape. This 2D landscape stands in for the millions of dimensions of a real n
  • Teach a Network Your Drawings — The perceptron sorted 2D points. A real image classifier works the same way, just with more inputs. Your drawing is shrunk to 16×16 pixels,
  • Overfitting & Regularization — A big enough network can memorise anything, including the noise. Here the data is split in two: the network trains only on the training poin
  • Neural Network Painter — Curve fitting in 2D with colour. The network learns a function from a pixel's position (x, y) to its colour (r, g, b). Once trained, the who
  • K-Means Clustering — Not all learning needs labels. K-means finds groups by itself by repeating two steps. (1) Assign: each point joins its nearest centroid. (2)

Neuroevolution

  • Neuroevolution Ecosystem — Neuroevolution combines the last two chapters. Each creature is steered by its own small neural network, but there is no backpropagation and
  • Neuroevolution: Self-Driving Cars — Each car sees the world through five distance sensors (ray casts against the track walls) plus its own speed. Those 6 numbers feed a small n
  • Neuroevolution: Balancing a Pole — The classic control benchmark. A pole is hinged on a cart, and the only way to keep it upright is to push the cart left or right, like balan
  • Neuroevolution: Rocket Landing — A harder control problem. Each rocket starts high up with a random drift and must touch down gently, upright and on the pad. Its network see