p5 2.0.1 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/accessibility/color_namer.js +5 -5
- package/dist/accessibility/describe.js +10 -0
- package/dist/accessibility/index.js +5 -5
- package/dist/accessibility/outputs.js +21 -0
- package/dist/app.js +5 -5
- package/dist/color/color_conversion.js +5 -5
- package/dist/color/creating_reading.js +1 -1
- package/dist/color/index.js +2 -2
- package/dist/color/p5.Color.js +1 -1
- package/dist/color/setting.js +2 -2
- package/dist/{constants-C-g_eAdC.js → constants-tYr0tCl8.js} +19 -3
- package/dist/core/constants.js +1 -1
- package/dist/core/environment.js +6 -5
- package/dist/core/friendly_errors/fes_core.js +1 -1
- package/dist/core/friendly_errors/index.js +1 -1
- package/dist/core/friendly_errors/param_validator.js +41 -75
- package/dist/core/friendly_errors/sketch_reader.js +5 -5
- package/dist/core/friendly_errors/sketch_verifier.js +1 -1
- package/dist/core/friendly_errors/validate_params.js +5 -5
- package/dist/core/helpers.js +1 -1
- package/dist/core/init.js +5 -5
- package/dist/core/legacy.js +5 -5
- package/dist/core/main.js +5 -5
- package/dist/core/p5.Graphics.js +4 -4
- package/dist/core/p5.Renderer.js +3 -3
- package/dist/core/p5.Renderer2D.js +5 -5
- package/dist/core/rendering.js +4 -4
- package/dist/{creating_reading-D4AAKRbx.js → creating_reading-Cr8L2Jnm.js} +2 -2
- package/dist/dom/dom.js +10 -10
- package/dist/dom/index.js +2 -2
- package/dist/dom/p5.Element.js +2 -2
- package/dist/dom/p5.MediaElement.js +2 -2
- package/dist/events/acceleration.js +24 -24
- package/dist/events/keyboard.js +1 -2
- package/dist/image/const.js +1 -1
- package/dist/image/filterRenderer2D.js +4 -4
- package/dist/image/image.js +4 -4
- package/dist/image/index.js +4 -4
- package/dist/image/loading_displaying.js +4 -4
- package/dist/image/p5.Image.js +3 -3
- package/dist/image/pixels.js +1 -0
- package/dist/io/files.js +4 -4
- package/dist/io/index.js +4 -4
- package/dist/io/p5.TableRow.js +2 -2
- package/dist/{main-s72KWcUy.js → main-CAxvgiOV.js} +12 -9
- package/dist/math/Matrices/Matrix.js +1 -1
- package/dist/math/Matrices/MatrixNumjs.js +1 -1
- package/dist/math/index.js +1 -1
- package/dist/math/math.js +1 -1
- package/dist/math/p5.Matrix.js +1 -1
- package/dist/math/p5.Vector.js +1 -1
- package/dist/math/trigonometry.js +1 -1
- package/dist/{p5.Renderer-CwAYZOC2.js → p5.Renderer-Swjl9HQO.js} +5 -5
- package/dist/{rendering--aAe5aq3.js → rendering-B5TRR7aY.js} +101 -66
- package/dist/shape/2d_primitives.js +1 -1
- package/dist/shape/attributes.js +1 -1
- package/dist/shape/custom_shapes.js +2 -2
- package/dist/shape/index.js +2 -2
- package/dist/type/index.js +3 -3
- package/dist/type/p5.Font.js +3 -5
- package/dist/type/textCore.js +4 -4
- package/dist/webgl/3d_primitives.js +4 -4
- package/dist/webgl/GeometryBuilder.js +1 -1
- package/dist/webgl/ShapeBuilder.js +1 -1
- package/dist/webgl/index.js +4 -4
- package/dist/webgl/interaction.js +1 -1
- package/dist/webgl/light.js +4 -4
- package/dist/webgl/loading.js +4 -4
- package/dist/webgl/material.js +4 -4
- package/dist/webgl/p5.Camera.js +4 -4
- package/dist/webgl/p5.Framebuffer.js +4 -4
- package/dist/webgl/p5.Geometry.js +1 -1
- package/dist/webgl/p5.Quat.js +1 -1
- package/dist/webgl/p5.RendererGL.js +4 -4
- package/dist/webgl/p5.Shader.js +4 -4
- package/dist/webgl/p5.Texture.js +4 -4
- package/dist/webgl/text.js +32 -34
- package/lib/p5.esm.js +273 -225
- package/lib/p5.js +273 -225
- package/lib/p5.min.js +1 -1
- package/package.json +1 -2
- package/types/accessibility/color_namer.d.ts +8 -0
- package/types/accessibility/describe.d.ts +184 -0
- package/types/accessibility/gridOutput.d.ts +8 -0
- package/types/accessibility/outputs.d.ts +235 -0
- package/types/accessibility/textOutput.d.ts +8 -0
- package/types/color/color_conversion.d.ts +47 -0
- package/types/color/creating_reading.d.ts +1348 -0
- package/types/color/p5.Color.d.ts +1070 -0
- package/types/color/setting.d.ts +2085 -0
- package/types/core/constants.d.ts +341 -0
- package/types/core/environment.d.ts +668 -0
- package/types/core/friendly_errors/fes_core.d.ts +8 -0
- package/types/core/friendly_errors/file_errors.d.ts +8 -0
- package/types/core/friendly_errors/param_validator.d.ts +30 -0
- package/types/core/friendly_errors/sketch_reader.d.ts +8 -0
- package/types/core/friendly_errors/stacktrace.d.ts +11 -0
- package/types/core/friendly_errors/validate_params.d.ts +8 -0
- package/types/core/helpers.d.ts +8 -0
- package/types/core/legacy.d.ts +8 -0
- package/types/core/main.d.ts +5996 -0
- package/types/core/p5.Graphics.d.ts +484 -0
- package/types/core/p5.Renderer.d.ts +14 -0
- package/types/core/reference.d.ts +8 -0
- package/types/core/rendering.d.ts +481 -0
- package/types/core/structure.d.ts +492 -0
- package/types/core/transform.d.ts +1638 -0
- package/types/data/local_storage.d.ts +323 -0
- package/types/dom/dom.d.ts +1295 -0
- package/types/dom/p5.Element.d.ts +2011 -0
- package/types/dom/p5.File.d.ts +13 -0
- package/types/dom/p5.MediaElement.d.ts +1249 -0
- package/types/events/acceleration.d.ts +193 -0
- package/types/events/keyboard.d.ts +499 -0
- package/types/events/pointer.d.ts +782 -0
- package/types/global.d.ts +5542 -0
- package/types/image/filterRenderer2D.d.ts +54 -0
- package/types/image/image.d.ts +326 -0
- package/types/image/loading_displaying.d.ts +580 -0
- package/types/image/p5.Image.d.ts +5882 -0
- package/types/image/pixels.d.ts +832 -0
- package/types/io/files.d.ts +1447 -0
- package/types/io/p5.Table.d.ts +1247 -0
- package/types/io/p5.TableRow.d.ts +343 -0
- package/types/io/p5.XML.d.ts +1188 -0
- package/types/math/Matrices/Matrix.d.ts +1029 -0
- package/types/math/Matrices/MatrixNumjs.d.ts +8 -0
- package/types/math/calculation.d.ts +923 -0
- package/types/math/math.d.ts +90 -0
- package/types/math/noise.d.ts +311 -0
- package/types/math/p5.Matrix.d.ts +8 -0
- package/types/math/p5.Vector.d.ts +3416 -0
- package/types/math/random.d.ts +267 -0
- package/types/math/trigonometry.d.ts +663 -0
- package/types/p5.d.ts +6663 -0
- package/types/shape/2d_primitives.d.ts +1033 -0
- package/types/shape/attributes.d.ts +466 -0
- package/types/shape/curves.d.ts +740 -0
- package/types/shape/custom_shapes.d.ts +888 -0
- package/types/shape/vertex.d.ts +1141 -0
- package/types/type/p5.Font.d.ts +575 -0
- package/types/type/textCore.d.ts +1198 -0
- package/types/utilities/conversion.d.ts +894 -0
- package/types/utilities/time_date.d.ts +295 -0
- package/types/utilities/utility_functions.d.ts +587 -0
- package/types/webgl/3d_primitives.d.ts +1432 -0
- package/types/webgl/ShaderGenerator.d.ts +8 -0
- package/types/webgl/interaction.d.ts +371 -0
- package/types/webgl/light.d.ts +1184 -0
- package/types/webgl/loading.d.ts +481 -0
- package/types/webgl/material.d.ts +2656 -0
- package/types/webgl/p5.Camera.d.ts +3023 -0
- package/types/webgl/p5.DataArray.d.ts +61 -0
- package/types/webgl/p5.Framebuffer.d.ts +760 -0
- package/types/webgl/p5.Geometry.d.ts +1191 -0
- package/types/webgl/p5.Quat.d.ts +45 -0
- package/types/webgl/p5.RendererGL.d.ts +234 -0
- package/types/webgl/p5.Shader.d.ts +660 -0
- package/types/webgl/p5.Texture.d.ts +61 -0
- package/types/webgl/text.d.ts +74 -0
|
@@ -0,0 +1,1188 @@
|
|
|
1
|
+
// This file is auto-generated from JSDoc documentation
|
|
2
|
+
|
|
3
|
+
import p5 from 'p5';
|
|
4
|
+
|
|
5
|
+
declare module 'p5' {
|
|
6
|
+
class XML {
|
|
7
|
+
/**
|
|
8
|
+
* Returns the element's parent element as a new p5.XML
|
|
9
|
+
* object.
|
|
10
|
+
*/
|
|
11
|
+
getParent(): p5.XML;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Returns the element's name as a `String`.An XML element's name is given by its tag. For example, the element
|
|
15
|
+
* `<language>JavaScript</language>` has the name `language`.
|
|
16
|
+
*/
|
|
17
|
+
getName(): string;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Sets the element's tag name.An XML element's name is given by its tag. For example, the element
|
|
21
|
+
* `<language>JavaScript</language>` has the name `language`.The parameter, `name`, is the element's new name as a string. For example,
|
|
22
|
+
* calling `myXML.setName('planet')` will make the element's new tag name
|
|
23
|
+
* `<planet></planet>`.
|
|
24
|
+
*
|
|
25
|
+
* @param
|
|
26
|
+
*/
|
|
27
|
+
setName(name: string): void;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Returns `true` if the element has child elements and `false` if not.
|
|
31
|
+
*/
|
|
32
|
+
hasChildren(): boolean;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Returns an array with the names of the element's child elements as
|
|
36
|
+
* `String`s.
|
|
37
|
+
*/
|
|
38
|
+
listChildren(): string[];
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Returns an array with the element's child elements as new
|
|
42
|
+
* p5.XML objects.The parameter, `name`, is optional. If a string is passed, as in
|
|
43
|
+
* `myXML.getChildren('cat')`, then the method will only return child elements
|
|
44
|
+
* with the tag `<cat>`.
|
|
45
|
+
*
|
|
46
|
+
* @param
|
|
47
|
+
* @param
|
|
48
|
+
*/
|
|
49
|
+
getChildren(param: any, name: string): p5.XML[];
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Returns the first matching child element as a new
|
|
53
|
+
* p5.XML object.The parameter, `name`, is optional. If a string is passed, as in
|
|
54
|
+
* `myXML.getChild('cat')`, then the first child element with the tag
|
|
55
|
+
* `<cat>` will be returned. If a number is passed, as in
|
|
56
|
+
* `myXML.getChild(1)`, then the child element at that index will be returned.
|
|
57
|
+
*
|
|
58
|
+
* @param
|
|
59
|
+
* @param
|
|
60
|
+
*/
|
|
61
|
+
getChild(param: any, name: string | number): p5.XML;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Adds a new child element and returns a reference to it.The parameter, `child`, is the p5.XML object to add
|
|
65
|
+
* as a child element. For example, calling `myXML.addChild(otherXML)` inserts
|
|
66
|
+
* `otherXML` as a child element of `myXML`.
|
|
67
|
+
*
|
|
68
|
+
* @param
|
|
69
|
+
* @param
|
|
70
|
+
*/
|
|
71
|
+
addChild(node: any, child: p5.XML): p5.XML;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Removes the first matching child element.The parameter, `name`, is the child element to remove. If a string is
|
|
75
|
+
* passed, as in `myXML.removeChild('cat')`, then the first child element
|
|
76
|
+
* with the tag `<cat>` will be removed. If a number is passed, as in
|
|
77
|
+
* `myXML.removeChild(1)`, then the child element at that index will be
|
|
78
|
+
* removed.
|
|
79
|
+
*
|
|
80
|
+
* @param
|
|
81
|
+
* @param
|
|
82
|
+
*/
|
|
83
|
+
removeChild(param: any, name: string | number): void;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Returns the number of attributes the element has.
|
|
87
|
+
*/
|
|
88
|
+
getAttributeCount(): number;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Returns an `Array` with the names of the element's attributes.Note: Use
|
|
92
|
+
* myXML.getString() or
|
|
93
|
+
* myXML.getNum() to return an attribute's value.
|
|
94
|
+
*/
|
|
95
|
+
listAttributes(): string[];
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Returns `true` if the element has a given attribute and `false` if not.The parameter, `name`, is a string with the name of the attribute being
|
|
99
|
+
* checked.Note: Use
|
|
100
|
+
* myXML.getString() or
|
|
101
|
+
* myXML.getNum() to return an attribute's value.
|
|
102
|
+
*
|
|
103
|
+
* @param
|
|
104
|
+
*/
|
|
105
|
+
hasAttribute(name: string): boolean;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Return an attribute's value as a `Number`.The first parameter, `name`, is a string with the name of the attribute
|
|
109
|
+
* being checked. For example, calling `myXML.getNum('id')` returns the
|
|
110
|
+
* element's `id` attribute as a number.The second parameter, `defaultValue`, is optional. If a number is passed,
|
|
111
|
+
* as in `myXML.getNum('id', -1)`, it will be returned if the attribute
|
|
112
|
+
* doesn't exist or can't be converted to a number.Note: Use
|
|
113
|
+
* myXML.getString() or
|
|
114
|
+
* myXML.getNum() to return an attribute's value.
|
|
115
|
+
*
|
|
116
|
+
* @param
|
|
117
|
+
* @param
|
|
118
|
+
*/
|
|
119
|
+
getNum(name: string, defaultValue: number): number;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Return an attribute's value as a string.The first parameter, `name`, is a string with the name of the attribute
|
|
123
|
+
* being checked. For example, calling `myXML.getString('color')` returns the
|
|
124
|
+
* element's `id` attribute as a string.The second parameter, `defaultValue`, is optional. If a string is passed,
|
|
125
|
+
* as in `myXML.getString('color', 'deeppink')`, it will be returned if the
|
|
126
|
+
* attribute doesn't exist.Note: Use
|
|
127
|
+
* myXML.getString() or
|
|
128
|
+
* myXML.getNum() to return an attribute's value.
|
|
129
|
+
*
|
|
130
|
+
* @param
|
|
131
|
+
* @param
|
|
132
|
+
*/
|
|
133
|
+
getString(name: string, defaultValue: number): string;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Sets an attribute to a given value.The first parameter, `name`, is a string with the name of the attribute
|
|
137
|
+
* being set.The second parameter, `value`, is the attribute's new value. For example,
|
|
138
|
+
* calling `myXML.setAttribute('id', 123)` sets the `id` attribute to the
|
|
139
|
+
* value 123.
|
|
140
|
+
*
|
|
141
|
+
* @param
|
|
142
|
+
* @param
|
|
143
|
+
*/
|
|
144
|
+
setAttribute(name: string, value: number | string | boolean): void;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Returns the element's content as a `String`.The parameter, `defaultValue`, is optional. If a string is passed, as in
|
|
148
|
+
* `myXML.getContent('???')`, it will be returned if the element has no
|
|
149
|
+
* content.
|
|
150
|
+
*
|
|
151
|
+
* @param
|
|
152
|
+
*/
|
|
153
|
+
getContent(defaultValue: string): string;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Returns the element as a `String`.`myXML.serialize()` is useful for sending the element over the network or
|
|
157
|
+
* saving it to a file.
|
|
158
|
+
*/
|
|
159
|
+
serialize(): string;
|
|
160
|
+
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Returns the element's parent element as a new p5.XML
|
|
165
|
+
* object.
|
|
166
|
+
*
|
|
167
|
+
* @return parent element.
|
|
168
|
+
* @example <div>
|
|
169
|
+
* <code>
|
|
170
|
+
* let myXML;
|
|
171
|
+
*
|
|
172
|
+
* async function setup() {
|
|
173
|
+
* // Load the XML and create a p5.XML object.
|
|
174
|
+
* myXML = await loadXML('assets/animals.xml');
|
|
175
|
+
*
|
|
176
|
+
* createCanvas(100, 100);
|
|
177
|
+
*
|
|
178
|
+
* background(200);
|
|
179
|
+
*
|
|
180
|
+
* // Get an array with all mammal elements.
|
|
181
|
+
* let mammals = myXML.getChildren('mammal');
|
|
182
|
+
*
|
|
183
|
+
* // Get the first mammal element.
|
|
184
|
+
* let firstMammal = mammals[0];
|
|
185
|
+
*
|
|
186
|
+
* // Get the parent element.
|
|
187
|
+
* let parent = firstMammal.getParent();
|
|
188
|
+
*
|
|
189
|
+
* // Get the parent element's name.
|
|
190
|
+
* let name = parent.getName();
|
|
191
|
+
*
|
|
192
|
+
* // Style the text.
|
|
193
|
+
* textAlign(CENTER, CENTER);
|
|
194
|
+
* textFont('Courier New');
|
|
195
|
+
* textSize(14);
|
|
196
|
+
*
|
|
197
|
+
* // Display the parent element's name.
|
|
198
|
+
* text(name, 50, 50);
|
|
199
|
+
*
|
|
200
|
+
* describe('The word "animals" written in black on a gray background.');
|
|
201
|
+
* }
|
|
202
|
+
* </code>
|
|
203
|
+
* </div>
|
|
204
|
+
*/
|
|
205
|
+
function getParent(): p5.XML;
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Returns the element's name as a `String`.An XML element's name is given by its tag. For example, the element
|
|
209
|
+
* `<language>JavaScript</language>` has the name `language`.
|
|
210
|
+
*
|
|
211
|
+
* @return name of the element.
|
|
212
|
+
* @example <div>
|
|
213
|
+
* <code>
|
|
214
|
+
* let myXML;
|
|
215
|
+
*
|
|
216
|
+
* async function setup() {
|
|
217
|
+
* // Load the XML and create a p5.XML object.
|
|
218
|
+
* myXML = await loadXML('assets/animals.xml');
|
|
219
|
+
*
|
|
220
|
+
* createCanvas(100, 100);
|
|
221
|
+
*
|
|
222
|
+
* background(200);
|
|
223
|
+
*
|
|
224
|
+
* // Get an array with all mammal elements.
|
|
225
|
+
* let mammals = myXML.getChildren('mammal');
|
|
226
|
+
*
|
|
227
|
+
* // Get the first mammal element.
|
|
228
|
+
* let firstMammal = mammals[0];
|
|
229
|
+
*
|
|
230
|
+
* // Get the mammal element's name.
|
|
231
|
+
* let name = firstMammal.getName();
|
|
232
|
+
*
|
|
233
|
+
* // Style the text.
|
|
234
|
+
* textAlign(CENTER, CENTER);
|
|
235
|
+
* textFont('Courier New');
|
|
236
|
+
* textSize(14);
|
|
237
|
+
*
|
|
238
|
+
* // Display the element's name.
|
|
239
|
+
* text(name, 50, 50);
|
|
240
|
+
*
|
|
241
|
+
* describe('The word "mammal" written in black on a gray background.');
|
|
242
|
+
* }
|
|
243
|
+
* </code>
|
|
244
|
+
* </div>
|
|
245
|
+
*/
|
|
246
|
+
function getName(): string;
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Sets the element's tag name.An XML element's name is given by its tag. For example, the element
|
|
250
|
+
* `<language>JavaScript</language>` has the name `language`.The parameter, `name`, is the element's new name as a string. For example,
|
|
251
|
+
* calling `myXML.setName('planet')` will make the element's new tag name
|
|
252
|
+
* `<planet></planet>`.
|
|
253
|
+
*
|
|
254
|
+
* @param new tag name of the element.
|
|
255
|
+
* @example <div>
|
|
256
|
+
* <code>
|
|
257
|
+
* let myXML;
|
|
258
|
+
*
|
|
259
|
+
* async function setup() {
|
|
260
|
+
* // Load the XML and create a p5.XML object.
|
|
261
|
+
* myXML = await loadXML('assets/animals.xml');
|
|
262
|
+
*
|
|
263
|
+
* createCanvas(100, 100);
|
|
264
|
+
*
|
|
265
|
+
* background(200);
|
|
266
|
+
*
|
|
267
|
+
* // Get the element's original name.
|
|
268
|
+
* let oldName = myXML.getName();
|
|
269
|
+
*
|
|
270
|
+
* // Set the element's name.
|
|
271
|
+
* myXML.setName('monsters');
|
|
272
|
+
*
|
|
273
|
+
* // Get the element's new name.
|
|
274
|
+
* let newName = myXML.getName();
|
|
275
|
+
*
|
|
276
|
+
* // Style the text.
|
|
277
|
+
* textAlign(CENTER, CENTER);
|
|
278
|
+
* textFont('Courier New');
|
|
279
|
+
* textSize(14);
|
|
280
|
+
*
|
|
281
|
+
* // Display the element's names.
|
|
282
|
+
* text(oldName, 50, 33);
|
|
283
|
+
* text(newName, 50, 67);
|
|
284
|
+
*
|
|
285
|
+
* describe(
|
|
286
|
+
* 'The words "animals" and "monsters" written on separate lines. The text is black on a gray background.'
|
|
287
|
+
* );
|
|
288
|
+
* }
|
|
289
|
+
* </code></div>
|
|
290
|
+
*/
|
|
291
|
+
function setName(name: string): void;
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Returns `true` if the element has child elements and `false` if not.
|
|
295
|
+
*
|
|
296
|
+
* @return whether the element has children.
|
|
297
|
+
* @example <div>
|
|
298
|
+
* <code>
|
|
299
|
+
* let myXML;
|
|
300
|
+
*
|
|
301
|
+
* async function setup() {
|
|
302
|
+
* // Load the XML and create a p5.XML object.
|
|
303
|
+
* myXML = await loadXML('assets/animals.xml');
|
|
304
|
+
*
|
|
305
|
+
* createCanvas(100, 100);
|
|
306
|
+
*
|
|
307
|
+
* background(200);
|
|
308
|
+
*
|
|
309
|
+
* // Check whether the element has child elements.
|
|
310
|
+
* let isParent = myXML.hasChildren();
|
|
311
|
+
*
|
|
312
|
+
* // Style the text.
|
|
313
|
+
* textAlign(CENTER, CENTER);
|
|
314
|
+
* textFont('Courier New');
|
|
315
|
+
* textSize(14);
|
|
316
|
+
*
|
|
317
|
+
* // Style the text.
|
|
318
|
+
* if (isParent === true) {
|
|
319
|
+
* text('Parent', 50, 50);
|
|
320
|
+
* } else {
|
|
321
|
+
* text('Not Parent', 50, 50);
|
|
322
|
+
* }
|
|
323
|
+
*
|
|
324
|
+
* describe('The word "Parent" written in black on a gray background.');
|
|
325
|
+
* }
|
|
326
|
+
* </code>
|
|
327
|
+
* </div>
|
|
328
|
+
*/
|
|
329
|
+
function hasChildren(): boolean;
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Returns an array with the names of the element's child elements as
|
|
333
|
+
* `String`s.
|
|
334
|
+
*
|
|
335
|
+
* @return names of the child elements.
|
|
336
|
+
* @example <div>
|
|
337
|
+
* <code>
|
|
338
|
+
* let myXML;
|
|
339
|
+
*
|
|
340
|
+
* async function setup() {
|
|
341
|
+
* // Load the XML and create a p5.XML object.
|
|
342
|
+
* myXML = await loadXML('assets/animals.xml');
|
|
343
|
+
*
|
|
344
|
+
* createCanvas(100, 100);
|
|
345
|
+
*
|
|
346
|
+
* background(200);
|
|
347
|
+
*
|
|
348
|
+
* // Get the names of the element's children as an array.
|
|
349
|
+
* let children = myXML.listChildren();
|
|
350
|
+
*
|
|
351
|
+
* // Style the text.
|
|
352
|
+
* textAlign(LEFT, CENTER);
|
|
353
|
+
* textFont('Courier New');
|
|
354
|
+
* textSize(14);
|
|
355
|
+
*
|
|
356
|
+
* // Iterate over the array.
|
|
357
|
+
* for (let i = 0; i < children.length; i += 1) {
|
|
358
|
+
*
|
|
359
|
+
* // Calculate the y-coordinate.
|
|
360
|
+
* let y = (i + 1) * 25;
|
|
361
|
+
*
|
|
362
|
+
* // Display the child element's name.
|
|
363
|
+
* text(children[i], 10, y);
|
|
364
|
+
* }
|
|
365
|
+
*
|
|
366
|
+
* describe(
|
|
367
|
+
* 'The words "mammal", "mammal", "mammal", and "reptile" written on separate lines. The text is black on a gray background.'
|
|
368
|
+
* );
|
|
369
|
+
* }
|
|
370
|
+
* </code>
|
|
371
|
+
* </div>
|
|
372
|
+
*/
|
|
373
|
+
function listChildren(): string[];
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Returns an array with the element's child elements as new
|
|
377
|
+
* p5.XML objects.The parameter, `name`, is optional. If a string is passed, as in
|
|
378
|
+
* `myXML.getChildren('cat')`, then the method will only return child elements
|
|
379
|
+
* with the tag `<cat>`.
|
|
380
|
+
*
|
|
381
|
+
* @param name of the elements to return.
|
|
382
|
+
* @return child elements.
|
|
383
|
+
* @example <div>
|
|
384
|
+
* <code>
|
|
385
|
+
* let myXML;
|
|
386
|
+
*
|
|
387
|
+
* async function setup() {
|
|
388
|
+
* // Load the XML and create a p5.XML object.
|
|
389
|
+
* myXML = await loadXML('assets/animals.xml');
|
|
390
|
+
*
|
|
391
|
+
* createCanvas(100, 100);
|
|
392
|
+
*
|
|
393
|
+
* background(200);
|
|
394
|
+
*
|
|
395
|
+
* // Get an array of the child elements.
|
|
396
|
+
* let children = myXML.getChildren();
|
|
397
|
+
*
|
|
398
|
+
* // Style the text.
|
|
399
|
+
* textAlign(LEFT, CENTER);
|
|
400
|
+
* textFont('Courier New');
|
|
401
|
+
* textSize(14);
|
|
402
|
+
*
|
|
403
|
+
* // Iterate over the array.
|
|
404
|
+
* for (let i = 0; i < children.length; i += 1) {
|
|
405
|
+
*
|
|
406
|
+
* // Calculate the y-coordinate.
|
|
407
|
+
* let y = (i + 1) * 20;
|
|
408
|
+
*
|
|
409
|
+
* // Get the child element's content.
|
|
410
|
+
* let content = children[i].getContent();
|
|
411
|
+
*
|
|
412
|
+
* // Display the child element's content.
|
|
413
|
+
* text(content, 10, y);
|
|
414
|
+
* }
|
|
415
|
+
*
|
|
416
|
+
* describe(
|
|
417
|
+
* 'The words "Goat", "Leopard", "Zebra", and "Turtle" written on separate lines. The text is black on a gray background.'
|
|
418
|
+
* );
|
|
419
|
+
* }
|
|
420
|
+
* </code>
|
|
421
|
+
* </div>
|
|
422
|
+
*
|
|
423
|
+
* <div>
|
|
424
|
+
* <code>
|
|
425
|
+
* let myXML;
|
|
426
|
+
*
|
|
427
|
+
* async function setup() {
|
|
428
|
+
* // Load the XML and create a p5.XML object.
|
|
429
|
+
* myXML = await loadXML('assets/animals.xml');
|
|
430
|
+
*
|
|
431
|
+
* createCanvas(100, 100);
|
|
432
|
+
*
|
|
433
|
+
* background(200);
|
|
434
|
+
*
|
|
435
|
+
* // Get an array of the child elements
|
|
436
|
+
* // that are mammals.
|
|
437
|
+
* let children = myXML.getChildren('mammal');
|
|
438
|
+
*
|
|
439
|
+
* // Style the text.
|
|
440
|
+
* textAlign(LEFT, CENTER);
|
|
441
|
+
* textFont('Courier New');
|
|
442
|
+
* textSize(14);
|
|
443
|
+
*
|
|
444
|
+
* // Iterate over the array.
|
|
445
|
+
* for (let i = 0; i < children.length; i += 1) {
|
|
446
|
+
*
|
|
447
|
+
* // Calculate the y-coordinate.
|
|
448
|
+
* let y = (i + 1) * 20;
|
|
449
|
+
*
|
|
450
|
+
* // Get the child element's content.
|
|
451
|
+
* let content = children[i].getContent();
|
|
452
|
+
*
|
|
453
|
+
* // Display the child element's content.
|
|
454
|
+
* text(content, 10, y);
|
|
455
|
+
* }
|
|
456
|
+
*
|
|
457
|
+
* describe(
|
|
458
|
+
* 'The words "Goat", "Leopard", and "Zebra" written on separate lines. The text is black on a gray background.'
|
|
459
|
+
* );
|
|
460
|
+
* }
|
|
461
|
+
* </code>
|
|
462
|
+
* </div>
|
|
463
|
+
*/
|
|
464
|
+
function getChildren(param: any, name?: string): p5.XML[];
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Returns the first matching child element as a new
|
|
468
|
+
* p5.XML object.The parameter, `name`, is optional. If a string is passed, as in
|
|
469
|
+
* `myXML.getChild('cat')`, then the first child element with the tag
|
|
470
|
+
* `<cat>` will be returned. If a number is passed, as in
|
|
471
|
+
* `myXML.getChild(1)`, then the child element at that index will be returned.
|
|
472
|
+
*
|
|
473
|
+
* @param element name or index.
|
|
474
|
+
* @return child element.
|
|
475
|
+
* @example <div>
|
|
476
|
+
* <code>
|
|
477
|
+
* let myXML;
|
|
478
|
+
*
|
|
479
|
+
* async function setup() {
|
|
480
|
+
* // Load the XML and create a p5.XML object.
|
|
481
|
+
* myXML = await loadXML('assets/animals.xml');
|
|
482
|
+
*
|
|
483
|
+
* createCanvas(100, 100);
|
|
484
|
+
*
|
|
485
|
+
* background(200);
|
|
486
|
+
*
|
|
487
|
+
* // Get the first child element that is a mammal.
|
|
488
|
+
* let goat = myXML.getChild('mammal');
|
|
489
|
+
*
|
|
490
|
+
* // Style the text.
|
|
491
|
+
* textAlign(CENTER, CENTER);
|
|
492
|
+
* textFont('Courier New');
|
|
493
|
+
* textSize(14);
|
|
494
|
+
*
|
|
495
|
+
* // Get the child element's content.
|
|
496
|
+
* let content = goat.getContent();
|
|
497
|
+
*
|
|
498
|
+
* // Display the child element's content.
|
|
499
|
+
* text(content, 50, 50);
|
|
500
|
+
*
|
|
501
|
+
* describe('The word "Goat" written in black on a gray background.');
|
|
502
|
+
* }
|
|
503
|
+
* </code>
|
|
504
|
+
* </div>
|
|
505
|
+
*
|
|
506
|
+
* <div>
|
|
507
|
+
* <code>
|
|
508
|
+
* let myXML;
|
|
509
|
+
*
|
|
510
|
+
* async function setup() {
|
|
511
|
+
* // Load the XML and create a p5.XML object.
|
|
512
|
+
* myXML = await loadXML('assets/animals.xml');
|
|
513
|
+
*
|
|
514
|
+
* createCanvas(100, 100);
|
|
515
|
+
*
|
|
516
|
+
* background(200);
|
|
517
|
+
*
|
|
518
|
+
* // Get the child element at index 1.
|
|
519
|
+
* let leopard = myXML.getChild(1);
|
|
520
|
+
*
|
|
521
|
+
* // Style the text.
|
|
522
|
+
* textAlign(CENTER, CENTER);
|
|
523
|
+
* textFont('Courier New');
|
|
524
|
+
* textSize(14);
|
|
525
|
+
*
|
|
526
|
+
* // Get the child element's content.
|
|
527
|
+
* let content = leopard.getContent();
|
|
528
|
+
*
|
|
529
|
+
* // Display the child element's content.
|
|
530
|
+
* text(content, 50, 50);
|
|
531
|
+
*
|
|
532
|
+
* describe('The word "Leopard" written in black on a gray background.');
|
|
533
|
+
* }
|
|
534
|
+
* </code>
|
|
535
|
+
* </div>
|
|
536
|
+
*/
|
|
537
|
+
function getChild(param: any, name: string | number): p5.XML;
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* Adds a new child element and returns a reference to it.The parameter, `child`, is the p5.XML object to add
|
|
541
|
+
* as a child element. For example, calling `myXML.addChild(otherXML)` inserts
|
|
542
|
+
* `otherXML` as a child element of `myXML`.
|
|
543
|
+
*
|
|
544
|
+
* @param child element to add.
|
|
545
|
+
* @return added child element.
|
|
546
|
+
* @example <div>
|
|
547
|
+
* <code>
|
|
548
|
+
* let myXML;
|
|
549
|
+
*
|
|
550
|
+
* async function setup() {
|
|
551
|
+
* // Load the XML and create a p5.XML object.
|
|
552
|
+
* myXML = await loadXML('assets/animals.xml');
|
|
553
|
+
*
|
|
554
|
+
* createCanvas(100, 100);
|
|
555
|
+
*
|
|
556
|
+
* background(200);
|
|
557
|
+
*
|
|
558
|
+
* // Create a new p5.XML object.
|
|
559
|
+
* let newAnimal = new p5.XML();
|
|
560
|
+
*
|
|
561
|
+
* // Set its properties.
|
|
562
|
+
* newAnimal.setName('hydrozoa');
|
|
563
|
+
* newAnimal.setAttribute('id', 4);
|
|
564
|
+
* newAnimal.setAttribute('species', 'Physalia physalis');
|
|
565
|
+
* newAnimal.setContent('Bluebottle');
|
|
566
|
+
*
|
|
567
|
+
* // Add the child element.
|
|
568
|
+
* myXML.addChild(newAnimal);
|
|
569
|
+
*
|
|
570
|
+
* // Get the first child element that is a hydrozoa.
|
|
571
|
+
* let blueBottle = myXML.getChild('hydrozoa');
|
|
572
|
+
*
|
|
573
|
+
* // Style the text.
|
|
574
|
+
* textAlign(CENTER, CENTER);
|
|
575
|
+
* textFont('Courier New');
|
|
576
|
+
* textSize(14);
|
|
577
|
+
*
|
|
578
|
+
* // Get the child element's content.
|
|
579
|
+
* let content = blueBottle.getContent();
|
|
580
|
+
*
|
|
581
|
+
* // Display the child element's content.
|
|
582
|
+
* text(content, 50, 50);
|
|
583
|
+
*
|
|
584
|
+
* describe('The word "Bluebottle" written in black on a gray background.');
|
|
585
|
+
* }
|
|
586
|
+
* </code>
|
|
587
|
+
* </div>
|
|
588
|
+
*/
|
|
589
|
+
function addChild(node: any, child: p5.XML): p5.XML;
|
|
590
|
+
|
|
591
|
+
/**
|
|
592
|
+
* Removes the first matching child element.The parameter, `name`, is the child element to remove. If a string is
|
|
593
|
+
* passed, as in `myXML.removeChild('cat')`, then the first child element
|
|
594
|
+
* with the tag `<cat>` will be removed. If a number is passed, as in
|
|
595
|
+
* `myXML.removeChild(1)`, then the child element at that index will be
|
|
596
|
+
* removed.
|
|
597
|
+
*
|
|
598
|
+
* @param name or index of the child element to remove.
|
|
599
|
+
* @example <div>
|
|
600
|
+
* <code>
|
|
601
|
+
* let myXML;
|
|
602
|
+
*
|
|
603
|
+
* async function setup() {
|
|
604
|
+
* // Load the XML and create a p5.XML object.
|
|
605
|
+
* myXML = await loadXML('assets/animals.xml');
|
|
606
|
+
*
|
|
607
|
+
* createCanvas(100, 100);
|
|
608
|
+
*
|
|
609
|
+
* background(200);
|
|
610
|
+
*
|
|
611
|
+
* // Remove the first mammal element.
|
|
612
|
+
* myXML.removeChild('mammal');
|
|
613
|
+
*
|
|
614
|
+
* // Get an array of child elements.
|
|
615
|
+
* let children = myXML.getChildren();
|
|
616
|
+
*
|
|
617
|
+
* // Style the text.
|
|
618
|
+
* textAlign(LEFT, CENTER);
|
|
619
|
+
* textFont('Courier New');
|
|
620
|
+
* textSize(14);
|
|
621
|
+
*
|
|
622
|
+
* // Iterate over the array.
|
|
623
|
+
* for (let i = 0; i < children.length; i += 1) {
|
|
624
|
+
*
|
|
625
|
+
* // Calculate the y-coordinate.
|
|
626
|
+
* let y = (i + 1) * 25;
|
|
627
|
+
*
|
|
628
|
+
* // Get the child element's content.
|
|
629
|
+
* let content = children[i].getContent();
|
|
630
|
+
*
|
|
631
|
+
* // Display the child element's content.
|
|
632
|
+
* text(content, 10, y);
|
|
633
|
+
* }
|
|
634
|
+
*
|
|
635
|
+
* describe(
|
|
636
|
+
* 'The words "Leopard", "Zebra", and "Turtle" written on separate lines. The text is black on a gray background.'
|
|
637
|
+
* );
|
|
638
|
+
* }
|
|
639
|
+
* </code>
|
|
640
|
+
* </div>
|
|
641
|
+
*
|
|
642
|
+
* <div>
|
|
643
|
+
* <code>
|
|
644
|
+
* let myXML;
|
|
645
|
+
*
|
|
646
|
+
* async function setup() {
|
|
647
|
+
* // Load the XML and create a p5.XML object.
|
|
648
|
+
* myXML = await loadXML('assets/animals.xml');
|
|
649
|
+
*
|
|
650
|
+
* createCanvas(100, 100);
|
|
651
|
+
*
|
|
652
|
+
* background(200);
|
|
653
|
+
*
|
|
654
|
+
* // Remove the element at index 2.
|
|
655
|
+
* myXML.removeChild(2);
|
|
656
|
+
*
|
|
657
|
+
* // Get an array of child elements.
|
|
658
|
+
* let children = myXML.getChildren();
|
|
659
|
+
*
|
|
660
|
+
* // Style the text.
|
|
661
|
+
* textAlign(LEFT, CENTER);
|
|
662
|
+
* textFont('Courier New');
|
|
663
|
+
* textSize(14);
|
|
664
|
+
*
|
|
665
|
+
* // Iterate over the array.
|
|
666
|
+
* for (let i = 0; i < children.length; i += 1) {
|
|
667
|
+
*
|
|
668
|
+
* // Calculate the y-coordinate.
|
|
669
|
+
* let y = (i + 1) * 25;
|
|
670
|
+
*
|
|
671
|
+
* // Get the child element's content.
|
|
672
|
+
* let content = children[i].getContent();
|
|
673
|
+
*
|
|
674
|
+
* // Display the child element's content.
|
|
675
|
+
* text(content, 10, y);
|
|
676
|
+
* }
|
|
677
|
+
*
|
|
678
|
+
* describe(
|
|
679
|
+
* 'The words "Goat", "Leopard", and "Turtle" written on separate lines. The text is black on a gray background.'
|
|
680
|
+
* );
|
|
681
|
+
* }
|
|
682
|
+
* </code>
|
|
683
|
+
* </div>
|
|
684
|
+
*/
|
|
685
|
+
function removeChild(param: any, name: string | number): void;
|
|
686
|
+
|
|
687
|
+
/**
|
|
688
|
+
* Returns the number of attributes the element has.
|
|
689
|
+
*
|
|
690
|
+
* @return number of attributes.
|
|
691
|
+
* @example <div>
|
|
692
|
+
* <code>
|
|
693
|
+
* let myXML;
|
|
694
|
+
*
|
|
695
|
+
* async function setup() {
|
|
696
|
+
* // Load the XML and create a p5.XML object.
|
|
697
|
+
* myXML = await loadXML('assets/animals.xml');
|
|
698
|
+
*
|
|
699
|
+
* createCanvas(100, 100);
|
|
700
|
+
*
|
|
701
|
+
* background(200);
|
|
702
|
+
*
|
|
703
|
+
* // Get the first child element.
|
|
704
|
+
* let first = myXML.getChild(0);
|
|
705
|
+
*
|
|
706
|
+
* // Get the number of attributes.
|
|
707
|
+
* let numAttributes = first.getAttributeCount();
|
|
708
|
+
*
|
|
709
|
+
* // Style the text.
|
|
710
|
+
* textAlign(CENTER, CENTER);
|
|
711
|
+
* textFont('Courier New');
|
|
712
|
+
* textSize(14);
|
|
713
|
+
*
|
|
714
|
+
* // Display the number of attributes.
|
|
715
|
+
* text(numAttributes, 50, 50);
|
|
716
|
+
*
|
|
717
|
+
* describe('The number "2" written in black on a gray background.');
|
|
718
|
+
* }
|
|
719
|
+
* </code>
|
|
720
|
+
* </div>
|
|
721
|
+
*/
|
|
722
|
+
function getAttributeCount(): number;
|
|
723
|
+
|
|
724
|
+
/**
|
|
725
|
+
* Returns an `Array` with the names of the element's attributes.Note: Use
|
|
726
|
+
* myXML.getString() or
|
|
727
|
+
* myXML.getNum() to return an attribute's value.
|
|
728
|
+
*
|
|
729
|
+
* @return attribute names.
|
|
730
|
+
* @example <div>
|
|
731
|
+
* <code>
|
|
732
|
+
* let myXML;
|
|
733
|
+
*
|
|
734
|
+
* async function setup() {
|
|
735
|
+
* // Load the XML and create a p5.XML object.
|
|
736
|
+
* myXML = await loadXML('assets/animals.xml');
|
|
737
|
+
*
|
|
738
|
+
* createCanvas(100, 100);
|
|
739
|
+
*
|
|
740
|
+
* background(200);
|
|
741
|
+
*
|
|
742
|
+
* // Get the first child element.
|
|
743
|
+
* let first = myXML.getChild(0);
|
|
744
|
+
*
|
|
745
|
+
* // Get the number of attributes.
|
|
746
|
+
* let attributes = first.listAttributes();
|
|
747
|
+
*
|
|
748
|
+
* // Style the text.
|
|
749
|
+
* textAlign(CENTER, CENTER);
|
|
750
|
+
* textFont('Courier New');
|
|
751
|
+
* textSize(14);
|
|
752
|
+
*
|
|
753
|
+
* // Display the element's attributes.
|
|
754
|
+
* text(attributes, 50, 50);
|
|
755
|
+
*
|
|
756
|
+
* describe('The text "id,species" written in black on a gray background.');
|
|
757
|
+
* }
|
|
758
|
+
* </code>
|
|
759
|
+
* </div>
|
|
760
|
+
*/
|
|
761
|
+
function listAttributes(): string[];
|
|
762
|
+
|
|
763
|
+
/**
|
|
764
|
+
* Returns `true` if the element has a given attribute and `false` if not.The parameter, `name`, is a string with the name of the attribute being
|
|
765
|
+
* checked.Note: Use
|
|
766
|
+
* myXML.getString() or
|
|
767
|
+
* myXML.getNum() to return an attribute's value.
|
|
768
|
+
*
|
|
769
|
+
* @param name of the attribute to be checked.
|
|
770
|
+
* @return whether the element has the attribute.
|
|
771
|
+
* @example <div>
|
|
772
|
+
* <code>
|
|
773
|
+
* let myXML;
|
|
774
|
+
*
|
|
775
|
+
* async function setup() {
|
|
776
|
+
* // Load the XML and create a p5.XML object.
|
|
777
|
+
* myXML = await loadXML('assets/animals.xml');
|
|
778
|
+
*
|
|
779
|
+
* createCanvas(100, 100);
|
|
780
|
+
*
|
|
781
|
+
* background(200);
|
|
782
|
+
*
|
|
783
|
+
* // Get the first mammal child element.
|
|
784
|
+
* let mammal = myXML.getChild('mammal');
|
|
785
|
+
*
|
|
786
|
+
* // Check whether the element has an
|
|
787
|
+
* // species attribute.
|
|
788
|
+
* let hasSpecies = mammal.hasAttribute('species');
|
|
789
|
+
*
|
|
790
|
+
* // Style the text.
|
|
791
|
+
* textAlign(CENTER, CENTER);
|
|
792
|
+
* textFont('Courier New');
|
|
793
|
+
* textSize(14);
|
|
794
|
+
*
|
|
795
|
+
* // Display whether the element has a species attribute.
|
|
796
|
+
* if (hasSpecies === true) {
|
|
797
|
+
* text('Species', 50, 50);
|
|
798
|
+
* } else {
|
|
799
|
+
* text('No species', 50, 50);
|
|
800
|
+
* }
|
|
801
|
+
*
|
|
802
|
+
* describe('The text "Species" written in black on a gray background.');
|
|
803
|
+
* }
|
|
804
|
+
* </code>
|
|
805
|
+
* </div>
|
|
806
|
+
*/
|
|
807
|
+
function hasAttribute(name: string): boolean;
|
|
808
|
+
|
|
809
|
+
/**
|
|
810
|
+
* Return an attribute's value as a `Number`.The first parameter, `name`, is a string with the name of the attribute
|
|
811
|
+
* being checked. For example, calling `myXML.getNum('id')` returns the
|
|
812
|
+
* element's `id` attribute as a number.The second parameter, `defaultValue`, is optional. If a number is passed,
|
|
813
|
+
* as in `myXML.getNum('id', -1)`, it will be returned if the attribute
|
|
814
|
+
* doesn't exist or can't be converted to a number.Note: Use
|
|
815
|
+
* myXML.getString() or
|
|
816
|
+
* myXML.getNum() to return an attribute's value.
|
|
817
|
+
*
|
|
818
|
+
* @param name of the attribute to be checked.
|
|
819
|
+
* @param value to return if the attribute doesn't exist.
|
|
820
|
+
* @return attribute value as a number.
|
|
821
|
+
* @example <div>
|
|
822
|
+
* <code>
|
|
823
|
+
* let myXML;
|
|
824
|
+
*
|
|
825
|
+
* async function setup() {
|
|
826
|
+
* // Load the XML and create a p5.XML object.
|
|
827
|
+
* myXML = await loadXML('assets/animals.xml');
|
|
828
|
+
*
|
|
829
|
+
* createCanvas(100, 100);
|
|
830
|
+
*
|
|
831
|
+
* background(200);
|
|
832
|
+
*
|
|
833
|
+
* // Get the first reptile child element.
|
|
834
|
+
* let reptile = myXML.getChild('reptile');
|
|
835
|
+
*
|
|
836
|
+
* // Get the reptile's content.
|
|
837
|
+
* let content = reptile.getContent();
|
|
838
|
+
*
|
|
839
|
+
* // Get the reptile's ID.
|
|
840
|
+
* let id = reptile.getNum('id');
|
|
841
|
+
*
|
|
842
|
+
* // Style the text.
|
|
843
|
+
* textAlign(LEFT, CENTER);
|
|
844
|
+
* textFont('Courier New');
|
|
845
|
+
* textSize(14);
|
|
846
|
+
*
|
|
847
|
+
* // Display the ID attribute.
|
|
848
|
+
* text(`${content} is ${id + 1}th`, 5, 50, 90);
|
|
849
|
+
*
|
|
850
|
+
* describe(`The text "${content} is ${id + 1}th" written in black on a gray background.`);
|
|
851
|
+
* }
|
|
852
|
+
* </code>
|
|
853
|
+
* </div>
|
|
854
|
+
*
|
|
855
|
+
* <div>
|
|
856
|
+
* <code>
|
|
857
|
+
* let myXML;
|
|
858
|
+
*
|
|
859
|
+
* async function setup() {
|
|
860
|
+
* // Load the XML and create a p5.XML object.
|
|
861
|
+
* myXML = await loadXML('assets/animals.xml');
|
|
862
|
+
*
|
|
863
|
+
* createCanvas(100, 100);
|
|
864
|
+
*
|
|
865
|
+
* background(200);
|
|
866
|
+
*
|
|
867
|
+
* // Get the first reptile child element.
|
|
868
|
+
* let reptile = myXML.getChild('reptile');
|
|
869
|
+
*
|
|
870
|
+
* // Get the reptile's content.
|
|
871
|
+
* let content = reptile.getContent();
|
|
872
|
+
*
|
|
873
|
+
* // Get the reptile's size.
|
|
874
|
+
* let weight = reptile.getNum('weight', 135);
|
|
875
|
+
*
|
|
876
|
+
* // Style the text.
|
|
877
|
+
* textAlign(LEFT, CENTER);
|
|
878
|
+
* textFont('Courier New');
|
|
879
|
+
* textSize(14);
|
|
880
|
+
*
|
|
881
|
+
* // Display the ID attribute.
|
|
882
|
+
* text(`${content} is ${weight}kg`, 5, 50, 90);
|
|
883
|
+
*
|
|
884
|
+
* describe(
|
|
885
|
+
* `The text "${content} is ${weight}kg" written in black on a gray background.`
|
|
886
|
+
* );
|
|
887
|
+
* }
|
|
888
|
+
* </code>
|
|
889
|
+
* </div>
|
|
890
|
+
*/
|
|
891
|
+
function getNum(name: string, defaultValue?: number): number;
|
|
892
|
+
|
|
893
|
+
/**
|
|
894
|
+
* Return an attribute's value as a string.The first parameter, `name`, is a string with the name of the attribute
|
|
895
|
+
* being checked. For example, calling `myXML.getString('color')` returns the
|
|
896
|
+
* element's `id` attribute as a string.The second parameter, `defaultValue`, is optional. If a string is passed,
|
|
897
|
+
* as in `myXML.getString('color', 'deeppink')`, it will be returned if the
|
|
898
|
+
* attribute doesn't exist.Note: Use
|
|
899
|
+
* myXML.getString() or
|
|
900
|
+
* myXML.getNum() to return an attribute's value.
|
|
901
|
+
*
|
|
902
|
+
* @param name of the attribute to be checked.
|
|
903
|
+
* @param value to return if the attribute doesn't exist.
|
|
904
|
+
* @return attribute value as a string.
|
|
905
|
+
* @example <div>
|
|
906
|
+
* <code>
|
|
907
|
+
* let myXML;
|
|
908
|
+
*
|
|
909
|
+
* async function setup() {
|
|
910
|
+
* // Load the XML and create a p5.XML object.
|
|
911
|
+
* myXML = await loadXML('assets/animals.xml');
|
|
912
|
+
*
|
|
913
|
+
* createCanvas(100, 100);
|
|
914
|
+
*
|
|
915
|
+
* background(200);
|
|
916
|
+
*
|
|
917
|
+
* // Get the first reptile child element.
|
|
918
|
+
* let reptile = myXML.getChild('reptile');
|
|
919
|
+
*
|
|
920
|
+
* // Get the reptile's content.
|
|
921
|
+
* let content = reptile.getContent();
|
|
922
|
+
*
|
|
923
|
+
* // Get the reptile's species.
|
|
924
|
+
* let species = reptile.getString('species');
|
|
925
|
+
*
|
|
926
|
+
* // Style the text.
|
|
927
|
+
* textAlign(LEFT, CENTER);
|
|
928
|
+
* textFont('Courier New');
|
|
929
|
+
* textSize(14);
|
|
930
|
+
*
|
|
931
|
+
* // Display the species attribute.
|
|
932
|
+
* text(`${content}: ${species}`, 5, 50, 90);
|
|
933
|
+
*
|
|
934
|
+
* describe(`The text "${content}: ${species}" written in black on a gray background.`);
|
|
935
|
+
* }
|
|
936
|
+
* </code>
|
|
937
|
+
* </div>
|
|
938
|
+
*
|
|
939
|
+
* <div>
|
|
940
|
+
* <code>
|
|
941
|
+
* let myXML;
|
|
942
|
+
*
|
|
943
|
+
* async function setup() {
|
|
944
|
+
* // Load the XML and create a p5.XML object.
|
|
945
|
+
* myXML = await loadXML('assets/animals.xml');
|
|
946
|
+
*
|
|
947
|
+
* createCanvas(100, 100);
|
|
948
|
+
*
|
|
949
|
+
* background(200);
|
|
950
|
+
*
|
|
951
|
+
* // Get the first reptile child element.
|
|
952
|
+
* let reptile = myXML.getChild('reptile');
|
|
953
|
+
*
|
|
954
|
+
* // Get the reptile's content.
|
|
955
|
+
* let content = reptile.getContent();
|
|
956
|
+
*
|
|
957
|
+
* // Get the reptile's color.
|
|
958
|
+
* let attribute = reptile.getString('color', 'green');
|
|
959
|
+
*
|
|
960
|
+
* // Style the text.
|
|
961
|
+
* textAlign(CENTER, CENTER);
|
|
962
|
+
* textFont('Courier New');
|
|
963
|
+
* textSize(14);
|
|
964
|
+
* fill(attribute);
|
|
965
|
+
*
|
|
966
|
+
* // Display the element's content.
|
|
967
|
+
* text(content, 50, 50);
|
|
968
|
+
*
|
|
969
|
+
* describe(`The text "${content}" written in green on a gray background.`);
|
|
970
|
+
* }
|
|
971
|
+
* </code>
|
|
972
|
+
* </div>
|
|
973
|
+
*/
|
|
974
|
+
function getString(name: string, defaultValue?: number): string;
|
|
975
|
+
|
|
976
|
+
/**
|
|
977
|
+
* Sets an attribute to a given value.The first parameter, `name`, is a string with the name of the attribute
|
|
978
|
+
* being set.The second parameter, `value`, is the attribute's new value. For example,
|
|
979
|
+
* calling `myXML.setAttribute('id', 123)` sets the `id` attribute to the
|
|
980
|
+
* value 123.
|
|
981
|
+
*
|
|
982
|
+
* @param name of the attribute to be set.
|
|
983
|
+
* @param attribute's new value.
|
|
984
|
+
* @example <div>
|
|
985
|
+
* <code>
|
|
986
|
+
* let myXML;
|
|
987
|
+
*
|
|
988
|
+
* async function setup() {
|
|
989
|
+
* // Load the XML and create a p5.XML object.
|
|
990
|
+
* myXML = await loadXML('assets/animals.xml');
|
|
991
|
+
*
|
|
992
|
+
* createCanvas(100, 100);
|
|
993
|
+
*
|
|
994
|
+
* background(200);
|
|
995
|
+
*
|
|
996
|
+
* // Get the first reptile child element.
|
|
997
|
+
* let reptile = myXML.getChild('reptile');
|
|
998
|
+
*
|
|
999
|
+
* // Set the reptile's color.
|
|
1000
|
+
* reptile.setAttribute('color', 'green');
|
|
1001
|
+
*
|
|
1002
|
+
* // Get the reptile's content.
|
|
1003
|
+
* let content = reptile.getContent();
|
|
1004
|
+
*
|
|
1005
|
+
* // Get the reptile's color.
|
|
1006
|
+
* let attribute = reptile.getString('color');
|
|
1007
|
+
*
|
|
1008
|
+
* // Style the text.
|
|
1009
|
+
* textAlign(LEFT, CENTER);
|
|
1010
|
+
* textFont('Courier New');
|
|
1011
|
+
* textSize(14);
|
|
1012
|
+
*
|
|
1013
|
+
* // Display the element's content.
|
|
1014
|
+
* text(`${content} is ${attribute}`, 5, 50, 90);
|
|
1015
|
+
*
|
|
1016
|
+
* describe(
|
|
1017
|
+
* `The text "${content} is ${attribute}" written in green on a gray background.`
|
|
1018
|
+
* );
|
|
1019
|
+
* }
|
|
1020
|
+
* </code>
|
|
1021
|
+
* </div>
|
|
1022
|
+
*/
|
|
1023
|
+
function setAttribute(name: string, value: number | string | boolean): void;
|
|
1024
|
+
|
|
1025
|
+
/**
|
|
1026
|
+
* Returns the element's content as a `String`.The parameter, `defaultValue`, is optional. If a string is passed, as in
|
|
1027
|
+
* `myXML.getContent('???')`, it will be returned if the element has no
|
|
1028
|
+
* content.
|
|
1029
|
+
*
|
|
1030
|
+
* @param value to return if the element has no
|
|
1031
|
+
* content.
|
|
1032
|
+
* @return element's content as a string.
|
|
1033
|
+
* @example <div>
|
|
1034
|
+
* <code>
|
|
1035
|
+
* let myXML;
|
|
1036
|
+
*
|
|
1037
|
+
* async function setup() {
|
|
1038
|
+
* // Load the XML and create a p5.XML object.
|
|
1039
|
+
* myXML = await loadXML('assets/animals.xml');
|
|
1040
|
+
*
|
|
1041
|
+
* createCanvas(100, 100);
|
|
1042
|
+
*
|
|
1043
|
+
* background(200);
|
|
1044
|
+
*
|
|
1045
|
+
* // Get the first reptile child element.
|
|
1046
|
+
* let reptile = myXML.getChild('reptile');
|
|
1047
|
+
*
|
|
1048
|
+
* // Get the reptile's content.
|
|
1049
|
+
* let content = reptile.getContent();
|
|
1050
|
+
*
|
|
1051
|
+
* // Style the text.
|
|
1052
|
+
* textAlign(CENTER, CENTER);
|
|
1053
|
+
* textFont('Courier New');
|
|
1054
|
+
* textSize(14);
|
|
1055
|
+
*
|
|
1056
|
+
* // Display the element's content.
|
|
1057
|
+
* text(content, 5, 50, 90);
|
|
1058
|
+
*
|
|
1059
|
+
* describe(`The text "${content}" written in green on a gray background.`);
|
|
1060
|
+
* }
|
|
1061
|
+
* </code>
|
|
1062
|
+
* </div>
|
|
1063
|
+
*
|
|
1064
|
+
* <div>
|
|
1065
|
+
* <code>
|
|
1066
|
+
* function setup() {
|
|
1067
|
+
* createCanvas(100, 100);
|
|
1068
|
+
*
|
|
1069
|
+
* background(200);
|
|
1070
|
+
*
|
|
1071
|
+
* // Create a p5.XML object.
|
|
1072
|
+
* let blankSpace = new p5.XML();
|
|
1073
|
+
*
|
|
1074
|
+
* // Get the element's content and use a default value.
|
|
1075
|
+
* let content = blankSpace.getContent('Your name');
|
|
1076
|
+
*
|
|
1077
|
+
* // Style the text.
|
|
1078
|
+
* textAlign(CENTER, CENTER);
|
|
1079
|
+
* textFont('Courier New');
|
|
1080
|
+
* textSize(14);
|
|
1081
|
+
*
|
|
1082
|
+
* // Display the element's content.
|
|
1083
|
+
* text(content, 5, 50, 90);
|
|
1084
|
+
*
|
|
1085
|
+
* describe(`The text "${content}" written in green on a gray background.`);
|
|
1086
|
+
* }
|
|
1087
|
+
* </code>
|
|
1088
|
+
* </div>
|
|
1089
|
+
*/
|
|
1090
|
+
function getContent(defaultValue?: string): string;
|
|
1091
|
+
|
|
1092
|
+
/**
|
|
1093
|
+
* Returns the element as a `String`.`myXML.serialize()` is useful for sending the element over the network or
|
|
1094
|
+
* saving it to a file.
|
|
1095
|
+
*
|
|
1096
|
+
* @return element as a string.
|
|
1097
|
+
* @example <div>
|
|
1098
|
+
* <code>
|
|
1099
|
+
* let myXML;
|
|
1100
|
+
*
|
|
1101
|
+
* async function setup() {
|
|
1102
|
+
* // Load the XML and create a p5.XML object.
|
|
1103
|
+
* myXML = await loadXML('assets/animals.xml');
|
|
1104
|
+
*
|
|
1105
|
+
* createCanvas(100, 100);
|
|
1106
|
+
*
|
|
1107
|
+
* background(200);
|
|
1108
|
+
*
|
|
1109
|
+
* // Style the text.
|
|
1110
|
+
* textAlign(LEFT, CENTER);
|
|
1111
|
+
* textFont('Courier New');
|
|
1112
|
+
* textSize(12);
|
|
1113
|
+
*
|
|
1114
|
+
* // Display instructions.
|
|
1115
|
+
* text('Double-click to save', 5, 50, 90);
|
|
1116
|
+
*
|
|
1117
|
+
* describe('The text "Double-click to save" written in black on a gray background.');
|
|
1118
|
+
* }
|
|
1119
|
+
*
|
|
1120
|
+
* // Save the file when the user double-clicks.
|
|
1121
|
+
* function doubleClicked() {
|
|
1122
|
+
* // Create a p5.PrintWriter object.
|
|
1123
|
+
* // Use the file format .xml.
|
|
1124
|
+
* let myWriter = createWriter('animals', 'xml');
|
|
1125
|
+
*
|
|
1126
|
+
* // Serialize the XML data to a string.
|
|
1127
|
+
* let data = myXML.serialize();
|
|
1128
|
+
*
|
|
1129
|
+
* // Write the data to the print stream.
|
|
1130
|
+
* myWriter.write(data);
|
|
1131
|
+
*
|
|
1132
|
+
* // Save the file and close the print stream.
|
|
1133
|
+
* myWriter.close();
|
|
1134
|
+
* }
|
|
1135
|
+
* </code>
|
|
1136
|
+
* </div>
|
|
1137
|
+
*/
|
|
1138
|
+
function serialize(): string;
|
|
1139
|
+
|
|
1140
|
+
/**
|
|
1141
|
+
* Sets the element's content.An element's content is the text between its tags. For example, the element
|
|
1142
|
+
* `<language>JavaScript</language>` has the content `JavaScript`.The parameter, `content`, is a string with the element's new content.
|
|
1143
|
+
*
|
|
1144
|
+
* @param new content for the element.
|
|
1145
|
+
* @example <div>
|
|
1146
|
+
* <code>
|
|
1147
|
+
* let myXML;
|
|
1148
|
+
*
|
|
1149
|
+
* async function setup() {
|
|
1150
|
+
* // Load the XML and create a p5.XML object.
|
|
1151
|
+
* myXML = await loadXML('assets/animals.xml');
|
|
1152
|
+
*
|
|
1153
|
+
* createCanvas(100, 100);
|
|
1154
|
+
*
|
|
1155
|
+
* background(200);
|
|
1156
|
+
*
|
|
1157
|
+
* // Get the first reptile child element.
|
|
1158
|
+
* let reptile = myXML.getChild('reptile');
|
|
1159
|
+
*
|
|
1160
|
+
* // Get the reptile's original content.
|
|
1161
|
+
* let oldContent = reptile.getContent();
|
|
1162
|
+
*
|
|
1163
|
+
* // Set the reptile's content.
|
|
1164
|
+
* reptile.setContent('Loggerhead');
|
|
1165
|
+
*
|
|
1166
|
+
* // Get the reptile's new content.
|
|
1167
|
+
* let newContent = reptile.getContent();
|
|
1168
|
+
*
|
|
1169
|
+
* // Style the text.
|
|
1170
|
+
* textAlign(CENTER, CENTER);
|
|
1171
|
+
* textFont('Courier New');
|
|
1172
|
+
* textSize(14);
|
|
1173
|
+
*
|
|
1174
|
+
* // Display the element's old and new content.
|
|
1175
|
+
* text(`${oldContent}: ${newContent}`, 5, 50, 90);
|
|
1176
|
+
*
|
|
1177
|
+
* describe(
|
|
1178
|
+
* `The text "${oldContent}: ${newContent}" written in green on a gray background.`
|
|
1179
|
+
* );
|
|
1180
|
+
* }
|
|
1181
|
+
* </code>
|
|
1182
|
+
* </div>
|
|
1183
|
+
*/
|
|
1184
|
+
function setContent(content: string): void;
|
|
1185
|
+
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
export default function p5_XML(p5: any, fn: any): void;
|