* @module Math * @for p5
(p5, fn)
| 4 | */ |
| 5 | |
| 6 | function math(p5, fn) { |
| 7 | /** |
| 8 | * Creates a new <a href="#/p5.Vector">p5.Vector</a> object. |
| 9 | * |
| 10 | * A vector can be thought of in different ways. In one view, a vector is like |
| 11 | * an arrow pointing in space. Vectors have both magnitude (length) and |
| 12 | * direction. This view is helpful for programming motion. |
| 13 | * |
| 14 | * A vector's components determine its magnitude and direction. For example, |
| 15 | * calling `createVector(3, 4)` creates a new |
| 16 | * <a href="#/p5.Vector">p5.Vector</a> object with an x-component of 3 and a |
| 17 | * y-component of 4. From the origin, this vector's tip is 3 units to the |
| 18 | * right and 4 units down. |
| 19 | * |
| 20 | * You can also pass N dimensions to the `createVector` function. For example, |
| 21 | * calling `createVector(1, 2, 3, 4)` creates a vector with four components. |
| 22 | * This allows for flexibility in representing vectors in higher-dimensional |
| 23 | * spaces. |
| 24 | * |
| 25 | * Calling `createVector()` **with no arguments** is **deprecated** and will emit |
| 26 | * a friendly warning. Use `createVector(0)`, `createVector(0, 0)`, or |
| 27 | * `createVector(0, 0, 0)` instead. |
| 28 | * |
| 29 | * <a href="#/p5.Vector">p5.Vector</a> objects are often used to program |
| 30 | * motion because they simplify the math. For example, a moving ball has a |
| 31 | * position and a velocity. Position describes where the ball is in space. The |
| 32 | * ball's position vector extends from the origin to the ball's center. |
| 33 | * Velocity describes the ball's speed and the direction it's moving. If the |
| 34 | * ball is moving straight up, its velocity vector points straight up. Adding |
| 35 | * the ball's velocity vector to its position vector moves it, as in |
| 36 | * `pos.add(vel)`. Vector math relies on methods inside the |
| 37 | * <a href="#/p5.Vector">p5.Vector</a> class. |
| 38 | * |
| 39 | * @method createVector |
| 40 | * @param {...Number} x List of numbers representing each component of the vector. |
| 41 | * @return {p5.Vector} new <a href="#/p5.Vector">p5.Vector</a> object. |
| 42 | * |
| 43 | * @example |
| 44 | * function setup() { |
| 45 | * createCanvas(100, 100); |
| 46 | * |
| 47 | * background(200); |
| 48 | * |
| 49 | * // Create p5.Vector objects. |
| 50 | * let p1 = createVector(25, 25); |
| 51 | * let p2 = createVector(50, 50); |
| 52 | * let p3 = createVector(75, 75); |
| 53 | * |
| 54 | * // Draw the dots. |
| 55 | * strokeWeight(5); |
| 56 | * point(p1); |
| 57 | * point(p2); |
| 58 | * point(p3); |
| 59 | * |
| 60 | * describe('Three black dots form a diagonal line from top left to bottom right.'); |
| 61 | * } |
| 62 | * |
| 63 | * @example |
no outgoing calls
no test coverage detected