Skip to content

Commit daaa5b1

Browse files
authored
Notion - Update docs
1 parent 72fcfdc commit daaa5b1

File tree

6 files changed

+7
-27
lines changed

6 files changed

+7
-27
lines changed

content/00_5_introduction.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ <h2 id="what-do-you-need-to-know">What Do You Need to Know?</h2>
2020
<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>
2121
<h2 id="how-are-you-reading-this-book">How Are You Reading This Book?</h2>
2222
<p>Are you reading this book on a Kindle? Printed paper? On your laptop in PDF form? On a tablet showing an animated HTML5 version? Are you strapped to a chair, absorbing the content directly into your brain via a series of electrodes, tubes, and cartridges?</p>
23-
<p>My dream has always been to write this book in one single format (in this case, a collection of Notion documents) and then, after pressing a magic button (<code>npm run build</code>), out comes the book in any and all formats you might want—PDF, HTML5, printed hard copy, Kindle, and so on. This was largely made possible by the <a href="https://github.com/magicbookproject">Magic Book project</a>, an open source framework for self-publishing originally developed at ITP by Rune Madsen and Steve Klise. Everything has been designed and styled using CSS—no manual typesetting or layout.</p>
23+
<p>My dream has always been to write this book in one single format (in this case, a collection of Notion documents) and then, after pressing a magic button (<code>npm run build</code>), out comes the book in any and all formats you might want—PDF, HTML5, printed hard copy, Kindle, and so on. This was largely made possible by the <a href="https://github.com/magicbookproject">Magic Book project</a>, which is an open source framework for self-publishing originally developed at ITP by Rune Madsen and Steve Klise. Everything has been designed and styled using CSS—no manual typesetting or layout.</p>
2424
<p>The reality of putting this book together isn’t quite so clean as that, and the story of how it happened is long. If you’re interested in learning more, make sure to read the book’s acknowledgments, and then go hire the people I’ve thanked to help you publish a book! <a href="https://github.com/nature-of-code">I’ll also include more details in the associated GitHub repository</a>.</p>
2525
<p>The bottom line is that no matter what format you’re reading it in, the material is all the same. The only difference will be in how you experience the code examples—more on that in <a href="#how-to-read-the-code">“How to Read the Code”</a>.</p>
2626
<h3 id="the-coding-train-connection">The Coding Train Connection</h3>

content/00_randomness.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,6 @@ <h3 id="example-06-a-perlin-noise-walker">Example 0.6: A Perlin Noise Walker</h3
567567
// x- and y-position mapped from noise
568568
this.x = map(noise(this.tx), 0, 1, 0, width);
569569
this.y = map(noise(this.ty), 0, 1, 0, height);
570-
571570
// Move forward through time.
572571
this.tx += 0.01;
573572
this.ty += 0.01;

content/01_vectors.html

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -658,13 +658,10 @@ <h3 id="example-16-normalizing-a-vector">Example 1.6: Normalizing a Vector</h3>
658658

659659
translate(width / 2, height / 2);
660660
stroke(200);
661-
strokeWeight(2);
662661
line(0, 0, mouse.x, mouse.y);
663-
664-
// In this example, after the vector is normalized, it’s multiplied by 50. Note that no matter where the mouse is, the vector always has the same length (50) because of the normalization process.
662+
//{!2} In this example, after the vector is normalized, it’s multiplied by 50. Note that no matter where the mouse is, the vector always has the same length (50) because of the normalization process.
665663
mouse.normalize();
666664
mouse.mult(50);
667-
668665
stroke(0);
669666
strokeWeight(8);
670667
line(0, 0, mouse.x, mouse.y);
@@ -713,7 +710,7 @@ <h2 id="motion-with-vectors">Motion with Vectors</h2>
713710
<p>The <code>Mover</code> class also needs a function that determines what the object should do when it reaches the edge of the canvas. For now, I’ll do something simple and have it wrap around the edges:</p>
714711
<div class="snip-above">
715712
<pre class="codesplit" data-code-language="javascript"> checkEdges() {
716-
//{!11} When it reaches one edge, set the position to the other edge.
713+
//{!5} When it reaches one edge, set the position to the other edge.
717714
if (this.position.x > width) {
718715
this.position.x = 0;
719716
} else if (this.position.x &#x3C; 0) {

content/02_forces.html

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,6 @@ <h3 id="example-25-fluid-resistance">Example 2.5: Fluid Resistance</h3>
589589
</figure>
590590
</div>
591591
<pre class="codesplit" data-code-language="javascript">let movers = [];
592-
593592
let liquid;
594593

595594
function setup() {
@@ -623,7 +622,6 @@ <h3 id="example-25-fluid-resistance">Example 2.5: Fluid Resistance</h3>
623622
let gravity = createVector(0, 0.1 * movers[i].mass);
624623
// Apply gravity.
625624
movers[i].applyForce(gravity);
626-
627625
// Update and display the mover.
628626
movers[i].update();
629627
movers[i].show();
@@ -740,10 +738,8 @@ <h3 id="gravitational-attraction">Gravitational Attraction</h3>
740738

741739
function draw() {
742740
background(255);
743-
744-
// Draw the <code>Attractor</code> object.
741+
//{!1} Draw the <code>Attractor</code> object.
745742
attractor.show();
746-
747743
mover.update();
748744
mover.show();
749745
}</pre>
@@ -812,10 +808,9 @@ <h3 id="gravitational-attraction">Gravitational Attraction</h3>
812808
<pre class="codesplit" data-code-language="javascript">function draw() {
813809
background(255);
814810

815-
// Calculate the attraction force and apply it.
811+
//{!2} Calculate the attraction force and apply it.
816812
<strong>let force = attractor.attract(mover);
817813
mover.applyForce(force);</strong>
818-
819814
mover.update();
820815

821816
attractor.show();
@@ -915,7 +910,6 @@ <h3 id="example-27-attraction-with-many-movers">Example 2.7: Attraction with Man
915910
</div>
916911
<pre class="codesplit" data-code-language="javascript">// Now you have 10 movers!
917912
let movers = [];
918-
919913
let attractor;
920914

921915
function setup() {
@@ -936,7 +930,6 @@ <h3 id="example-27-attraction-with-many-movers">Example 2.7: Attraction with Man
936930
//{!1} Calculate an attraction force for each <code>Mover</code> object.
937931
let force = attractor.attract(movers[i]);
938932
movers[i].applyForce(force);
939-
940933
movers[i].update();
941934
movers[i].show();
942935
}

content/03_oscillation.html

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,8 @@ <h2 id="pointing-in-the-direction-of-movement">Pointing in the Direction of Move
269269
</table>
270270
<p>Now that I have the formula, let’s see where it should go in the <code>Mover</code> class’s <code>show()</code> method to make the mover (now drawn as a rectangle) point in its direction of motion. Note that in p5.js, the function for inverse tangent is <code>atan()</code>:</p>
271271
<pre class="codesplit" data-code-language="javascript"> show() {
272-
// Solve for the angle by using <code>atan()</code>.
272+
//{!1} Solve for the angle by using <code>atan()</code>.
273273
let angle = atan(this.velocity.y / this.velocity.x);
274-
275274
stroke(0);
276275
fill(175);
277276
push();
@@ -483,9 +482,8 @@ <h3 id="example-35-simple-harmonic-motion-i">Example 3.5: Simple Harmonic Motion
483482
let period = 120;
484483
let amplitude = 200;
485484

486-
// Calculate the horizontal position according to the formula for simple harmonic motion.
485+
//{!1} Calculate the horizontal position according to the formula for simple harmonic motion.
487486
let x = amplitude * sin(TWO_PI * frameCount / period);
488-
489487
stroke(0);
490488
fill(127);
491489
translate(width / 2, height / 2);
@@ -748,7 +746,6 @@ <h2 id="spring-forces">Spring Forces</h2>
748746
let force = p5.Vector.sub(bob, anchor);
749747
let currentLength = force.mag();
750748
let x = currentLength - restLength;
751-
752749
// Put it together: direction and magnitude!
753750
force.setMag(-1 * k * x);</pre>
754751
<p>Now that I have the algorithm for computing the spring force, the question remains: What OOP structure should I use? This is one of those situations that has no one correct answer. Several possibilities exist, and the one I choose depends on my goals and personal coding style.</p>
@@ -1025,11 +1022,9 @@ <h3 id="example-311-swinging-pendulum">Example 3.11: Swinging Pendulum</h3>
10251022
let gravity = 0.4;
10261023
// Formula for angular acceleration
10271024
this.angleAcceleration = (-1 * gravity / this.r) * sin(this.angle);
1028-
10291025
// Standard angular motion algorithm
10301026
this.angleVelocity += this.angleAcceleration;
10311027
this.angle += this.angleVelocity;
1032-
10331028
//{!1} Apply some damping.
10341029
this.angleVelocity *= this.damping;
10351030
}

content/04_particles.html

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,9 @@ <h3 id="example-41-a-single-particle">Example 4.1: A Single Particle</h3>
129129
// Operate the single particle.
130130
particle.update();
131131
particle.show();
132-
133132
// Apply a gravity force.
134133
let gravity = createVector(0, 0.1);
135134
particle.applyForce(gravity);
136-
137135
// Check the particle’s state and make a new particle.
138136
if (particle.isDead()) {
139137
particle = new Particle(width / 2, 20);
@@ -610,7 +608,6 @@ <h3 id="inheritance-basics">Inheritance Basics</h3>
610608
<p>Here’s how the syntax of inheritance works:</p>
611609
<pre class="codesplit" data-code-language="javascript">//{!1} The <code>Animal</code> class is the parent (or superclass).
612610
class Animal {
613-
614611
constructor() {
615612
// <code>Dog</code> and <code>Cat</code> inherit the variable <code>age</code>.
616613
this.age = 0;
@@ -1101,7 +1098,6 @@ <h3 id="example-47-a-particle-system-with-a-repeller">Example 4.7: A Particle Sy
11011098

11021099
//{!1} The emitter manages all the particles.
11031100
class Emitter {
1104-
11051101
constructor(x, y) {
11061102
this.origin = createVector(x, y);
11071103
this.particles = [];

0 commit comments

Comments
 (0)