Skip to content

Commit a2a814e

Browse files
authored
Merge pull request #1026 from processing/fix-constants
2 parents acaa4f8 + d54ff31 commit a2a814e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+4999
-1496
lines changed

public/reference/data.json

Lines changed: 184 additions & 997 deletions
Large diffs are not rendered by default.

public/search-indices/en.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

public/search-indices/es.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

public/search-indices/hi.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

public/search-indices/ko.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

public/search-indices/zh-Hans.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
title: height
3+
module: DOM
4+
submodule: DOM
5+
file: src/dom/p5.Element.js
6+
description: A <code>Number</code> property that stores the element's height.
7+
line: 2493
8+
isConstructor: false
9+
itemtype: property
10+
class: p5.Element
11+
type: Number
12+
---
13+
14+
15+
# height
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
title: width
3+
module: DOM
4+
submodule: DOM
5+
file: src/dom/p5.Element.js
6+
description: A <code>Number</code> property that stores the element's width.
7+
line: 2493
8+
isConstructor: false
9+
itemtype: property
10+
class: p5.Element
11+
type: Number
12+
---
13+
14+
15+
# width
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
title: src
3+
module: DOM
4+
submodule: DOM
5+
file: src/dom/p5.MediaElement.js
6+
description: Path to the media element's source as a string.
7+
line: 1807
8+
isConstructor: false
9+
itemtype: property
10+
example:
11+
- |-
12+
<div>
13+
<code>
14+
let beat;
15+
16+
function setup() {
17+
createCanvas(100, 100);
18+
19+
// Create a p5.MediaElement using createAudio().
20+
beat = createAudio('/assets/beat.mp3');
21+
22+
describe('The text "https://p5js.org/reference//assets/beat.mp3" written in black on a gray background.');
23+
}
24+
25+
function draw() {
26+
background(200);
27+
28+
textWrap(CHAR);
29+
text(beat.src, 10, 10, 80, 80);
30+
}
31+
</code>
32+
</div>
33+
class: p5.MediaElement
34+
---
35+
36+
37+
# src

src/content/reference/en/p5.Vector/add.mdx

Lines changed: 151 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,163 @@ title: add
33
module: Math
44
submodule: ''
55
file: src/math/p5.Vector.js
6-
description: ''
7-
line: 3342
6+
description: >
7+
<p>Adds to a vector's components.</p>
8+
9+
<p><code>add()</code> can use separate numbers, as in <code>v.add(1, 2,
10+
3)</code>,
11+
12+
another <a href="/reference/p5/p5.Vector">p5.Vector</a> object, as in
13+
<code>v.add(v2)</code>, or
14+
15+
an array of numbers, as in <code>v.add([1, 2, 3])</code>.</p>
16+
17+
<p>If a value isn't provided for a component, it won't change. For
18+
19+
example, <code>v.add(4, 5)</code> adds 4 to <code>v.x</code>, 5 to
20+
<code>v.y</code>, and 0 to <code>v.z</code>.
21+
22+
Calling <code>add()</code> with no arguments, as in <code>v.add()</code>, has
23+
no effect.</p>
24+
25+
<p>This method supports N-dimensional vectors.</p>
26+
27+
<p>The static version of <code>add()</code>, as in <code>p5.Vector.add(v2,
28+
v1)</code>, returns a new
29+
30+
<a href="/reference/p5/p5.Vector">p5.Vector</a> object and doesn't change the
31+
32+
originals.</p>
33+
line: 517
834
isConstructor: false
935
itemtype: method
10-
example: []
36+
example:
37+
- |-
38+
<div>
39+
<code>
40+
function setup() {
41+
createCanvas(100, 100);
42+
43+
background(200);
44+
45+
// Style the points.
46+
strokeWeight(5);
47+
48+
// Top left.
49+
let pos = createVector(25, 25);
50+
point(pos);
51+
52+
// Top right.
53+
// Add numbers.
54+
pos.add(50, 0);
55+
point(pos);
56+
57+
// Bottom right.
58+
// Add a p5.Vector.
59+
let p2 = createVector(0, 50);
60+
pos.add(p2);
61+
point(pos);
62+
63+
// Bottom left.
64+
// Add an array.
65+
let arr = [-50, 0];
66+
pos.add(arr);
67+
point(pos);
68+
69+
describe('Four black dots arranged in a square on a gray background.');
70+
}
71+
</code>
72+
</div>
73+
74+
<div>
75+
<code>
76+
function setup() {
77+
createCanvas(100, 100);
78+
79+
background(200);
80+
81+
// Top left.
82+
let p1 = createVector(25, 25);
83+
84+
// Center.
85+
let p2 = createVector(50, 50);
86+
87+
// Bottom right.
88+
// Add p1 and p2.
89+
let p3 = p5.Vector.add(p1, p2);
90+
91+
// Draw the points.
92+
strokeWeight(5);
93+
point(p1);
94+
point(p2);
95+
point(p3);
96+
97+
describe('Three black dots in a diagonal line from top left to bottom right.');
98+
}
99+
</code>
100+
</div>
101+
102+
<div>
103+
<code>
104+
function setup() {
105+
createCanvas(100, 100);
106+
107+
describe('Three arrows drawn on a gray square. A red arrow extends from the top left corner to the center. A blue arrow extends from the tip of the red arrow. A purple arrow extends from the origin to the tip of the blue arrow.');
108+
}
109+
110+
function draw() {
111+
background(200);
112+
113+
let origin = createVector(0, 0);
114+
115+
// Draw the red arrow.
116+
let v1 = createVector(50, 50);
117+
drawArrow(origin, v1, 'red');
118+
119+
// Draw the blue arrow.
120+
let v2 = createVector(-30, 20);
121+
drawArrow(v1, v2, 'blue');
122+
123+
// Purple arrow.
124+
let v3 = p5.Vector.add(v1, v2);
125+
drawArrow(origin, v3, 'purple');
126+
}
127+
128+
// Draws an arrow between two vectors.
129+
function drawArrow(base, vec, myColor) {
130+
push();
131+
stroke(myColor);
132+
strokeWeight(3);
133+
fill(myColor);
134+
translate(base.x, base.y);
135+
line(0, 0, vec.x, vec.y);
136+
rotate(vec.heading());
137+
let arrowSize = 7;
138+
translate(vec.mag() - arrowSize, 0);
139+
triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);
140+
pop();
141+
}
142+
</code>
143+
</div>
11144
class: p5.Vector
12-
return:
13-
description: resulting <a href="#/p5.Vector">p5.Vector</a>.
14-
type: p5.Vector
15145
overloads:
16146
- params:
17-
- name: v1
18-
description: A <a href="#/p5.Vector">p5.Vector</a> to add
19-
type: p5.Vector
20-
- name: v2
21-
description: A <a href="#/p5.Vector">p5.Vector</a> to add
22-
type: p5.Vector
23-
- name: target
24-
description: vector to receive the result.
147+
- name: x
148+
description: x component of the vector to be added or an array of components.
149+
type: Number|Array
150+
- name: 'y'
151+
description: y component of the vector to be added.
25152
optional: 1
26-
type: p5.Vector
27-
return:
28-
description: resulting <a href="#/p5.Vector">p5.Vector</a>.
29-
type: p5.Vector
30-
chainable: false
153+
type: Number
154+
- name: z
155+
description: z component of the vector to be added.
156+
optional: 1
157+
type: Number
158+
- params:
159+
- name: value
160+
description: The vector to add
161+
type: 'p5.Vector|Number[]'
162+
chainable: true
31163
---
32164

33165

0 commit comments

Comments
 (0)