Hello! This book is an experiment based on a simple premise: simulating the world around us is a powerful aid to understanding, so we should get started as early as possible.

My primary goal is to teach you how to describe natural phenomena using one formal language (mathematics) so that you can reproduce them using another formal language (computer code). Of equal importance is the pursuit of creative expression. My hope for you, dear reader, is that you walk away from each exercise a little more confident that you can understand anything you observe and construct anything you can imagine.

Over the course of a dozen chapters, you will progress from simulating the nighttime sky to developing an artificial intelligence, all using p5.js. We’ll start simple and keep the jargon to an absolute minimum.

About half of the text is adapted from one of my favorite programming books, The Nature of Code by Daniel Shiffman. The rest of the material is drawn from lessons I teach in my high school math classes.

A Little Background

The Wikipedia entry on mathematics begins by highlighting core topics including quantity, structure, space, and change. Whether you’re into creating works of art, making money, or exploring the limits of knowledge, mathematics is a useful lens through which to view the world.

In 1936, two mathematicians named Alonzo Church and Alan Turing were interested in determining what functions could be computed; they ended up laying the foundation of what we know as computer science. It’s fitting that computational thinking—thinking about problems in terms of data, models, algorithms, and systems—is a powerful approach to learning mathematics.

It’s not overselling it to say that modern life is entirely dependent upon math and code. More to the point, working at the intersection of these entwined fields can be a whole lot of fun.


Shout out to Shiffman for his tireless efforts to make coding accessible for beginners and for making his book available for remixing.


For my students. Nerds.