Jump to ratings and reviews
Rate this book

The Nature of Code

Rate this book
How can we capture the unpredictable evolutionary and emergent properties of nature in software? How can understanding the mathematical principles behind our physical world help us to create digital worlds? This book focuses on a range of programming strategies and techniques behind computer simulations of natural systems, from elementary concepts in mathematics and physics to more advanced algorithms that enable sophisticated visual results. Readers will progress from building a basic physics engine to creating intelligent moving objects and complex systems, setting the foundation for further experiments in generative design. Subjects covered include forces, trigonometry, fractals, cellular automata, self-organization, and genetic algorithms. The book's examples are written in Processing, an open-source language and development environment built on top of the Java programming language. On the book's website (http://www.natureofcode.com), the examples run in the browser via Processing's JavaScript mode.

520 pages, Paperback

First published December 13, 2012

Loading interface...
Loading interface...

About the author

Daniel Shiffman

6 books81 followers

Ratings & Reviews

What do you think?
Rate this book

Friends & Following

Create a free account to discover what your friends think of this book!

Community Reviews

5 stars
297 (64%)
4 stars
130 (28%)
3 stars
24 (5%)
2 stars
4 (<1%)
1 star
2 (<1%)
Displaying 1 - 28 of 28 reviews
Profile Image for Jovany Agathe.
279 reviews
June 22, 2019
 Nature of Code teaches how to simulate natural systems using the Processing program language. Processing is a programming language has built in functionality for simulating natural events, and the language is similar to Java.

Beginning chapters are focused on physics and calculus. There were some of the best explanations I have ever seen for showing the concepts and how formulas work. I was thinking how much better it would have been if I had learned calculus from a book like this. There are excellent details how forces, vectors, and angles work. Working examples are implemented in using Processing.

The middle of the book tells you which libraries are useful. The author takes the time to explain which parts you want to implement your self and when you should rely on a given library.

Later parts of the book go into more advanced natural systems such as simulating biological events. Some genetic algorithms are presented, and lastly the building blocks of neural networks are examined. Descriptions are geared towards beginners and the walk through is quite detailed.

This book works whether you want to learn programming or simulate natural events.
Profile Image for Antonio.
5 reviews
July 12, 2015
I think this book is the best choice if you're starting in the world of Computational Science and simulation.

But not only! If you know how to simulate or programming, but you want to learn how to start programming some complex systems (like neural networks, for example) this book is great. Or even if you're planning to become a videogame programmer, this book also is a good choise!

The language is very simple and is really easy to read and follow. It starts from zero, you don't need to know almost any Maths of Physics to follow it. The only think you'll need before read is to learn some programming language.
Profile Image for Lucas.
16 reviews
March 25, 2018
This book took me the longest to read. I read it in parts and not in any order.

I have this book to thank for my interests in the link between biology and computers.
So many things have been inspired by or are connected to nature in computer science: neural networks, genetic algorithms and fractals to name a few.

It has also been an inspiration for many of my projects. The amount of fascinating information explained in such simple ways is amazing. How complicated subjects are made visual in various ways.

One of the most underrated books in my opinion.
Profile Image for Oscar Rodrigues.
13 reviews
July 2, 2017
The best thing about this book is its simplicity and elegance in describing the patterns we find in nature through code. It's great for learning programming, physics, math or art. Or, even better, all of the above!
Profile Image for Benji.
349 reviews55 followers
May 10, 2015
Gentle introduction to OOP using Processing, showcasing its tremendous power.
Profile Image for POURIA.
22 reviews14 followers
January 24, 2023
I don't think I'll ever read another programming book as joyful as this one. The prose and the way it's written make it a delightful reading experience—something rare to find in this category of books—, and this is owned to Daniel Shiffman's cheerful personality and his passion for teaching.

I was initially interested and picked this book up because I wanted to get into creative coding and generated art—both relatively new terms to me—but, wow, I got much more.

This book covers a wide range of topics, from basic trigonometry and physics to more complex topics such as artificial intelligence. I was impressed by the intuitive way vectors were explained in the first chapter. As I read through the subsequent chapters, and every time that I thought the next one couldn’t get any more interesting, each chapter opened up a whole new world for me to explore.

The book is free for download, and there are also videos covering the chapters on YouTube. The examples are written in Processing, a Java framework, but you can also use p5.js. You don’t really need prior experience in Java, as Processing is simple to learn and use. It was designed specifically for this purpose, and its immediate visual feedback makes it an ideal choice for creating sketches with code.

If you're a programmer looking to try something new, this book is for you.
Profile Image for Richard.
242 reviews7 followers
January 29, 2013
I've decided to put some of the geeky maths books I read up on here, at least the good ones, and this one is good!

You can make things fly about the screen! And give those things basic intelligence and all sorts!

Its written for processing, but its more of a conceptal book than a processing one. Once you get those concepts, you can apply it anywhere. If you want to do AI, Steering Behaviours, Motion Graphics, even XSI ICE and Houdini effects, this book will really help you(even though its not about those programs). Its also great for Computer game programming - its really easy to convert the code to Unity for example.

Go Go Go Go Coding skills!

Profile Image for Franck Chauvel.
119 reviews5 followers
November 16, 2014
This book is a nice and light introduction to artificial intelligence, from the perspective of producing nice visualisations. If you are more interested in the AI parts than the visualisation with the Processing platform, you may want to check out other books.
Profile Image for Patrick Arminio.
3 reviews17 followers
May 19, 2015
I love this book, everything was nicely well explained with good examples. The only bad chapter was the last one (about neural networks) which didn't have too many informations about them, but since this is an hard topic I won't blame the author, in fact the introduction was good :)
Profile Image for Abdelhadi Naimi.
3 reviews1 follower
March 23, 2017
This book in it self is art, it taught me a lot about coding from simple physics engines to neural networks.
It didn't go into much details into its subjects but it was really fun to read and try out the code and mess around with it.
Profile Image for Alb85.
295 reviews9 followers
July 19, 2020
Il libro spiega come simulare la natura che ci circonda attraverso il linguaggio di programmazione Processing.

Processing non lo conoscevo e mi ha sorpreso in positivo. È pensato per facilitare la vita a chi vuole sviluppare applicazioni basate su contesti 2D o 3D. Bastano davvero poche righe di codice per raggiungere obiettivi non banali. Inoltre, è portabile in Java, Javascript, Python, e altri.

Il libro non è un manuale di Processing, ma una guida base alla simulazione.
Introduce il concetto fisico base di “forza”, e di come si può esprimere matematicamente attraverso il concetto di “vettore”. Parla di casualità e rumore, concetti essenziali per simulare comportamenti naturali.

Il libro spiega poi come simulare la forza di gravita, l’attrito, e l’oscillazione, la viscosità, prima applicate su un singolo oggetto e poi su un sistema di particelle (particle system).

I capitoli successivi descrivono i principali approcci alla simulazione:
- agenti autonomi: implementa molti dei veicoli descritti nel paper “Steering Behaviors For Autonomous Characters” di Craig W. Reynolds
- automa cellulare: prende spunto dal programma “Game of Life,” di John Conway
- frattali, algoritmi genetici e reti neurali.

L’autore, Daniel Shiffman, è un ottimo programmatore e insegnante. Qui trovate il suo canale youtube con molti video interessanti.
Libro consigliato a chiunque è affascinato dai processi della natura, non solo ai programmatori.

Spunti interessanti:
- Perlin noise can be used to generate various effects with natural qualities, such as clouds, landscapes, and patterned textures like marble. Perlin noise has a more organic appearance because it produces a naturally ordered (“smooth”) sequence of pseudo-random numbers.
- http://roberthodgin.com/
- velocity.add(acceleration); location.add(velocity); The above methodology is known as Euler integration (named for the mathematician Leonhard Euler, pronounced “Oiler”) or the Euler method. It’s essentially the simplest form of integration and very easy to implement in our code (see the two lines above!) However, it is not necessarily the most efficient form, nor is it close to being the most accurate.
- I still believe that Euler is the best method for learning the basics, and it’s also perfectly adequate for most of the projects we might make in Processing. Anything we lose in efficiency or inaccuracy we make up in ease of use and understandability. For better accuracy, Box2D uses something called symplectic Euler or semi-explicit Euler (http://en.wikipedia.org/wiki/Symplect...), a slight modification of Euler. There is also an integration method called Runge-Kutta (named for German mathematicians C. Runge and M. W. Kutta), which is used in some physics engines. A very popular integration method that our next physics library uses is known as “Verlet integration.” A simple way to describe Verlet integration is to think of our typical motion algorithm without velocity. After all, we don’t really need to store the velocity. If we always know where an object was at one point in time and where it is now, we can extrapolate its velocity. Verlet integration does precisely this, though instead of having a variable for velocity, it calculates velocity while the program is running. Verlet integration is particularly well suited for particle systems, especially particle systems with spring connections between the particles. We don’t need to worry about the details because toxiclibs, as we’ll see below, takes care of them for us. However, if you are interested, here is the seminal paper on Verlet physics, from which just about every Verlet computer graphics simulation is derived: “Advanced Character Physics” (http://www.gamasutra.com/resource_gui...). And of course, you can find out more about Verlet integration from Wikipedia (http://en.wikipedia.org/wiki/Verlet_i...).
- Turtles, Termites, and Traffic Jams by Mitchel Resnick
- Perhaps the most significant scientific (and lengthy) work studying cellular automata arrived in 2002: Stephen Wolfram’s 1,280-page A New Kind of Science (http://www.wolframscience.com/nksonli...).
- Conway’s Game of Life (http://stevenklise.github.com/Conways...) by Steven Klise (uses Processing.js!)
- I’d recommend the books Artificial Intelligence: A Modern Approach by Stuart J. Russell and Peter Norvig and AI for Game Developers by David M. Bourg and Glenn Seemann.
Profile Image for Heather Stark.
21 reviews
January 20, 2023
Much detailed focus on 'simulating natural systems' taught through examples. Lots of examples that relate to elementary physics. I think it could do with some more pure exposition on e.g. developing classes, and the event model in Processing. There are concepts around extensibility that are strangely implicit and you have to figure out by looking at Java, which I think kind of spoils the point. Great resource though!
1 review6 followers
July 15, 2020
Absolute delight to learning from this book.
If you know about processing and oops(just read learning processing by same author) you can start this book.
It teaches how to simulate phenomenon you see in nature in a great fun and clear way using processing.
You can see YouTube video on the coding train.
Profile Image for Alexandre Teles.
14 reviews2 followers
March 25, 2019
Great book. It summarizes the concepts of nature, movement and physic laws from our world to code in a very explanatory and intuitive way. It's a must have book to understand how to program in real world, so it's good for math, physics, games and experimentations.
6 reviews
August 21, 2019
Very well written, fun book covering a range of interesting topics. Not overly technical, reads like a relaxing novel. Chapters are well structured and can be even read separately. Recommended for everyone from data scientist to game developer.
Profile Image for Dennis Cahillane.
115 reviews8 followers
May 11, 2019
Lessons perfectly balanced with prose and code samples, making this book a very effectively learning tool.
Profile Image for Mark.
400 reviews9 followers
November 1, 2021
Dimensionality matters, a lot, but not in his code. It is impressive how the book turned into a machine learning lesson.
Profile Image for Zingsho.
39 reviews17 followers
March 17, 2022
The joy of learning to code I have received by just watching his YouTube videos for free and practicing with this book. Thank you!
Profile Image for Giuseppe Tavera.
13 reviews
February 10, 2017
La parte relativa agli algoritmi genetici e agli automi cellulari è meravigliosa, non posso che consigliare la lettura di questo libro a chi si interessa veramente al mondo della programmazione.
Profile Image for Olivier Wellmann.
2 reviews23 followers
February 13, 2015
Great book

amazing book on sw development. goes deep with many interesting topics and aspects covered through-out. if you want to re-discover all. this is a fascinating book.
Profile Image for Justin.
199 reviews44 followers
August 28, 2016
A book for people with little programming knowledge, while still being worthwhile for those with experience.
Displaying 1 - 28 of 28 reviews

Can't find what you're looking for?

Get help and learn more about the design.