Skip to content

Commit

Permalink
Merge pull request #867 from nature-of-code/notion-update-docs
Browse files Browse the repository at this point in the history
6-11 final touches
  • Loading branch information
shiffman committed Feb 27, 2024
2 parents 0f064c4 + 8330f42 commit 4ef33aa
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 16 deletions.
3 changes: 0 additions & 3 deletions content/06_libraries.html
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,6 @@ <h3 id="example-64-polygon-shapes">Example 6.4: Polygon Shapes</h3>
vertices[2] = Vector.create(15, 0);
vertices[3] = Vector.create(0, 10);
vertices[4] = Vector.create(-20, 15);

//{!2} Make a body shaped by the vertices.
let options = { restitution: 1 };
this.body = Bodies.fromVertices(x, y, vertices, options);
Expand Down Expand Up @@ -602,10 +601,8 @@ <h3 id="exercise-63">Exercise 6.3</h3>
<pre class="codesplit" data-code-language="javascript">// Make the bodies.
let part1 = Bodies.rectangle(x, y, w, h);
let part2 = Bodies.circle(x, y, r);

// Join the two bodies together in an array.
let body = Body.create({ parts: [part1, part2] });

// Add the compound body to the world.
Composite.add(engine.world, body);</pre>
<p>While this does create a compound body by combining two shapes, the code isn’t quite right. If you run it, you’ll see that both shapes are centered on the same (<em>x</em>, <em>y</em>) position, as in Figure 6.7.</p>
Expand Down
2 changes: 0 additions & 2 deletions content/07_ca.html
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,6 @@ <h3 id="example-71-wolfram-elementary-cellular-automata">Example 7.1: Wolfram El
let generation = 0;
// Cell size
let w = 10;

//{!1} Rule 90
let ruleset = [0, 1, 0, 1, 1, 0, 1, 0];

Expand Down Expand Up @@ -370,7 +369,6 @@ <h3 id="example-71-wolfram-elementary-cellular-automata">Example 7.1: Wolfram El
nextgen[i] = rules(left, me, right);
}
cells = nextgen;

//{!1} The next generation
generation++;
}
Expand Down
3 changes: 0 additions & 3 deletions content/08_fractals.html
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,6 @@ <h3 id="the-monster-curve">The Monster Curve</h3>
</div>
<p>To accomplish the goal of treating each segment as an individual object, I must first decide what this object should be in the first place. What data should it store? What functions should it have? The Koch curve is a series of connected lines, and so I’ll think of each segment as a <em>KochLine</em>. Each <code>KochLine</code> object has a start point (a) and an end point (b). These points are represented as <code>p5.Vector</code> objects, and the line is drawn using the <code>line()</code> function:</p>
<pre class="codesplit" data-code-language="javascript">class KochLine {

//{!2} A line between two points: <code>a</code> and <code>b</code>
constructor(a, b) {
// <code>a</code> and <code>b</code> are <code>p5.Vector</code> objects.
Expand Down Expand Up @@ -489,13 +488,11 @@ <h3 id="the-deterministic-version">The Deterministic Version</h3>
//{!1} The root
line(0, 0, 0, -100);
translate(0, -100);

// Branch to the right
push();
rotate(PI / 6);
line(0, 0, 0, -100);
pop();

// Branch to the left
rotate(-PI / 6);
line(0, 0, 0, -100);</pre>
Expand Down
7 changes: 0 additions & 7 deletions content/10_nn.html
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ <h3 id="putting-it-all-together-1">Putting It All Together</h3>
<p>With the sum, I can then compute the output:</p>
<pre class="codesplit" data-code-language="javascript">// Step 3: Pass the sum through an activation function.
let output = activate(sum);

// The activation function
function activate(sum) {
//{!5} Return a 1 if positive, –1 if negative.
Expand Down Expand Up @@ -451,10 +450,8 @@ <h3 id="example-101-the-perceptron">Example 10.1: The Perceptron</h3>

function setup() {
createCanvas(640, 240);

// The perceptron has three inputs (including bias) and a learning rate of 0.0001.
perceptron = new Perceptron(3, 0.0001);

//{!1} Make 2,000 training data points.
for (let i = 0; i &#x3C; 2000; i++) {
let x = random(-width / 2, width / 2);
Expand All @@ -468,12 +465,10 @@ <h3 id="example-101-the-perceptron">Example 10.1: The Perceptron</h3>
// Reorient the canvas to match a traditional Cartesian plane.
translate(width / 2, height / 2);
scale(1, -1);

// Draw the line.
stroke(0);
strokeWeight(2);
line(-width / 2, f(-width / 2), width / 2, f(width / 2));

// Get the current <code>(x, y)</code> of the training data.
let x = training[count][0];
let y = training[count][1];
Expand All @@ -484,10 +479,8 @@ <h3 id="example-101-the-perceptron">Example 10.1: The Perceptron</h3>
}
// Train the perceptron.
perceptron.train(training[count], desired);

// For animation, train one point at a time.
count = (count + 1) % training.length;

// Draw all the points and color according to the output of the perceptron.
for (let dataPoint of training) {
let guess = perceptron.feedforward(dataPoint);
Expand Down
1 change: 0 additions & 1 deletion content/11_nn_ga.html
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,6 @@ <h3 id="sensing-the-environment">Sensing the Environment</h3>
this.r = 16;
// The creature has an array of sensors.
this.sensors = [];

// The creature has eight sensors.
let totalSensors = 8;
for (let i = 0; i &#x3C; totalSensors; i++) {
Expand Down

0 comments on commit 4ef33aa

Please sign in to comment.