mirror of
https://github.com/nature-of-code/noc-book-2
synced 2024-09-29 05:36:56 +02:00
Notion - Update docs
This commit is contained in:
parent
8cdea2e74c
commit
785078f889
3 changed files with 8 additions and 4 deletions
|
@ -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. I’ll 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 book’s 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, there’s no reason you couldn’t read this book having learned programming with a different language or development environment.</p>
|
||||
<p>If you’ve never written any code before, while you could read the book for the concepts and inspiration, you’ll likely struggle with the code because I’m 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 you’ve never written any code before, while you could read the book for the concepts and inspiration, you’ll likely struggle with the code because I’m 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 you’re an experienced programmer but haven’t 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 library’s “Get Started” page</a>.</p>
|
||||
<p>I should also point out that experience with object-oriented programming is fairly critical. I’ll 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 object’s motion (<strong>Chapter 0</strong>), I’m 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 won’t 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, you’re going to quickly realize that a force (<strong>Chapter 2</strong>) is a vector. Kick a soccer ball and you’re 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 you’ve tackled the basics of motion and forces for an individual inanimate object, I’ll 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>
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -582,8 +582,9 @@ for (let i = 1; i < 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 && neighborSum < 2) next[i][j] = 0;
|
||||
//{.continue}
|
||||
else if (board[i][j] === 1 && neighborSum > 3) next[i][j] = 0;
|
||||
else if (board[i][j] === 0 && neighborSum === 3) next[i][j] = 1;
|
||||
else next[i][j] = board[i][j];
|
||||
|
|
Loading…
Reference in a new issue