diff --git a/content/00_5_introduction.html b/content/00_5_introduction.html index 3d404f6a..85444c25 100644 --- a/content/00_5_introduction.html +++ b/content/00_5_introduction.html @@ -199,6 +199,6 @@

The Ecosystem Project

At the end of each chapter, you’ll find a series of prompts for one such project—exercises that build on each other, one topic at a time. This project is based on the following scenario. You’ve been asked by a science museum to develop the software for a new exhibit, the Digital Ecosystem, a world of animated, procedural creatures that live in a computer simulation for visitors to enjoy as they enter the museum. I don’t mean to suggest that this is a particularly innovative or creative concept. Rather, I’ll use this example Ecosystem Project idea as a literal representation of the content in the book, demonstrating how the elements can fit together in a single program. I encourage you to develop your own idea, one that’s perhaps more abstract and nontraditional.

Getting Help and Submitting Feedback

Coding can be tough and frustrating, and the ideas in this book aren’t always straightforward. You don’t have to go it alone. There’s probably someone else reading right now who would love to co-organize a study group or a book club where you can meet, chat, and share your struggles and successes. If you don’t find a local community for traveling this journey together, what about an online one? Two places I’d suggest are the official Processing forums and the Coding Train Discord server.

-

I consider the online version of this book a living document and welcome your feedback. For all things book related, please visit the Nature of Code website. The raw source text of the book and all the illustrations are on GitHub. Please leave feedback and submit corrections by using GitHub issues.

+

I consider the online version of this book a living document and welcome your feedback. For all things book related, please visit the Nature of Code website. The raw source text of the book and all the illustrations are on GitHub. Please leave feedback and submit corrections by using GitHub issues.

More important, I want to see what you make! You can share your ideas by submitting to the passenger showcase on the Coding Train website or in the channels on the aforementioned Discord. A hello in a YouTube comment is always welcome (although to be honest, it’s often best not to read the comments on YouTube), and feel free to tag me on whatever platform the future of social media has to offer—whichever one is the friendliest and least toxic! I want to enjoy all the bloops that swim in your ecosystem. Whether they leap triumphantly over a wave of creativity or make a tiny splash in a pond of learning, let’s bask in the ripples they send through the nature of coding!

\ No newline at end of file diff --git a/content/03_oscillation.html b/content/03_oscillation.html index 548146a1..b4b5d53f 100644 --- a/content/03_oscillation.html +++ b/content/03_oscillation.html @@ -940,7 +940,7 @@

The Pendulum

}

Next, I need to write an update() method to update the pendulum’s angle according to the formula:

-
+
  update() {
     // An arbitrary constant
     let gravity = 0.4;
diff --git a/content/06_libraries.html b/content/06_libraries.html
index 739185b1..b5ae1da8 100644
--- a/content/06_libraries.html
+++ b/content/06_libraries.html
@@ -1045,7 +1045,7 @@ 

A Brief Interlude: Integration Me

I’ve managed to get most of the way through this material related to physics simulation without really needing to dive into calculus. As I wrap up the first half of this book, however, it’s worth taking a moment to examine the calculus behind what I’ve been demonstrating and how it relates to the methodology in certain physics libraries (like Box2D, Matter.js, and the upcoming Toxiclibs.js). This way, you’ll know what to say at the next cocktail party when someone asks you about integration.

I’ll begin with a question: “What does integration have to do with position, velocity, and acceleration?” To answer, I should first define differentiation, the process of finding a derivative. The derivative of a function is a measure of how a function changes over time. Consider position and its derivative. Position is a point in space, while velocity is the change in position over time. Therefore, velocity can be described as the derivative of position. And what’s acceleration? The change in velocity over time. Acceleration is the derivative of velocity.

Integration, the process of finding an integral, is the inverse of differentiation. For example, the integral of an object’s velocity over time tells us the object’s new position when that time period ends. Position is the integral of velocity, and velocity is the integral of acceleration.

-

Since the physics simulations in this book are founded on the notion of calculating acceleration based on forces, integration is needed to figure out the object’s location after a certain period of time (like one cycle of the draw() loop). In other words, you’ve been doing integration all along! The following code shows what it looks like.

+

Since the physics simulations in this book are founded on the notion of calculating acceleration based on forces, integration is needed to figure out the object’s location after a certain period of time (like one cycle of the draw() loop). In other words, you’ve been doing integration all along!

velocity.add(acceleration);
 position.add(velocity);

This methodology is known as Euler integration, or the Euler method (named for the mathematician Leonhard Euler, pronounced Oiler). It’s essentially the simplest form of integration and is very easy to implement in code—just two lines! However, while it’s computationally simple, it’s by no means the most accurate or stable choice for certain types of simulations.

diff --git a/content/08_fractals.html b/content/08_fractals.html index e5d8b9c2..03e2018f 100644 --- a/content/08_fractals.html +++ b/content/08_fractals.html @@ -452,8 +452,8 @@

Exercise 8.4

Exercise 8.5

Use recursion to draw the Sierpiński triangle (as seen in Chapter 7’s Wolfram elementary CA).

-   -
 
+ +

Trees

diff --git a/content/09_ga.html b/content/09_ga.html index 3ea209ca..8d7440e4 100644 --- a/content/09_ga.html +++ b/content/09_ga.html @@ -40,7 +40,7 @@

Why Use Genetic Algorithms?

Consider a cat named Clawdius. Clawdius types on a reduced typewriter containing only 27 characters: the 26 English letters plus the spacebar. The probability of Clawdius hitting any given
key is 1 in 27.

Next, consider the phrase “to be or not to be that is the question” (for simplicity, I’m ignoring capitalization and punctuation). The phrase is 39 characters long, including spaces. If Clawdius starts typing, the chance he’ll get the first character right is 1 in 27. Since the probability he’ll get the second character right is also 1 in 27, he has a 1 in 729 (27 \times 27) chance of landing the first two characters in correct order. (This follows directly from our discussion of probability in Chapter 0.) Therefore, the probability that Clawdius will type the full phrase is 1 in 27 multiplied by itself 39 times, or (1/27)^{39}. That equals a probability of . . .

1 \text{ in } \text{66,555,937,033,867,822,607,895,549,241,096,482,953,017,615,834,735,226,163}
-

Needless to say, even hitting just this one phrase, let alone an entire play, let alone all
38 Shakespeare plays (yes, even The Two Noble Kinsmen) is highly unlikely. Even if Clawdius were a computer simulation and could type a million random phrases per second, for Clawdius to have a 99 percent probability of eventually getting just the one phrase right, he would have to type for 9,719,096,182,010,563,073,125,591,133,903,305,625,605,017 years. (For comparison, the universe is estimated to be a mere 13,750,000,000 years old.)

+

Needless to say, even hitting just this one phrase, let alone an entire play, let alone all of Shakespeare’s 38 plays (yes, even The Two Noble Kinsmen) is highly unlikely. Even if Clawdius were a computer simulation and could type a million random phrases per second, for Clawdius to have a 99 percent probability of eventually getting just the one phrase right, he would have to type for 9,719,096,182,010,563,073,125,591,133,903,305,625,605,017 years. (For comparison, the universe is estimated to be a mere 13,750,000,000 years old.)

The point of all these unfathomably large numbers isn’t to give you a headache, but to demonstrate that a brute-force algorithm (typing every possible random phrase) isn’t a reasonable strategy for arriving randomly at “to be or not to be that is the question.” Enter GAs, which start with random phrases and swiftly find the solution through simulated evolution, leaving plenty of time for Clawdius to savor a cozy catnap.

To be fair, this particular problem (to arrive at the phrase “to be or not to be that is the question”) is a ridiculous one. Since you know the answer already, all you need to do is type it. Here’s a p5.js sketch that solves the problem:

let s = "to be or not to be that is the question";
diff --git a/content/images/10_nn/10_nn_5.png b/content/images/10_nn/10_nn_5.png
index 79797c7e..78c76c07 100644
Binary files a/content/images/10_nn/10_nn_5.png and b/content/images/10_nn/10_nn_5.png differ