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

6-11 final touches
This commit is contained in:
Daniel Shiffman 2024-02-26 21:41:44 -05:00 committed by GitHub
commit 4ef33aaea0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 0 additions and 16 deletions

View file

@ -551,7 +551,6 @@ let trapezoid = Bodies.trapezoid(x, y, width, height, slope);</pre>
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);
@ -602,10 +601,8 @@ let trapezoid = Bodies.trapezoid(x, y, width, height, slope);</pre>
<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 isnt quite right. If you run it, youll see that both shapes are centered on the same (<em>x</em>, <em>y</em>) position, as in Figure 6.7.</p>

View file

@ -336,7 +336,6 @@ let cells;
let generation = 0;
// Cell size
let w = 10;
//{!1} Rule 90
let ruleset = [0, 1, 0, 1, 1, 0, 1, 0];
@ -370,7 +369,6 @@ function draw() {
nextgen[i] = rules(left, me, right);
}
cells = nextgen;
//{!1} The next generation
generation++;
}

View file

@ -281,7 +281,6 @@ function drawCircles(x, y, radius) {
</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 Ill 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.
@ -489,13 +488,11 @@ line(0, 0, 0, -100);</pre>
//{!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>

View file

@ -164,7 +164,6 @@ for (let i = 0; i &#x3C; inputs.length; i++) {
<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.
@ -451,10 +450,8 @@ function f(x) {
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);
@ -468,12 +465,10 @@ function draw() {
// 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];
@ -484,10 +479,8 @@ function draw() {
}
// 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);

View file

@ -688,7 +688,6 @@ function draw() {
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++) {