The Nature of Code cover image

The Nature of Code

by Daniel Shiffman
July 2024, 600 pp.
Use coupon code PREORDER to get 25% off!

Download Chapter 7: Cellular Automata Look Inside!

Nature of Code pages 16-17Nature of Code pages 150-151Nature of Code pages 532-533

How can we use code to capture the unpredictable properties of nature? How can understanding the mathematical principles behind our physical world help us create interesting digital environments? Written by “The Coding Train” YouTube star Daniel Shiffman, The Nature of Code is a beginner-friendly creative coding tutorial that explores a range of programming strategies for developing computer simulations of natural systems—from elementary concepts in math and physics to sophisticated machine-learning algorithms.

Using the same enthusiastic style on display in Shiffman’s popular YT channel, this book makes learning to program fun, empowering you to generate fascinating graphical output while refining your problem-solving and algorithmic-thinking skills. You’ll progress from building a basic physics engine that simulates the effects of forces like gravity and wind resistance, to creating evolving systems of intelligent autonomous agents that can learn from their mistakes and adapt to their environment.

The Nature of Code introduces important topics such as:

  • Randomness
  • Forces and vectors
  • Trigonometry
  • Cellular automata and fractals
  • Genetic algorithms
  • Neural networks 

Learn from an expert how to transform your beginner-level skills into writing well-organized, thoughtful programs that set the stage for further experiments in generative design.

NOTE: All examples are written with p5.js, a JavaScript library for creative coding, and are available on the book's website. 

Author Bio 

Daniel Shiffman is an Associate Arts Professor at ITP/IMA, Tisch School of the Arts, NYU. He is a director of The Processing Foundation and the author of Learning Processing: A Beginner’s Guide to Programming Images, Animation, and Interaction and The Nature of Code, an open source book about simulating natural phenomenon with code. On his YouTube channel, The Coding Train, he publishes "creative coding" tutorials with subjects ranging from the basics of programming languages like JavaScript (with p5.js) and Java (with Processing) to generative algorithms like physics simulation, computer vision, and data visualization.

Table of contents 


Chapter 0: Randomness
Chapter 1: Vectors
Chapter 2: Forces
Chapter 3: Oscillation
Chapter 4: Particle Systems
Chapter 5: Autonomous Agents
Chapter 6: Physics Libraries
Chapter 7: Cellular Automata
Chapter 8: Fractals
Chapter 9: Evolutionary Computing

Chapter 10: Neural Networks
Chapter 11: Neuroevolution

Appendix: Creature Design

Image Credits


The chapters in red are included in this Early Access PDF.