Notion - Update docs

This commit is contained in:
shiffman 2024-02-27 14:57:20 +00:00 committed by GitHub
parent 8177aa9988
commit 453263812e
3 changed files with 16 additions and 21 deletions

View file

@ -952,7 +952,6 @@ static add(v1, v2) {
<p>When calling a static method, instead of referencing an object instance, you reference the name of the class. Heres the right way to implement the vector addition example:</p>
<pre class="codesplit" data-code-language="javascript">let v = createVector(0, 0);
let u = createVector(4, 5);
<s>let w = v.add(u);</s>
<strong>let w = p5.Vector.add(v, u);</strong></pre>
<p>The <code>p5.Vector</code> class has static versions of <code>add()</code>, <code>sub()</code>, <code>mult()</code>, and <code>div()</code>. These static methods allow you to perform generic mathematical operations on vectors without changing the value of one of the input vectors in the process.</p>

View file

@ -515,22 +515,18 @@ function setup() {
<p>Imagine its a Saturday morning. Youve just gone out for a lovely jog, had a delicious bowl of cereal, and are sitting quietly at your computer with a cup of warm chamomile tea. Its your old friend so-and-sos birthday, and youve decided youd like to make a greeting card with p5.js. How about simulating some confetti? Purple confetti, pink confetti, star-shaped confetti, square confetti, fast confetti, fluttery confetti—all kinds of confetti, all with different appearances and different behaviors, exploding onto the screen all at once.</p>
<p>What you have is clearly a particle system: a collection of individual pieces (particles) of confetti. You might be able to cleverly redesign the <code>Particle</code> class to have variables that store color, shape, behavior, and more. To create a variety of particles, you might initialize those variables with random values. But what if some of your particles are drastically different? It could become very messy to have all sorts of code for different ways of being a particle in the same class. Another option might be to do the following:</p>
<pre class="codesplit" data-code-language="javascript">class HappyConfetti {
}
class FunConfetti {
}
class WackyConfetti {
}</pre>
<p>This is a nice solution: create three classes to describe the different kinds of confetti that are part of your particle system. The <code>Emitter</code> constructor could then have some code to pick randomly from the three classes when filling the array (note that this probabilistic method is the same one I employed in the random walk examples in Chapter 0):</p>
<div class="snip-below">
<pre class="codesplit" data-code-language="javascript">class Emitter {
constructor(num) {
this.particles = [];
for (let i = 0; i &#x3C; num; i++) {
let r = random(1);
// Randomly pick a kind of particle.