(p5, fn)
| 3577 | } |
| 3578 | |
| 3579 | function vector(p5, fn) { |
| 3580 | /** |
| 3581 | * A class to describe a two or three-dimensional vector. |
| 3582 | * |
| 3583 | * A vector can be thought of in different ways. In one view, a vector is like |
| 3584 | * an arrow pointing in space. Vectors have both magnitude (length) and |
| 3585 | * direction. |
| 3586 | * |
| 3587 | * `p5.Vector` objects are often used to program motion because they simplify |
| 3588 | * the math. For example, a moving ball has a position and a velocity. |
| 3589 | * Position describes where the ball is in space. The ball's position vector |
| 3590 | * extends from the origin to the ball's center. Velocity describes the ball's |
| 3591 | * speed and the direction it's moving. If the ball is moving straight up, its |
| 3592 | * velocity vector points straight up. Adding the ball's velocity vector to |
| 3593 | * its position vector moves it, as in `pos.add(vel)`. Vector math relies on |
| 3594 | * methods inside the `p5.Vector` class. |
| 3595 | * |
| 3596 | * Note: <a href="#/p5/createVector">createVector()</a> is the recommended way |
| 3597 | * to make an instance of this class. |
| 3598 | * |
| 3599 | * @class p5.Vector |
| 3600 | * @param {Number} [x] x component of the vector. |
| 3601 | * @param {Number} [y] y component of the vector. |
| 3602 | * @param {Number} [z] z component of the vector. |
| 3603 | * @example |
| 3604 | * function setup() { |
| 3605 | * createCanvas(100, 100); |
| 3606 | * |
| 3607 | * background(200); |
| 3608 | * |
| 3609 | * // Create p5.Vector objects. |
| 3610 | * let p1 = createVector(25, 25); |
| 3611 | * let p2 = createVector(75, 75); |
| 3612 | * |
| 3613 | * // Style the points. |
| 3614 | * strokeWeight(5); |
| 3615 | * |
| 3616 | * // Draw the first point using a p5.Vector. |
| 3617 | * point(p1); |
| 3618 | * |
| 3619 | * // Draw the second point using a p5.Vector's components. |
| 3620 | * point(p2.x, p2.y); |
| 3621 | * |
| 3622 | * describe('Two black dots on a gray square, one at the top left and the other at the bottom right.'); |
| 3623 | * } |
| 3624 | * |
| 3625 | * @example |
| 3626 | * let pos; |
| 3627 | * let vel; |
| 3628 | * |
| 3629 | * function setup() { |
| 3630 | * createCanvas(100, 100); |
| 3631 | * |
| 3632 | * // Create p5.Vector objects. |
| 3633 | * pos = createVector(50, 100); |
| 3634 | * vel = createVector(0, -1); |
| 3635 | * |
| 3636 | * describe('A black dot moves from bottom to top on a gray square. The dot reappears at the bottom when it reaches the top.'); |
no outgoing calls
no test coverage detected