The Nature of Code: Simulating Natural Systems with JavaScriptAll aboard The Coding Train! This beginner-friendly creative coding tutorial is designed to grow your skills in a fun, hands-on way as you build simulations of real-world phenomena with “The Coding Train” YouTube star Daniel Shiffman. What if you could re-create the awe-inspiring flocking patterns of birds or the hypnotic dance of fireflies—with code? For over a decade, The Nature of Code has empowered countless readers to do just that, bridging the gap between creative expression and programming. This innovative guide by Daniel Shiffman, creator of the beloved Coding Train, welcomes budding and seasoned programmers alike into a world where code meets playful creativity. This JavaScript-based edition of Shiffman’s groundbreaking work gently unfolds the mysteries of the natural world, turning complex topics like genetic algorithms, physics-based simulations, and neural networks into accessible and visually stunning creations. Embark on this extraordinary adventure with projects involving:
Shiffman’s work has transformed thousands of curious minds into creators, breaking down barriers between science, art, and technology, and inviting readers to see code not just as a tool for tasks but as a canvas for boundless creativity. Whether you’re deciphering the elegant patterns of natural phenomena or crafting your own digital ecosystems, Shiffman’s guidance is sure to inform and inspire. The Nature of Code is not just about coding; it’s about looking at the natural world in a new way and letting its wonders inspire your next creation. Dive in and discover the joy of turning code into art—all while mastering coding fundamentals along the way. NOTE: All examples are written with p5.js, a JavaScript library for creative coding, and are available on the book's website. |
Contents
| 1 | |
| 13 | |
| 19 | |
The Ecosystem Project | 31 |
Vectors | 33 |
Vectors in p5 js | 37 |
More Vector Math | 45 |
Vector Magnitude | 51 |
Falling Boxes Hitting Boundaries | 308 |
Matter js Constraints | 315 |
Collision Events | 327 |
Verlet Physics with Toxiclibs js | 333 |
SoftBody Simulations | 342 |
Attraction and Repulsion Behaviors | 355 |
Cellular Automata | 359 |
Elementary Cellular Automata | 362 |
Acceleration | 59 |
The Ecosystem Project | 69 |
Forces | 71 |
Force Accumulation | 77 |
Forces | 83 |
The nBody Problem | 110 |
The Ecosystem Project | 116 |
Oscillation | 117 |
Trigonometry Functions | 125 |
Polar to Cartesian | 132 |
Oscillation with Angular Velocity | 138 |
Spring Forces | 147 |
The Pendulum | 154 |
The Ecosystem Project | 165 |
Particle Systems | 167 |
An Array of Particles | 174 |
A Single Particle Emitter | 181 |
and Polymorphism | 196 |
Image Textures and Additive Blending | 205 |
The Ecosystem Project | 211 |
Autonomous Agents | 213 |
Flow Fields | 233 |
FlowField Following | 239 |
Complex Systems | 257 |
Why Does My Sketch Run So Slowly? | 274 |
The Ecosystem Project | 285 |
Physics Libraries | 287 |
Importing the Matter js Library | 291 |
Matter js with p5 js | 302 |
Wolfram Classification | 379 |
ObjectOriented Cells | 390 |
The Ecosystem Project | 396 |
Fractals | 397 |
The Koch Curve | 411 |
Trees | 419 |
Lsystems | 427 |
The Ecosystem Project | 435 |
Evolutionary Computing | 437 |
How Genetic Algorithms Work | 442 |
Customizing Genetic Algorithms | 463 |
Smart Rockets | 469 |
Ecosystem Simulation | 487 |
The Ecosystem Project | 495 |
Neural Networks | 497 |
Putting the Network in Neural Network | 517 |
Building a Gesture Classifier | 529 |
The Ecosystem Project | 542 |
Neuroevolution | 543 |
Evolving Neural Networks Is NEAT | 549 |
Neuroevolutionary Flappy Bird | 554 |
Steering the Neuroevolutionary Way | 565 |
A Neuroevolutionary Ecosystem | 573 |
The Ecosystem Project | 582 |
Creature Design | 585 |
Image Credits | 589 |
| 591 | |
Other editions - View all
Common terms and phrases
acceleration algorithm angular angular acceleration angular velocity animation apply applyForce array Attractor background(255 bird bloop boids calculate called canvas cell Chapter circle constraint constructor create createCanvas(640 createVector(0 creatures desired velocity direction distance dot product ecosystem elements Emitter example Exercise Figure formula fractal friction function draw function setup gravity height Here’s implement inputs JavaScript L-system let angle let particle look loop machine learning magnitude mass Matter.js Matter.js body method motion mouse move Mover class Mover object multiple neural network Newton's second law normal point options oscillation output p5.js sketch p5.Vector objects Particle object particle system path pendulum perceptron Perlin noise physics engine pixels position programming quadtree radians random numbers rocket rotate ruleset shape simulation sine speed spring steering force step stroke(0 target this.acceleration this.position this.position.y this.velocity this.y Toxiclibs.js update variable vector vehicle VerletParticle2D visual walker width


