Skip to content

Commit

Permalink
Merge pull request #968 from nature-of-code/notion-update-docs
Browse files Browse the repository at this point in the history
[Notion] Update docs
  • Loading branch information
shiffman authored May 27, 2024
2 parents 6f1709a + 835258e commit 455a29a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion content/03_oscillation.html
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ <h2 id="properties-of-oscillation">Properties of Oscillation</h2>
<p>Once I have the amplitude and period, it’s time to write a formula to calculate the circle’s x-position as a function of time (the current frame count):</p>
<pre class="codesplit" data-code-language="javascript">// <code>amplitude</code> and <code>period</code> are my own variables; <code>frameCount</code> is built into p5.js.
let x = amplitude * sin(TWO_PI * frameCount / period);</pre>
<p>Think about what’s going here. First, whatever value the <code>sin()</code> function returns is multiplied by <code>amplitude</code>. As you saw in Figure 3.10, the output of the sine function oscillates between –1 and 1. Multiplying that value by my chosen amplitude—call it <em>a</em>—gives me the desired result: a value that oscillates between –<em>a</em> and <em>a</em>. (This is also a place where you could use p5.js’s <code>map()</code> function to map the output of <code>sin()</code> to a custom range.)</p>
<p>Think about what’s going on here. First, whatever value the <code>sin()</code> function returns is multiplied by <code>amplitude</code>. As you saw in Figure 3.10, the output of the sine function oscillates between –1 and 1. Multiplying that value by my chosen amplitude—call it <em>a</em>—gives me the desired result: a value that oscillates between –<em>a</em> and <em>a</em>. (This is also a place where you could use p5.js’s <code>map()</code> function to map the output of <code>sin()</code> to a custom range.)</p>
<p>Now, think about what’s inside the <code>sin()</code> function:</p>
<pre class="codesplit" data-code-language="javascript">TWO_PI * frameCount / period</pre>
<p>What’s going on here? Start with what you know. I’ve explained that sine has a period of <span data-type="equation">2\pi</span>, meaning it will start at 0 and repeat at <span data-type="equation">2\pi</span>, <span data-type="equation">4\pi</span>, <span data-type="equation">6\pi</span>, and so on. If my desired period of oscillation is 120 frames, I want the circle to be in the same position when <code>frameCount</code> is at 120 frames, 240 frames, 360 frames, and so on. Here, <code>frameCount</code> is the only value changing over time; it starts at 0 and counts upward. Let’s take a look at what the formula yields as <code>frameCount</code> increases.</p>
Expand Down
2 changes: 1 addition & 1 deletion content/09_ga.html
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ <h3 id="step-2-selection">Step 2: Selection</h3>
<tr>
<td>E</td>
<td>1.5</td>
<td>0.1</td>
<td>0.15</td>
<td>15%</td>
</tr>
</tbody>
Expand Down

0 comments on commit 455a29a

Please sign in to comment.