Course overview
What makes a ball bounce, a planet orbit or a flock turn together? Students use p5.js, a JavaScript library for drawing and animation in the browser, to turn those questions into interactive programs they can test. Drawing on Daniel Shiffman’s The Nature of Code, Level 1 teaches programming through physics. Level 2 uses those foundations to model groups, generate patterns and build games.
Planning your course
School levels: Upper secondary
Format: Two courses taught in sequence
Tell us what your students can already code, how long each lesson slot is and what devices they’ll use. If your school restricts browser-based tools or student accounts, let us know so we can discuss the setup.
Learning outcomes
- Write and debug JavaScript programs that handle input and manage many objects at once.
- Turn a scientific idea into a working model and explain what the model leaves out.
- Design rules for a simulation or game, then test how changing one rule affects the whole system.
Curriculum and hands-on
Level 1: JavaScript and physics modelling (30 hours)
Students start by drawing and animating in p5.js. They use loops and arrays to work with many objects, classes to give those objects their own behaviour, and vectors to describe motion. They compare random movement with the smoother variation of Perlin noise, for example by making a field of grass sway.
From there, they model acceleration and forces such as gravity, wind and drag. They might build a marble run or simulate planets that pull on one another. For a longer project, students can build an interactive physics visualisation that lets a classmate change a force and see how it affects the model.
Level 2: Advanced simulations and game design (30 hours)
Students build on those motion models to program autonomous agents that steer, follow paths or flock. They use cellular automata to explore what happens when cells follow simple rules, from Conway’s Game of Life to falling sand and generated cave maps.
The follow-on can also cover recursive fractals, genetic algorithms and constraint-based generation: for example, using wave function collapse to assemble a map from tiles that must fit together. Other extensions include raycasting for line of sight, 3D scenes and networked multiplayer.
For a longer project, students might turn a board game into a playable video game with autonomous opponents or a map that changes each time.