mirror of
https://github.com/nature-of-code/noc-book-2
synced 2024-11-16 07:47:48 +01:00
Notion - Update docs
This commit is contained in:
parent
f4ffe38b5d
commit
84fa08a4a0
2 changed files with 0 additions and 4 deletions
|
@ -918,18 +918,15 @@ position.add(velocity);</pre>
|
|||
<p>Setting aside vectors for a second, take a look at the following code:</p>
|
||||
<pre class="codesplit" data-code-language="javascript">let x = 0;
|
||||
let y = 5;
|
||||
|
||||
x = x + y;</pre>
|
||||
<p>This is probably what you’re used to, yes? I give <code>x</code> a value of 0, add <code>y</code> to it, and now <code>x</code> is equal to 5. I could write similar code for adding two vectors:</p>
|
||||
<pre class="codesplit" data-code-language="javascript">let v = createVector(0, 0);
|
||||
let u = createVector(4, 5);
|
||||
|
||||
v.add(u);</pre>
|
||||
<p>The vector <code>v</code> has the value of (0, 0), I add the vector <code>u</code> to it, and now <code>v</code> is equal to (4, 5). Makes sense, right?</p>
|
||||
<p>Now consider this example:</p>
|
||||
<pre class="codesplit" data-code-language="javascript">let x = 0;
|
||||
let y = 5;
|
||||
|
||||
let z = x + y;</pre>
|
||||
<p>I give <code>x</code> a value of 0, add <code>y</code> to it, and store the result in a new variable <code>z</code>. The value of <code>x</code> doesn’t change here (neither does <code>y</code>)! This may seem like a trivial point, and one that’s quite intuitive when it comes to mathematical operations with simple numbers. However, it’s not so obvious with mathematical operations using <code>p5.Vector</code> objects. Let’s try to rewrite the example with vectors, based on what I’ve covered of the <code>p5.Vector</code> class so far:</p>
|
||||
<pre class="codesplit" data-code-language="javascript">let v = createVector(0, 0);
|
||||
|
|
|
@ -295,7 +295,6 @@ let ball = <span class="blank">Bodies</span>.<span class="blank">circle</span>(<
|
|||
<div class="avoid-break">
|
||||
<pre class="codesplit" data-code-language="javascript">// Store the canvas in a variable.
|
||||
let canvas = createCanvas(640, 360);
|
||||
|
||||
// Configure the renderer.
|
||||
let params = {
|
||||
canvas: canvas.elt,
|
||||
|
|
Loading…
Reference in a new issue