freeprogrammingbooks.com

The Nature of Code: Simulating Natural Systems with JavaScript

By Daniel Shiffman (2024)

The Nature of Code: Simulating Natural Systems with JavaScript book cover

Creative coding has grown from a niche practice into a vibrant discipline at the intersection of technology, art, and science. With the rise of JavaScript as the universal language of the web, libraries like p5.js have made it possible for anyone with a browser to create interactive visualizations, simulations, and generative art.

The demand for developers who can bridge creative expression with programming logic continues to grow across industries — from data visualization and game development to digital art installations and scientific research communication.

Understanding how to model natural systems through code opens doors to more intuitive programming, where complex behaviors emerge from simple rules. This approach not only produces captivating visual results but also deepens your grasp of core programming concepts like object-oriented design, vectors, and algorithmic thinking.

About the book

The Nature of Code by Daniel Shiffman is a hands-on guide to simulating natural systems using JavaScript and the p5.js library. First published in 2012 and now fully rebooted for the modern web, this second edition teaches you how to model phenomena from physics and biology — gravity, flocking, fractals, neural networks, and more — directly in your browser.

This is not a dry science textbook. Shiffman takes a practical, code-first approach: every concept is accompanied by fully functional p5.js sketches that you can run, modify, and experiment with online. The book assumes one semester of programming experience (variables, conditionals, loops, objects, and arrays), making it ideal for self-taught developers, design students, and programmers curious about simulation and generative art.

What you will learn

  • Build a physics engine from scratch — forces, gravity, friction, and fluid resistance
  • Create autonomous agents that perceive and react to their environment
  • Simulate complex systems with particle systems, cellular automata, and fractals
  • Implement genetic algorithms that evolve behavior over time
  • Design and train neural networks for decision-making and adaptation
  • Work with vectors, trigonometry, and randomness to drive natural-looking motion
  • Integrate physics libraries like Matter.js for advanced simulations
  • Use object-oriented programming to manage thousands of interacting elements

Table of contents

  • Acknowledgments
  • Introduction
  • 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
  • Index

Book details

  • Title: The Nature of Code: Simulating Natural Systems with JavaScript
  • Author(s): Daniel Shiffman
  • Publication year: 2024
  • Publisher: No Starch Press
  • Pages: 640
  • PDF size: Not available (free HTML version at natureofcode.com)
  • Estimated reading time: ~16 h
  • Level: Intermediate
  • Main category: Programming
  • Subcategory: Creative Coding
  • Language: English
  • License: CC BY-NC-SA 4.0

Este libro está disponible gratuitamente en su formato original en línea.

More books in: Programming


Legal notice: This book is shared for educational purposes only. The content is distributed under Creative Commons licenses or with explicit permission from the author. FreeProgrammingBooks may host files that comply with their respective licenses.

Want more free books?

Join our channels and receive free books, courses and tech news.