Merge pull request #919 from nature-of-code/notion-update-docs

Final Updates
This commit is contained in:
Daniel Shiffman 2024-03-13 17:45:51 -04:00 committed by GitHub
commit f286509d8c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 6 additions and 6 deletions

View file

@ -199,6 +199,6 @@ function draw() {
<p>At the end of each chapter, youll 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. Youve been asked by a science museum to develop the software for a new exhibit, the <em>Digital Ecosystem</em>, a world of animated, procedural creatures that live in a computer simulation for visitors to enjoy as they enter the museum. I dont mean to suggest that this is a particularly innovative or creative concept. Rather, Ill 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 thats perhaps more abstract and nontraditional.</p>
<h2 id="getting-help-and-submitting-feedback">Getting Help and Submitting Feedback</h2>
<p>Coding can be tough and frustrating, and the ideas in this book arent always straightforward. You dont have to go it alone. Theres 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 dont find a local community for traveling this journey together, what about an online one? Two places Id suggest are <a href="https://discourse.processing.org/">the official Processing forums</a> and <a href="https://thecodingtrain.com/discord">the Coding Train Discord server</a>.</p>
<p>I consider the online version of this book a living document and welcome your feedback. For all things book related, <a href="https://natureofcode.com/">please visit the Nature of Code website</a>. The <a href="https://github.com/nature-of-code">raw source text of the book and all the illustrations are on GitHub</a>. Please <a href="https://github.com/nature-of-code/noc-book-2023/issues">leave feedback and submit corrections by using GitHub issues</a>.</p>
<p>I consider the online version of this book a living document and welcome your feedback. For all things book related, <a href="https://natureofcode.com/">please visit the Nature of Code website</a>. The <a href="https://github.com/nature-of-code">raw source text of the book and all the illustrations are on GitHub</a>. Please <a href="https://github.com/nature-of-code/noc-book-2/issues">leave feedback and submit corrections by using GitHub issues</a>.</p>
<p>More important, I want to see what you make! You can share your ideas by <a href="https://thecodingtrain.com/showcase">submitting to the passenger showcase on the Coding Train website</a> or in the channels on the aforementioned Discord. A hello in a YouTube comment is always welcome (although to be honest, its 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, lets bask in the ripples they send through the nature of coding!</p>
</section>

View file

@ -940,7 +940,7 @@ function draw() {
} </pre>
</div>
<p>Next, I need to write an <code>update()</code> method to update the pendulums angle according to the formula:</p>
<div class="snip-below snip-below">
<div class="snip-above snip-below">
<pre class="codesplit" data-code-language="javascript"> update() {
// An arbitrary constant
let gravity = 0.4;

View file

@ -1045,7 +1045,7 @@ function mousePressed() {
<p>Ive 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, its worth taking a moment to examine the calculus behind what Ive been demonstrating and how it relates to the methodology in certain physics libraries (like Box2D, Matter.js, and the upcoming Toxiclibs.js). This way, youll know what to say at the next cocktail party when someone asks you about integration.</p>
<p>Ill begin with a question: “What does integration have to do with position, velocity, and acceleration?” To answer, I should first define <strong>differentiation</strong>, the process of finding a derivative. The <strong>derivative</strong> 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 whats acceleration? The change in velocity over time. Acceleration is the derivative of velocity.</p>
<p><strong>Integration</strong>, the process of finding an integral, is the inverse of differentiation. For example, the <strong>integral</strong> of an objects velocity over time tells us the objects new position when that time period ends. Position is the integral of velocity, and velocity is the integral of acceleration.</p>
<p>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 objects location after a certain period of time (like one cycle of the <code>draw()</code> loop). In other words, youve been doing integration all along! The following code shows what it looks like.</p>
<p>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 objects location after a certain period of time (like one cycle of the <code>draw()</code> loop). In other words, youve been doing integration all along!</p>
<pre class="codesplit" data-code-language="javascript">velocity.add(acceleration);
position.add(velocity);</pre>
<p>This methodology is known as <strong>Euler integration</strong>, or the Euler method (named for the mathematician Leonhard Euler, pronounced <em>Oiler</em>). Its essentially the simplest form of integration and is very easy to implement in code—just two lines! However, while its computationally simple, its by no means the most accurate or stable choice for certain types of simulations.</p>

View file

@ -452,8 +452,8 @@ function setup() {
<h3 id="exercise-85">Exercise 8.5</h3>
<p>Use recursion to draw the Sierpiński triangle (as seen in <a href="/cellular-automata#section-cellular-automata">Chapter 7</a>s Wolfram elementary CA).</p>
<figure>
<img src="images/08_fractals/08_fractals_19.png" alt=" ">
<figcaption> </figcaption>
<img src="images/08_fractals/08_fractals_19.png" alt="">
<figcaption></figcaption>
</figure>
</div>
<h2 id="trees">Trees</h2>

View file

@ -40,7 +40,7 @@
<p>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<br>key is 1 in 27.</p>
<p>Next, consider the phrase “to be or not to be that is the question” (for simplicity, Im ignoring capitalization and punctuation). The phrase is 39 characters long, including spaces. If Clawdius starts typing, the chance hell get the first character right is 1 in 27. Since the probability hell get the second character right is also 1 in 27, he has a 1 in 729 (<span data-type="equation">27 \times 27</span>) chance of landing the first two characters in correct order. (This follows directly from our discussion of probability in <a href="/random#section-random">Chapter 0</a>.) Therefore, the probability that Clawdius will type the full phrase is 1 in 27 multiplied by itself 39 times, or <span data-type="equation">(1/27)^{39}</span>. That equals a probability of . . .</p>
<div data-type="equation">1 \text{ in } \text{66,555,937,033,867,822,607,895,549,241,096,482,953,017,615,834,735,226,163}</div>
<p>Needless to say, even hitting just this one phrase, let alone an entire play, let alone all<br>38 Shakespeare plays (yes, even <em>The Two Noble Kinsmen</em>) 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.)</p>
<p>Needless to say, even hitting just this one phrase, let alone an entire play, let alone all of Shakespeares 38 plays (yes, even <em>The Two Noble Kinsmen</em>) 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.)</p>
<p>The point of all these unfathomably large numbers isnt to give you a headache, but to demonstrate that a brute-force algorithm (typing every possible random phrase) isnt 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.</p>
<p>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. Heres a p5.js sketch that solves the problem:</p>
<pre class="codesplit" data-code-language="javascript">let s = "to be or not to be that is the question";

Binary file not shown.

Before

Width:  |  Height:  |  Size: 318 KiB

After

Width:  |  Height:  |  Size: 316 KiB