88import p5 from '../core/main' ;
99
1010/**
11- * Creates a new <a href="#/p5.Vector">p5.Vector</a> object. A vector is like
12- * an arrow pointing in space. Vectors have both magnitude (length)
13- * and direction. Calling `createVector()` without arguments sets the new
14- * vector's components to 0.
11+ * Creates a new <a href="#/p5.Vector">p5.Vector</a> object.
12+ *
13+ * A vector can be thought of in different ways. In one view, a vector is like
14+ * an arrow pointing in space. Vectors have both magnitude (length) and
15+ * direction. This view is helpful for programming motion.
16+ *
17+ * A vector's components determine its magnitude and direction. For example,
18+ * calling `createVector(3, 4)` creates a new
19+ * <a href="#/p5.Vector">p5.Vector</a> object with an x-component of 3 and a
20+ * y-component of 4. From the origin, this vector's tip is 3 units to the
21+ * right and 4 units down.
1522 *
1623 * <a href="#/p5.Vector">p5.Vector</a> objects are often used to program
1724 * motion because they simplify the math. For example, a moving ball has a
@@ -28,19 +35,28 @@ import p5 from '../core/main';
2835 * @param {Number } [y] y component of the vector.
2936 * @param {Number } [z] z component of the vector.
3037 * @return {p5.Vector } new <a href="#/p5.Vector">p5.Vector</a> object.
38+ *
3139 * @example
3240 * <div>
3341 * <code>
34- * let p1 = createVector(25, 25);
35- * let p2 = createVector(50, 50);
36- * let p3 = createVector(75, 75);
42+ * function setup() {
43+ * createCanvas(100, 100);
44+ *
45+ * background(200);
3746 *
38- * strokeWeight(5);
39- * point(p1 );
40- * point(p2 );
41- * point(p3 );
47+ * // Create p5.Vector objects.
48+ * let p1 = createVector(25, 25 );
49+ * let p2 = createVector(50, 50 );
50+ * let p3 = createVector(75, 75 );
4251 *
43- * describe('Three black dots form a diagonal line from top left to bottom right.');
52+ * // Draw the dots.
53+ * strokeWeight(5);
54+ * point(p1);
55+ * point(p2);
56+ * point(p3);
57+ *
58+ * describe('Three black dots form a diagonal line from top left to bottom right.');
59+ * }
4460 * </code>
4561 * </div>
4662 *
@@ -51,23 +67,29 @@ import p5 from '../core/main';
5167 *
5268 * function setup() {
5369 * createCanvas(100, 100);
54- * pos = createVector(width / 2, height);
70+ *
71+ * // Create p5.Vector objects.
72+ * pos = createVector(50, 100);
5573 * vel = createVector(0, -1);
74+ *
75+ * describe('A black dot moves from bottom to top on a gray square. The dot reappears at the bottom when it reaches the top.');
5676 * }
5777 *
5878 * function draw() {
5979 * background(200);
6080 *
81+ * // Add velocity to position.
6182 * pos.add(vel);
6283 *
84+ * // If the dot reaches the top of the canvas,
85+ * // restart from the bottom.
6386 * if (pos.y < 0) {
64- * pos.y = height ;
87+ * pos.y = 100 ;
6588 * }
6689 *
90+ * // Draw the dot.
6791 * strokeWeight(5);
6892 * point(pos);
69- *
70- * describe('A black dot moves from bottom to top on a gray square. The dot reappears at the bottom when it reaches the top.');
7193 * }
7294 * </code>
7395 * </div>
0 commit comments