Notion - Update docs

This commit is contained in:
shiffman 2024-03-05 15:50:34 +00:00 committed by GitHub
parent 8cdea2e74c
commit 785078f889
3 changed files with 8 additions and 4 deletions

View file

@ -15,7 +15,10 @@
<p>All the examples in this book have been tested with p5.js version 1.9.0, but for the most part they should also work with earlier versions. Ill be keeping them up to date with the latest version. The most <a href="https://natureofcode.com/">recent code can always be found on this books website</a> and <a href="https://github.com/nature-of-code">its associated GitHub repository</a>.</p>
<h2 id="what-do-you-need-to-know">What Do You Need to Know?</h2>
<p>The prerequisites for understanding the material in this book could be stated as “one semester of programming instruction with p5.js, Processing, or any other creative coding environment.” That said, theres no reason you couldnt read this book having learned programming with a different language or development environment.</p>
<p>If youve never written any code before, while you could read the book for the concepts and inspiration, youll likely struggle with the code because Im assuming knowledge of the fundamentals: variables, conditionals, loops, functions, objects, and arrays. If these concepts are new to you, my <a href="https://thecodingtrain.com/p5js">“Code! Programming with p5.js”</a> and <a href="https://thecodingtrain.com/processing">“Learning Processing”</a> video courses provide the fundamentals of what you need to know.</p>
<p>
If youve never written any code before, while you could read the book for the concepts and inspiration, youll likely struggle with the code because Im assuming knowledge of the fundamentals: variables, conditionals, loops, functions, objects, and arrays. If these concepts are new to you, my <a href="https://thecodingtrain.com/p5js">“Code! Programming with p5.js”</a> and <a href="https://thecodingtrain.com/processing">“Learning Processing”</a> video courses provide the fundamentals of what you need
to know.
</p>
<p>If youre an experienced programmer but havent worked with p5.js, you can probably pick it up by <a href="https://p5js.org/">checking out the p5.js documentation</a>, poking through the examples, and <a href="https://p5js.org/get-started">reading through the librarys “Get Started” page</a>.</p>
<p>I should also point out that experience with object-oriented programming is fairly critical. Ill review some of the basics in Chapter 0, but if classes and objects are unfamiliar to you, I suggest watching <a href="https://thecodingtrain.com/oop">my p5.js and Processing object-oriented video tutorials, both also available at the Coding Train</a>.</p>
<h2 id="how-are-you-reading-this-book">How Are You Reading This Book?</h2>
@ -39,7 +42,6 @@
<p>You draw a shape at position <code>x</code>. With each frame of animation, you increment the value of <code>x</code>, redraw the shape, and voilà—the illusion of motion! Maybe you took it a step or two further and included a <code>y</code> position, as well as variables for speed along the x- and y-axes:</p>
<pre class="codesplit" data-code-language="javascript">x = x + xspeed;
y = y + yspeed;</pre>
<p>Part 1 of this story will take this idea even further. After exploring how to use different flavors of randomness to drive an objects motion (<strong>Chapter 0</strong>), Im going to take these <code>xspeed</code> and <code>yspeed</code> variables and demonstrate how together they form a vector (<strong>Chapter 1</strong>). You wont get any new functionality out of this, but it will build a solid foundation for programming motion in the rest of the book.</p>
<p>Once you know a little something about vectors, youre going to quickly realize that a force (<strong>Chapter 2</strong>) is a vector. Kick a soccer ball and youre applying a force. What does a force cause an object to do? According to Sir Isaac Newton, force equals mass times acceleration, so that force causes an object to accelerate. Modeling forces will allow you to create systems with dynamic motion, in which objects move according to a variety of rules.</p>
<p>Now, that soccer ball to which you applied a force might have also been spinning. If an object moves according to its <em>linear</em> acceleration, it can spin according to its <em>angular</em> acceleration (<strong>Chapter 3</strong>). Understanding the basics of angles and trigonometry will allow you to model rotating objects as well as grasp the principles behind oscillating motion, like a pendulum swinging or a spring bouncing.</p>
<p>Once youve tackled the basics of motion and forces for an individual inanimate object, Ill show you how to make thousands upon thousands of those objects and manage them as a single unit called a <em>particle system</em> (<strong>Chapter 4</strong>). Particle systems are also a good excuse to look at some additional features of object-oriented programming—namely, inheritance and polymorphism.</p>

View file

@ -1139,8 +1139,9 @@ class Repeller {
}
repel(particle) {
// This is the same repel algorithm from Chapter 2: forces based on gravitational attraction.
// {!1}
let force = p5.Vector.sub(this.position, particle.position);
// {.continue.bottom-align} This is the same repel algorithm from Chapter 2: forces based on gravitational attraction.
let distance = force.mag();
distance = constrain(distance, 5, 50);
let strength = -1 * this.power / (distance * distance);

View file

@ -582,8 +582,9 @@ for (let i = 1; i &#x3C; columns - 1; i++) {
}
// Correct by subtracting the cell state.
neighborSum -= board[i][j];
//{!4} The rules of life!
//{!1} The rules of life!
if (board[i][j] === 1 &#x26;&#x26; neighborSum &#x3C; 2) next[i][j] = 0;
//{.continue}
else if (board[i][j] === 1 &#x26;&#x26; neighborSum > 3) next[i][j] = 0;
else if (board[i][j] === 0 &#x26;&#x26; neighborSum === 3) next[i][j] = 1;
else next[i][j] = board[i][j];