p5 2.0.1 → 2.0.3
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-BRcElHU3.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 +46 -93
- 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 +11 -6
- 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-BKN5yFoS.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-R23xoC7s.js} +5 -5
- package/dist/{rendering--aAe5aq3.js → rendering-CvUVN-Vb.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 +5 -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 +289 -247
- package/lib/p5.js +289 -247
- 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 +5999 -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 +501 -0
- package/types/events/pointer.d.ts +782 -0
- package/types/global.d.ts +5544 -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 +6666 -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 +482 -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,1447 @@
|
|
|
1
|
+
// This file is auto-generated from JSDoc documentation
|
|
2
|
+
|
|
3
|
+
import p5 from 'p5';
|
|
4
|
+
|
|
5
|
+
declare module 'p5' {
|
|
6
|
+
class PrintWriter {
|
|
7
|
+
constructor(filename: string, extension?: string);
|
|
8
|
+
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Clears all data from the print stream.
|
|
13
|
+
*
|
|
14
|
+
* @example <div>
|
|
15
|
+
* <code>
|
|
16
|
+
* function setup() {
|
|
17
|
+
* createCanvas(100, 100);
|
|
18
|
+
*
|
|
19
|
+
* background(200);
|
|
20
|
+
*
|
|
21
|
+
* // Style the text.
|
|
22
|
+
* textAlign(LEFT, CENTER);
|
|
23
|
+
* textFont('Courier New');
|
|
24
|
+
* textSize(12);
|
|
25
|
+
*
|
|
26
|
+
* // Display instructions.
|
|
27
|
+
* text('Double-click to save', 5, 50, 90);
|
|
28
|
+
*
|
|
29
|
+
* describe('The text "Double-click to save" written in black on a gray background.');
|
|
30
|
+
* }
|
|
31
|
+
*
|
|
32
|
+
* // Save the file when the user double-clicks.
|
|
33
|
+
* function doubleClicked() {
|
|
34
|
+
* // Create a p5.PrintWriter object.
|
|
35
|
+
* let myWriter = createWriter('numbers.txt');
|
|
36
|
+
*
|
|
37
|
+
* // Add some data to the print stream.
|
|
38
|
+
* myWriter.print('Hello p5*js!');
|
|
39
|
+
*
|
|
40
|
+
* // Clear the print stream.
|
|
41
|
+
* myWriter.clear();
|
|
42
|
+
*
|
|
43
|
+
* // Save the file and close the print stream.
|
|
44
|
+
* myWriter.close();
|
|
45
|
+
* }
|
|
46
|
+
* </code>
|
|
47
|
+
* </div>
|
|
48
|
+
*/
|
|
49
|
+
function clear(): void;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Writes data to the print stream with new lines added.The parameter, `data`, is the data to write. `data` can be a number or
|
|
53
|
+
* string, as in `myWriter.print('hi')`, or an array of numbers and strings,
|
|
54
|
+
* as in `myWriter.print([1, 2, 3])`. A comma will be inserted between array
|
|
55
|
+
* array elements when they're added to the print stream.
|
|
56
|
+
*
|
|
57
|
+
* @param data to be written as a string, number,
|
|
58
|
+
* or array of strings and numbers.
|
|
59
|
+
* @example <div>
|
|
60
|
+
* <code>
|
|
61
|
+
* function setup() {
|
|
62
|
+
* createCanvas(100, 100);
|
|
63
|
+
*
|
|
64
|
+
* background(200);
|
|
65
|
+
*
|
|
66
|
+
* // Style the text.
|
|
67
|
+
* textAlign(LEFT, CENTER);
|
|
68
|
+
* textFont('Courier New');
|
|
69
|
+
* textSize(12);
|
|
70
|
+
*
|
|
71
|
+
* // Display instructions.
|
|
72
|
+
* text('Double-click to save', 5, 50, 90);
|
|
73
|
+
*
|
|
74
|
+
* describe('The text "Double-click to save" written in black on a gray background.');
|
|
75
|
+
* }
|
|
76
|
+
*
|
|
77
|
+
* // Save the file when the user double-clicks.
|
|
78
|
+
* function doubleClicked() {
|
|
79
|
+
* // Create a p5.PrintWriter object.
|
|
80
|
+
* let myWriter = createWriter('numbers.txt');
|
|
81
|
+
*
|
|
82
|
+
* // Add some data to the print stream.
|
|
83
|
+
* myWriter.print('1,2,3,');
|
|
84
|
+
* myWriter.print(['4', '5', '6']);
|
|
85
|
+
*
|
|
86
|
+
* // Save the file and close the print stream.
|
|
87
|
+
* myWriter.close();
|
|
88
|
+
* }
|
|
89
|
+
* </code>
|
|
90
|
+
* </div>
|
|
91
|
+
*/
|
|
92
|
+
function print(data: string | number | Array): void;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Loads a JSON file to create an `Object`.JavaScript Object Notation
|
|
96
|
+
* (JSON)
|
|
97
|
+
* is a standard format for sending data between applications. The format is
|
|
98
|
+
* based on JavaScript objects which have keys and values. JSON files store
|
|
99
|
+
* data in an object with strings as keys. Values can be strings, numbers,
|
|
100
|
+
* Booleans, arrays, `null`, or other objects.The first parameter, `path`, is a string with the path to the file.
|
|
101
|
+
* Paths to local files should be relative, as in
|
|
102
|
+
* `loadJSON('assets/data.json')`. URLs such as
|
|
103
|
+
* `'https://example.com/data.json'` may be blocked due to browser security.
|
|
104
|
+
* The `path` parameter can also be defined as a
|
|
105
|
+
* object for more advanced usage.The second parameter, `successCallback`, is optional. If a function is
|
|
106
|
+
* passed, as in `loadJSON('assets/data.json', handleData)`, then the
|
|
107
|
+
* `handleData()` function will be called once the data loads. The object
|
|
108
|
+
* created from the JSON data will be passed to `handleData()` as its only argument.
|
|
109
|
+
* The return value of the `handleData()` function will be used as the final return
|
|
110
|
+
* value of `loadJSON('assets/data.json', handleData)`.The third parameter, `failureCallback`, is also optional. If a function is
|
|
111
|
+
* passed, as in `loadJSON('assets/data.json', handleData, handleFailure)`,
|
|
112
|
+
* then the `handleFailure()` function will be called if an error occurs while
|
|
113
|
+
* loading. The `Error` object will be passed to `handleFailure()` as its only
|
|
114
|
+
* argument. The return value of the `handleFailure()` function will be used as the
|
|
115
|
+
* final return value of `loadJSON('assets/data.json', handleData, handleFailure)`.This function returns a `Promise` and should be used in an `async` setup with
|
|
116
|
+
* `await`. See the examples for the usage syntax.
|
|
117
|
+
*
|
|
118
|
+
* @param path of the JSON file to be loaded.
|
|
119
|
+
* @param function to call once the data is loaded. Will be passed the object.
|
|
120
|
+
* @param function to call if the data fails to load. Will be passed an `Error` event object.
|
|
121
|
+
* @return object containing the loaded data.
|
|
122
|
+
* @example <div>
|
|
123
|
+
* <code>
|
|
124
|
+
* let myData;
|
|
125
|
+
*
|
|
126
|
+
* async function setup() {
|
|
127
|
+
* myData = await loadJSON('assets/data.json');
|
|
128
|
+
* createCanvas(100, 100);
|
|
129
|
+
*
|
|
130
|
+
* background(200);
|
|
131
|
+
*
|
|
132
|
+
* // Style the circle.
|
|
133
|
+
* fill(myData.color);
|
|
134
|
+
* noStroke();
|
|
135
|
+
*
|
|
136
|
+
* // Draw the circle.
|
|
137
|
+
* circle(myData.x, myData.y, myData.d);
|
|
138
|
+
*
|
|
139
|
+
* describe('A pink circle on a gray background.');
|
|
140
|
+
* }
|
|
141
|
+
* </code>
|
|
142
|
+
* </div>
|
|
143
|
+
*
|
|
144
|
+
* <div>
|
|
145
|
+
* <code>
|
|
146
|
+
* let myData;
|
|
147
|
+
*
|
|
148
|
+
* async function setup() {
|
|
149
|
+
* myData = await loadJSON('assets/data.json');
|
|
150
|
+
* createCanvas(100, 100);
|
|
151
|
+
*
|
|
152
|
+
* background(200);
|
|
153
|
+
*
|
|
154
|
+
* // Create a p5.Color object and make it transparent.
|
|
155
|
+
* let c = color(myData.color);
|
|
156
|
+
* c.setAlpha(80);
|
|
157
|
+
*
|
|
158
|
+
* // Style the circles.
|
|
159
|
+
* fill(c);
|
|
160
|
+
* noStroke();
|
|
161
|
+
*
|
|
162
|
+
* // Iterate over the myData.bubbles array.
|
|
163
|
+
* for (let b of myData.bubbles) {
|
|
164
|
+
* // Draw a circle for each bubble.
|
|
165
|
+
* circle(b.x, b.y, b.d);
|
|
166
|
+
* }
|
|
167
|
+
*
|
|
168
|
+
* describe('Several pink bubbles floating in a blue sky.');
|
|
169
|
+
* }
|
|
170
|
+
* </code>
|
|
171
|
+
* </div>
|
|
172
|
+
*
|
|
173
|
+
* <div>
|
|
174
|
+
* <code>
|
|
175
|
+
* let myData;
|
|
176
|
+
*
|
|
177
|
+
* async function setup() {
|
|
178
|
+
* myData = await loadJSON('https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_day.geojson');
|
|
179
|
+
* createCanvas(100, 100);
|
|
180
|
+
*
|
|
181
|
+
* background(200);
|
|
182
|
+
*
|
|
183
|
+
* // Get data about the most recent earthquake.
|
|
184
|
+
* let quake = myData.features[0].properties;
|
|
185
|
+
*
|
|
186
|
+
* // Draw a circle based on the earthquake's magnitude.
|
|
187
|
+
* circle(50, 50, quake.mag * 10);
|
|
188
|
+
*
|
|
189
|
+
* // Style the text.
|
|
190
|
+
* textAlign(LEFT, CENTER);
|
|
191
|
+
* textFont('Courier New');
|
|
192
|
+
* textSize(11);
|
|
193
|
+
*
|
|
194
|
+
* // Display the earthquake's location.
|
|
195
|
+
* text(quake.place, 5, 80, 100);
|
|
196
|
+
*
|
|
197
|
+
* describe(`A white circle on a gray background. The text "${quake.place}" is written beneath the circle.`);
|
|
198
|
+
* }
|
|
199
|
+
* </code>
|
|
200
|
+
* </div>
|
|
201
|
+
*
|
|
202
|
+
* <div>
|
|
203
|
+
* <code>
|
|
204
|
+
* let bigQuake;
|
|
205
|
+
*
|
|
206
|
+
* // Load the GeoJSON and preprocess it.
|
|
207
|
+
* async function setup() {
|
|
208
|
+
* await loadJSON(
|
|
209
|
+
* 'https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_day.geojson',
|
|
210
|
+
* handleData
|
|
211
|
+
* );
|
|
212
|
+
*
|
|
213
|
+
* createCanvas(100, 100);
|
|
214
|
+
*
|
|
215
|
+
* background(200);
|
|
216
|
+
*
|
|
217
|
+
* // Draw a circle based on the earthquake's magnitude.
|
|
218
|
+
* circle(50, 50, bigQuake.mag * 10);
|
|
219
|
+
*
|
|
220
|
+
* // Style the text.
|
|
221
|
+
* textAlign(LEFT, CENTER);
|
|
222
|
+
* textFont('Courier New');
|
|
223
|
+
* textSize(11);
|
|
224
|
+
*
|
|
225
|
+
* // Display the earthquake's location.
|
|
226
|
+
* text(bigQuake.place, 5, 80, 100);
|
|
227
|
+
*
|
|
228
|
+
* describe(`A white circle on a gray background. The text "${bigQuake.place}" is written beneath the circle.`);
|
|
229
|
+
* }
|
|
230
|
+
*
|
|
231
|
+
* // Find the biggest recent earthquake.
|
|
232
|
+
* function handleData(data) {
|
|
233
|
+
* let maxMag = 0;
|
|
234
|
+
* // Iterate over the earthquakes array.
|
|
235
|
+
* for (let quake of data.features) {
|
|
236
|
+
* // Reassign bigQuake if a larger
|
|
237
|
+
* // magnitude quake is found.
|
|
238
|
+
* if (quake.properties.mag > maxMag) {
|
|
239
|
+
* bigQuake = quake.properties;
|
|
240
|
+
* }
|
|
241
|
+
* }
|
|
242
|
+
* }
|
|
243
|
+
* </code>
|
|
244
|
+
* </div>
|
|
245
|
+
*
|
|
246
|
+
* <div>
|
|
247
|
+
* <code>
|
|
248
|
+
* let bigQuake;
|
|
249
|
+
*
|
|
250
|
+
* // Load the GeoJSON and preprocess it.
|
|
251
|
+
* async function setup() {
|
|
252
|
+
* await loadJSON(
|
|
253
|
+
* 'https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_day.geojson',
|
|
254
|
+
* handleData,
|
|
255
|
+
* handleError
|
|
256
|
+
* );
|
|
257
|
+
*
|
|
258
|
+
* createCanvas(100, 100);
|
|
259
|
+
*
|
|
260
|
+
* background(200);
|
|
261
|
+
*
|
|
262
|
+
* // Draw a circle based on the earthquake's magnitude.
|
|
263
|
+
* circle(50, 50, bigQuake.mag * 10);
|
|
264
|
+
*
|
|
265
|
+
* // Style the text.
|
|
266
|
+
* textAlign(LEFT, CENTER);
|
|
267
|
+
* textFont('Courier New');
|
|
268
|
+
* textSize(11);
|
|
269
|
+
*
|
|
270
|
+
* // Display the earthquake's location.
|
|
271
|
+
* text(bigQuake.place, 5, 80, 100);
|
|
272
|
+
*
|
|
273
|
+
* describe(`A white circle on a gray background. The text "${bigQuake.place}" is written beneath the circle.`);
|
|
274
|
+
* }
|
|
275
|
+
*
|
|
276
|
+
* // Find the biggest recent earthquake.
|
|
277
|
+
* function handleData(data) {
|
|
278
|
+
* let maxMag = 0;
|
|
279
|
+
* // Iterate over the earthquakes array.
|
|
280
|
+
* for (let quake of data.features) {
|
|
281
|
+
* // Reassign bigQuake if a larger
|
|
282
|
+
* // magnitude quake is found.
|
|
283
|
+
* if (quake.properties.mag > maxMag) {
|
|
284
|
+
* bigQuake = quake.properties;
|
|
285
|
+
* }
|
|
286
|
+
* }
|
|
287
|
+
* }
|
|
288
|
+
*
|
|
289
|
+
* // Log any errors to the console.
|
|
290
|
+
* function handleError(error) {
|
|
291
|
+
* console.log('Oops!', error);
|
|
292
|
+
* }
|
|
293
|
+
* </code>
|
|
294
|
+
* </div>
|
|
295
|
+
*/
|
|
296
|
+
function loadJSON(path: string | Request, successCallback?: Function, errorCallback?: Function): Promise<object>;
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Loads a text file to create an `Array`.The first parameter, `path`, is always a string with the path to the file.
|
|
300
|
+
* Paths to local files should be relative, as in
|
|
301
|
+
* `loadStrings('assets/data.txt')`. URLs such as
|
|
302
|
+
* `'https://example.com/data.txt'` may be blocked due to browser security.
|
|
303
|
+
* The `path` parameter can also be defined as a
|
|
304
|
+
* object for more advanced usage.The second parameter, `successCallback`, is optional. If a function is
|
|
305
|
+
* passed, as in `loadStrings('assets/data.txt', handleData)`, then the
|
|
306
|
+
* `handleData()` function will be called once the data loads. The array
|
|
307
|
+
* created from the text data will be passed to `handleData()` as its only
|
|
308
|
+
* argument. The return value of the `handleData()` function will be used as
|
|
309
|
+
* the final return value of `loadStrings('assets/data.txt', handleData)`.The third parameter, `failureCallback`, is also optional. If a function is
|
|
310
|
+
* passed, as in `loadStrings('assets/data.txt', handleData, handleFailure)`,
|
|
311
|
+
* then the `handleFailure()` function will be called if an error occurs while
|
|
312
|
+
* loading. The `Error` object will be passed to `handleFailure()` as its only
|
|
313
|
+
* argument. The return value of the `handleFailure()` function will be used as
|
|
314
|
+
* the final return value of `loadStrings('assets/data.txt', handleData, handleFailure)`.This function returns a `Promise` and should be used in an `async` setup with
|
|
315
|
+
* `await`. See the examples for the usage syntax.
|
|
316
|
+
*
|
|
317
|
+
* @param path of the text file to be loaded.
|
|
318
|
+
* @param function to call once the data is
|
|
319
|
+
* loaded. Will be passed the array.
|
|
320
|
+
* @param function to call if the data fails to
|
|
321
|
+
* load. Will be passed an `Error` event
|
|
322
|
+
* object.
|
|
323
|
+
* @return new array containing the loaded text.
|
|
324
|
+
* @example <div>
|
|
325
|
+
* <code>
|
|
326
|
+
* let myData;
|
|
327
|
+
*
|
|
328
|
+
* async function setup() {
|
|
329
|
+
* myData = await loadStrings('assets/test.txt');
|
|
330
|
+
*
|
|
331
|
+
* createCanvas(100, 100);
|
|
332
|
+
*
|
|
333
|
+
* background(200);
|
|
334
|
+
*
|
|
335
|
+
* // Select a random line from the text.
|
|
336
|
+
* let phrase = random(myData);
|
|
337
|
+
*
|
|
338
|
+
* // Style the text.
|
|
339
|
+
* textAlign(LEFT, CENTER);
|
|
340
|
+
* textFont('Courier New');
|
|
341
|
+
* textSize(12);
|
|
342
|
+
*
|
|
343
|
+
* // Display the text.
|
|
344
|
+
* text(phrase, 10, 50, 90);
|
|
345
|
+
*
|
|
346
|
+
* describe(`The text "${phrase}" written in black on a gray background.`);
|
|
347
|
+
* }
|
|
348
|
+
* </code>
|
|
349
|
+
* </div>
|
|
350
|
+
*
|
|
351
|
+
* <div>
|
|
352
|
+
* <code>
|
|
353
|
+
* let lastLine;
|
|
354
|
+
*
|
|
355
|
+
* // Load the text and preprocess it.
|
|
356
|
+
* async function setup() {
|
|
357
|
+
* await loadStrings('assets/test.txt', handleData);
|
|
358
|
+
*
|
|
359
|
+
* createCanvas(100, 100);
|
|
360
|
+
*
|
|
361
|
+
* background(200);
|
|
362
|
+
*
|
|
363
|
+
* // Style the text.
|
|
364
|
+
* textAlign(LEFT, CENTER);
|
|
365
|
+
* textFont('Courier New');
|
|
366
|
+
* textSize(12);
|
|
367
|
+
*
|
|
368
|
+
* // Display the text.
|
|
369
|
+
* text(lastLine, 10, 50, 90);
|
|
370
|
+
*
|
|
371
|
+
* describe('The text "I talk like an orange" written in black on a gray background.');
|
|
372
|
+
* }
|
|
373
|
+
*
|
|
374
|
+
* // Select the last line from the text.
|
|
375
|
+
* function handleData(data) {
|
|
376
|
+
* lastLine = data[data.length - 1];
|
|
377
|
+
* }
|
|
378
|
+
* </code>
|
|
379
|
+
* </div>
|
|
380
|
+
*
|
|
381
|
+
* <div>
|
|
382
|
+
* <code>
|
|
383
|
+
* let lastLine;
|
|
384
|
+
*
|
|
385
|
+
* // Load the text and preprocess it.
|
|
386
|
+
* async function setup() {
|
|
387
|
+
* await loadStrings('assets/test.txt', handleData, handleError);
|
|
388
|
+
*
|
|
389
|
+
* createCanvas(100, 100);
|
|
390
|
+
*
|
|
391
|
+
* background(200);
|
|
392
|
+
*
|
|
393
|
+
* // Style the text.
|
|
394
|
+
* textAlign(LEFT, CENTER);
|
|
395
|
+
* textFont('Courier New');
|
|
396
|
+
* textSize(12);
|
|
397
|
+
*
|
|
398
|
+
* // Display the text.
|
|
399
|
+
* text(lastLine, 10, 50, 90);
|
|
400
|
+
*
|
|
401
|
+
* describe('The text "I talk like an orange" written in black on a gray background.');
|
|
402
|
+
* }
|
|
403
|
+
*
|
|
404
|
+
* // Select the last line from the text.
|
|
405
|
+
* function handleData(data) {
|
|
406
|
+
* lastLine = data[data.length - 1];
|
|
407
|
+
* }
|
|
408
|
+
*
|
|
409
|
+
* // Log any errors to the console.
|
|
410
|
+
* function handleError(error) {
|
|
411
|
+
* console.error('Oops!', error);
|
|
412
|
+
* }
|
|
413
|
+
* </code>
|
|
414
|
+
* </div>
|
|
415
|
+
*/
|
|
416
|
+
function loadStrings(path: string | Request, successCallback?: Function, errorCallback?: Function): Promise<string[]>;
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* Reads the contents of a file or URL and creates a p5.Table object with
|
|
420
|
+
* its values. If a file is specified, it must be located in the sketch's
|
|
421
|
+
* "data" folder. The filename parameter can also be a URL to a file found
|
|
422
|
+
* online. By default, the file is assumed to be comma-separated (in CSV
|
|
423
|
+
* format). Table only looks for a header row if the 'header' option is
|
|
424
|
+
* included.This function returns a `Promise` and should be used in an `async` setup with
|
|
425
|
+
* `await`. See the examples for the usage syntax.All files loaded and saved use UTF-8 encoding. This method is suitable for fetching files up to size of 64MB.
|
|
426
|
+
*
|
|
427
|
+
* @deprecated p5.Table will be removed in a future version of p5.js to make way for a new, friendlier version :)
|
|
428
|
+
* @param name of the file or URL to load
|
|
429
|
+
* @param the separator character used by the file, defaults to `','`
|
|
430
|
+
* @param "header" to indicate table has header row
|
|
431
|
+
* @param function to be executed after
|
|
432
|
+
* <a href="#/p5/loadTable">loadTable()</a> completes. On success, the
|
|
433
|
+
* <a href="#/p5.Table">Table</a> object is passed in as the
|
|
434
|
+
* first argument.
|
|
435
|
+
* @param function to be executed if
|
|
436
|
+
* there is an error, response is passed
|
|
437
|
+
* in as first argument
|
|
438
|
+
* @return <a href="#/p5.Table">Table</a> object containing data
|
|
439
|
+
* @example <div class='norender'>
|
|
440
|
+
* <code>
|
|
441
|
+
* let table;
|
|
442
|
+
*
|
|
443
|
+
* async function setup() {
|
|
444
|
+
* // Create a 200x200 canvas
|
|
445
|
+
* createCanvas(200, 200);
|
|
446
|
+
*
|
|
447
|
+
* // Load the CSV file with a header row
|
|
448
|
+
* table = await loadTable('assets/mammals.csv', ',', 'header');
|
|
449
|
+
*
|
|
450
|
+
* // Get the second row (index 1)
|
|
451
|
+
* let row = table.getRow(1);
|
|
452
|
+
*
|
|
453
|
+
* // Set text properties
|
|
454
|
+
* fill(0); // Set text color to black
|
|
455
|
+
* textSize(16); // Adjust text size as needed
|
|
456
|
+
*
|
|
457
|
+
* // Display each column value in the row on the canvas.
|
|
458
|
+
* // Using an offset for y-position so each value appears on a new line.
|
|
459
|
+
* for (let c = 0; c < table.getColumnCount(); c++) {
|
|
460
|
+
* text(row.getString(c), 10, 30 + c * 20);
|
|
461
|
+
* }
|
|
462
|
+
* }
|
|
463
|
+
* </code>
|
|
464
|
+
* </div>
|
|
465
|
+
*/
|
|
466
|
+
function loadTable(filename: string | Request, separator?: string, header?: string, callback?: Function, errorCallback?: Function): Promise<object>;
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* Loads an XML file to create a p5.XML object.Extensible Markup Language
|
|
470
|
+
* (XML)
|
|
471
|
+
* is a standard format for sending data between applications. Like HTML, the
|
|
472
|
+
* XML format is based on tags and attributes, as in
|
|
473
|
+
* `<time units="s">1234</time>`.The first parameter, `path`, is always a string with the path to the file.
|
|
474
|
+
* Paths to local files should be relative, as in
|
|
475
|
+
* `loadXML('assets/data.xml')`. URLs such as `'https://example.com/data.xml'`
|
|
476
|
+
* may be blocked due to browser security. The `path` parameter can also be defined
|
|
477
|
+
* as a
|
|
478
|
+
* object for more advanced usage.The second parameter, `successCallback`, is optional. If a function is
|
|
479
|
+
* passed, as in `loadXML('assets/data.xml', handleData)`, then the
|
|
480
|
+
* `handleData()` function will be called once the data loads. The
|
|
481
|
+
* p5.XML object created from the data will be passed
|
|
482
|
+
* to `handleData()` as its only argument. The return value of the `handleData()`
|
|
483
|
+
* function will be used as the final return value of `loadXML('assets/data.xml', handleData)`.The third parameter, `failureCallback`, is also optional. If a function is
|
|
484
|
+
* passed, as in `loadXML('assets/data.xml', handleData, handleFailure)`, then
|
|
485
|
+
* the `handleFailure()` function will be called if an error occurs while
|
|
486
|
+
* loading. The `Error` object will be passed to `handleFailure()` as its only
|
|
487
|
+
* argument. The return value of the `handleFailure()` function will be used as the
|
|
488
|
+
* final return value of `loadXML('assets/data.xml', handleData, handleFailure)`.This function returns a `Promise` and should be used in an `async` setup with
|
|
489
|
+
* `await`. See the examples for the usage syntax.
|
|
490
|
+
*
|
|
491
|
+
* @param path of the XML file to be loaded.
|
|
492
|
+
* @param function to call once the data is
|
|
493
|
+
* loaded. Will be passed the
|
|
494
|
+
* <a href="#/p5.XML">p5.XML</a> object.
|
|
495
|
+
* @param function to call if the data fails to
|
|
496
|
+
* load. Will be passed an `Error` event
|
|
497
|
+
* object.
|
|
498
|
+
* @return XML data loaded into a <a href="#/p5.XML">p5.XML</a>
|
|
499
|
+
* object.
|
|
500
|
+
* @example <div>
|
|
501
|
+
* <code>
|
|
502
|
+
* let myXML;
|
|
503
|
+
*
|
|
504
|
+
* // Load the XML and create a p5.XML object.
|
|
505
|
+
* async function setup() {
|
|
506
|
+
* myXML = await loadXML('assets/animals.xml');
|
|
507
|
+
*
|
|
508
|
+
* createCanvas(100, 100);
|
|
509
|
+
*
|
|
510
|
+
* background(200);
|
|
511
|
+
*
|
|
512
|
+
* // Get an array with all mammal tags.
|
|
513
|
+
* let mammals = myXML.getChildren('mammal');
|
|
514
|
+
*
|
|
515
|
+
* // Style the text.
|
|
516
|
+
* textAlign(LEFT, CENTER);
|
|
517
|
+
* textFont('Courier New');
|
|
518
|
+
* textSize(14);
|
|
519
|
+
*
|
|
520
|
+
* // Iterate over the mammals array.
|
|
521
|
+
* for (let i = 0; i < mammals.length; i += 1) {
|
|
522
|
+
*
|
|
523
|
+
* // Calculate the y-coordinate.
|
|
524
|
+
* let y = (i + 1) * 25;
|
|
525
|
+
*
|
|
526
|
+
* // Get the mammal's common name.
|
|
527
|
+
* let name = mammals[i].getContent();
|
|
528
|
+
*
|
|
529
|
+
* // Display the mammal's name.
|
|
530
|
+
* text(name, 20, y);
|
|
531
|
+
* }
|
|
532
|
+
*
|
|
533
|
+
* describe(
|
|
534
|
+
* 'The words "Goat", "Leopard", and "Zebra" written on three separate lines. The text is black on a gray background.'
|
|
535
|
+
* );
|
|
536
|
+
* }
|
|
537
|
+
* </code>
|
|
538
|
+
* </div>
|
|
539
|
+
*
|
|
540
|
+
* <div>
|
|
541
|
+
* <code>
|
|
542
|
+
* let lastMammal;
|
|
543
|
+
*
|
|
544
|
+
* // Load the XML and create a p5.XML object.
|
|
545
|
+
* async function setup() {
|
|
546
|
+
* await loadXML('assets/animals.xml', handleData);
|
|
547
|
+
*
|
|
548
|
+
* createCanvas(100, 100);
|
|
549
|
+
*
|
|
550
|
+
* background(200);
|
|
551
|
+
*
|
|
552
|
+
* // Style the text.
|
|
553
|
+
* textAlign(CENTER, CENTER);
|
|
554
|
+
* textFont('Courier New');
|
|
555
|
+
* textSize(16);
|
|
556
|
+
*
|
|
557
|
+
* // Display the content of the last mammal element.
|
|
558
|
+
* text(lastMammal, 50, 50);
|
|
559
|
+
*
|
|
560
|
+
* describe('The word "Zebra" written in black on a gray background.');
|
|
561
|
+
* }
|
|
562
|
+
*
|
|
563
|
+
* // Get the content of the last mammal element.
|
|
564
|
+
* function handleData(data) {
|
|
565
|
+
* // Get an array with all mammal elements.
|
|
566
|
+
* let mammals = data.getChildren('mammal');
|
|
567
|
+
*
|
|
568
|
+
* // Get the content of the last mammal.
|
|
569
|
+
* lastMammal = mammals[mammals.length - 1].getContent();
|
|
570
|
+
* }
|
|
571
|
+
* </code>
|
|
572
|
+
* </div>
|
|
573
|
+
*
|
|
574
|
+
* <div>
|
|
575
|
+
* <code>
|
|
576
|
+
* let lastMammal;
|
|
577
|
+
*
|
|
578
|
+
* // Load the XML and preprocess it.
|
|
579
|
+
* async function setup() {
|
|
580
|
+
* await loadXML('assets/animals.xml', handleData, handleError);
|
|
581
|
+
*
|
|
582
|
+
* createCanvas(100, 100);
|
|
583
|
+
*
|
|
584
|
+
* background(200);
|
|
585
|
+
*
|
|
586
|
+
* // Style the text.
|
|
587
|
+
* textAlign(CENTER, CENTER);
|
|
588
|
+
* textFont('Courier New');
|
|
589
|
+
* textSize(16);
|
|
590
|
+
*
|
|
591
|
+
* // Display the content of the last mammal element.
|
|
592
|
+
* text(lastMammal, 50, 50);
|
|
593
|
+
*
|
|
594
|
+
* describe('The word "Zebra" written in black on a gray background.');
|
|
595
|
+
* }
|
|
596
|
+
*
|
|
597
|
+
* // Get the content of the last mammal element.
|
|
598
|
+
* function handleData(data) {
|
|
599
|
+
* // Get an array with all mammal elements.
|
|
600
|
+
* let mammals = data.getChildren('mammal');
|
|
601
|
+
*
|
|
602
|
+
* // Get the content of the last mammal.
|
|
603
|
+
* lastMammal = mammals[mammals.length - 1].getContent();
|
|
604
|
+
* }
|
|
605
|
+
*
|
|
606
|
+
* // Log any errors to the console.
|
|
607
|
+
* function handleError(error) {
|
|
608
|
+
* console.error('Oops!', error);
|
|
609
|
+
* }
|
|
610
|
+
* </code>
|
|
611
|
+
* </div>
|
|
612
|
+
*/
|
|
613
|
+
function loadXML(path: string | Request, successCallback?: Function, errorCallback?: Function): Promise<p5.XML>;
|
|
614
|
+
|
|
615
|
+
/**
|
|
616
|
+
* This method is suitable for fetching files up to size of 64MB.
|
|
617
|
+
*
|
|
618
|
+
* @param name of the file or URL to load
|
|
619
|
+
* @param function to be executed after <a href="#/p5/loadBytes">loadBytes()</a>
|
|
620
|
+
* completes
|
|
621
|
+
* @param function to be executed if there
|
|
622
|
+
* is an error
|
|
623
|
+
* @returns a Uint8Array containing the loaded buffer
|
|
624
|
+
* @example <div>
|
|
625
|
+
* <code>
|
|
626
|
+
* let data;
|
|
627
|
+
*
|
|
628
|
+
* async function setup() {
|
|
629
|
+
* createCanvas(100, 100); // Create a canvas
|
|
630
|
+
* data = await loadBytes('assets/mammals.xml'); // Load the bytes from the XML file
|
|
631
|
+
*
|
|
632
|
+
* background(255); // Set a white background
|
|
633
|
+
* fill(0); // Set text color to black
|
|
634
|
+
*
|
|
635
|
+
* // Display the first 5 byte values on the canvas in hexadecimal format
|
|
636
|
+
* for (let i = 0; i < 5; i++) {
|
|
637
|
+
* let byteHex = data[i].toString(16);
|
|
638
|
+
* text(byteHex, 10, 18 * (i + 1)); // Adjust spacing as needed
|
|
639
|
+
* }
|
|
640
|
+
*
|
|
641
|
+
* describe('no image displayed, displays first 5 bytes of mammals.xml in hexadecimal format');
|
|
642
|
+
* }
|
|
643
|
+
* </code>
|
|
644
|
+
* </div>
|
|
645
|
+
*/
|
|
646
|
+
function loadBytes(file: string | Request, callback?: Function, errorCallback?: Function): Promise<Uint8Array>;
|
|
647
|
+
|
|
648
|
+
/**
|
|
649
|
+
* Loads a file at the given path as a Blob, then returns the resulting data or
|
|
650
|
+
* passes it to a success callback function, if provided. On load, this function
|
|
651
|
+
* returns a `Promise` that resolves to a Blob containing the file data.
|
|
652
|
+
*
|
|
653
|
+
* @param The path or Request object pointing to the file
|
|
654
|
+
* you want to load.
|
|
655
|
+
* @param Optional. A function to be called if the
|
|
656
|
+
* file successfully loads, receiving the
|
|
657
|
+
* resulting Blob as its only argument.
|
|
658
|
+
* @param Optional. A function to be called if an
|
|
659
|
+
* error occurs during loading; receives the
|
|
660
|
+
* error object as its only argument.
|
|
661
|
+
* @returns A promise that resolves with the loaded Blob.
|
|
662
|
+
* @example <div>
|
|
663
|
+
* <code>
|
|
664
|
+
* let myBlob;
|
|
665
|
+
*
|
|
666
|
+
* async function setup() {
|
|
667
|
+
* createCanvas(200, 200);
|
|
668
|
+
* background(220);
|
|
669
|
+
* try {
|
|
670
|
+
* // 1. Load an image file as a Blob.
|
|
671
|
+
* myBlob = await loadBlob('assets/flower-1.png');
|
|
672
|
+
*
|
|
673
|
+
* // 2. Convert the Blob into an object URL.
|
|
674
|
+
* const objectUrl = URL.createObjectURL(myBlob);
|
|
675
|
+
*
|
|
676
|
+
* // 3. Load that object URL into a p5.Image.
|
|
677
|
+
* loadImage(objectUrl, (img) => {
|
|
678
|
+
* // 4. Display the loaded image.
|
|
679
|
+
* image(img, 0, 0, width, height);
|
|
680
|
+
* });
|
|
681
|
+
* } catch (err) {
|
|
682
|
+
* console.error('Error loading blob:', err);
|
|
683
|
+
* }
|
|
684
|
+
* }
|
|
685
|
+
* </code>
|
|
686
|
+
* </div>
|
|
687
|
+
*/
|
|
688
|
+
function loadBlob(path: string | Request, successCallback?: Function, errorCallback?: Function): Promise<Blob>;
|
|
689
|
+
|
|
690
|
+
/**
|
|
691
|
+
* Method for executing an HTTP GET request. If data type is not specified,
|
|
692
|
+
* it will default to `'text'`. This is equivalent to
|
|
693
|
+
* calling httpDo(path, 'GET'). The 'binary' datatype will return
|
|
694
|
+
* a Blob object, and the 'arrayBuffer' datatype will return an ArrayBuffer
|
|
695
|
+
* which can be used to initialize typed arrays (such as Uint8Array).
|
|
696
|
+
*
|
|
697
|
+
* @param name of the file or url to load
|
|
698
|
+
* @param "json", "jsonp", "binary", "arrayBuffer",
|
|
699
|
+
* "xml", or "text"
|
|
700
|
+
* @param function to be executed after
|
|
701
|
+
* <a href="#/p5/httpGet">httpGet()</a> completes, data is passed in
|
|
702
|
+
* as first argument
|
|
703
|
+
* @param function to be executed if
|
|
704
|
+
* there is an error, response is passed
|
|
705
|
+
* in as first argument
|
|
706
|
+
* @return A promise that resolves with the data when the operation
|
|
707
|
+
* completes successfully or rejects with the error after
|
|
708
|
+
* one occurs.
|
|
709
|
+
* @example <div class='norender'><code>
|
|
710
|
+
* // Examples use USGS Earthquake API:
|
|
711
|
+
* // https://earthquake.usgs.gov/fdsnws/event/1/#methods
|
|
712
|
+
* let earthquakes;
|
|
713
|
+
* async function setup() {
|
|
714
|
+
* // Get the most recent earthquake in the database
|
|
715
|
+
* let url =
|
|
716
|
+
* 'https://earthquake.usgs.gov/fdsnws/event/1/query?' +
|
|
717
|
+
* 'format=geojson&limit=1&orderby=time';
|
|
718
|
+
* earthquakes = await httpGet(url, 'json');
|
|
719
|
+
* }
|
|
720
|
+
*
|
|
721
|
+
* function draw() {
|
|
722
|
+
* if (!earthquakes) {
|
|
723
|
+
* // Wait until the earthquake data has loaded before drawing.
|
|
724
|
+
* return;
|
|
725
|
+
* }
|
|
726
|
+
* background(200);
|
|
727
|
+
* // Get the magnitude and name of the earthquake out of the loaded JSON
|
|
728
|
+
* let earthquakeMag = earthquakes.features[0].properties.mag;
|
|
729
|
+
* let earthquakeName = earthquakes.features[0].properties.place;
|
|
730
|
+
* ellipse(width / 2, height / 2, earthquakeMag * 10, earthquakeMag * 10);
|
|
731
|
+
* textAlign(CENTER);
|
|
732
|
+
* text(earthquakeName, 0, height - 30, width, 30);
|
|
733
|
+
* noLoop();
|
|
734
|
+
* }
|
|
735
|
+
* </code></div>
|
|
736
|
+
*/
|
|
737
|
+
function httpGet(path: string | Request, datatype?: string, callback?: Function, errorCallback?: Function): Promise;
|
|
738
|
+
|
|
739
|
+
/**
|
|
740
|
+
*/
|
|
741
|
+
function httpGet(path: string | Request, callback: Function, errorCallback?: Function): Promise;
|
|
742
|
+
|
|
743
|
+
/**
|
|
744
|
+
* Method for executing an HTTP POST request. If data type is not specified,
|
|
745
|
+
* it will default to `'text'`. This is equivalent to
|
|
746
|
+
* calling httpDo(path, 'POST').
|
|
747
|
+
*
|
|
748
|
+
* @param name of the file or url to load
|
|
749
|
+
* @param param data passed sent with request
|
|
750
|
+
* @param "json", "jsonp", "xml", or "text".
|
|
751
|
+
* If omitted, <a href="#/p5/httpPost">httpPost()</a> will guess.
|
|
752
|
+
* @param function to be executed after
|
|
753
|
+
* <a href="#/p5/httpPost">httpPost()</a> completes, data is passed in
|
|
754
|
+
* as first argument
|
|
755
|
+
* @param function to be executed if
|
|
756
|
+
* there is an error, response is passed
|
|
757
|
+
* in as first argument
|
|
758
|
+
* @return A promise that resolves with the data when the operation
|
|
759
|
+
* completes successfully or rejects with the error after
|
|
760
|
+
* one occurs.
|
|
761
|
+
* @example <div>
|
|
762
|
+
* <code>
|
|
763
|
+
* // Examples use jsonplaceholder.typicode.com for a Mock Data API
|
|
764
|
+
*
|
|
765
|
+
* let url = 'https://jsonplaceholder.typicode.com/posts';
|
|
766
|
+
* let postData = { userId: 1, title: 'p5 Clicked!', body: 'p5.js is very cool.' };
|
|
767
|
+
*
|
|
768
|
+
* function setup() {
|
|
769
|
+
* createCanvas(100, 100);
|
|
770
|
+
* background(200);
|
|
771
|
+
* }
|
|
772
|
+
*
|
|
773
|
+
* function mousePressed() {
|
|
774
|
+
* httpPost(url, postData, 'json', function(result) {
|
|
775
|
+
* strokeWeight(2);
|
|
776
|
+
* text(result.body, mouseX, mouseY);
|
|
777
|
+
* });
|
|
778
|
+
* }
|
|
779
|
+
* </code>
|
|
780
|
+
* </div>
|
|
781
|
+
*
|
|
782
|
+
* <div><code>
|
|
783
|
+
* let url = 'ttps://invalidURL'; // A bad URL that will cause errors
|
|
784
|
+
* let postData = { title: 'p5 Clicked!', body: 'p5.js is very cool.' };
|
|
785
|
+
*
|
|
786
|
+
* function setup() {
|
|
787
|
+
* createCanvas(100, 100);
|
|
788
|
+
* background(200);
|
|
789
|
+
* }
|
|
790
|
+
*
|
|
791
|
+
* function mousePressed() {
|
|
792
|
+
* httpPost(
|
|
793
|
+
* url,
|
|
794
|
+
* postData,
|
|
795
|
+
* 'json',
|
|
796
|
+
* function(result) {
|
|
797
|
+
* // ... won't be called
|
|
798
|
+
* },
|
|
799
|
+
* function(error) {
|
|
800
|
+
* strokeWeight(2);
|
|
801
|
+
* text(error.toString(), mouseX, mouseY);
|
|
802
|
+
* }
|
|
803
|
+
* );
|
|
804
|
+
* }
|
|
805
|
+
* </code></div>
|
|
806
|
+
*/
|
|
807
|
+
function httpPost(path: string | Request, data?: object | boolean, datatype?: string, callback?: Function, errorCallback?: Function): Promise;
|
|
808
|
+
|
|
809
|
+
/**
|
|
810
|
+
*/
|
|
811
|
+
function httpPost(path: string | Request, data: object | boolean, callback?: Function, errorCallback?: Function): Promise;
|
|
812
|
+
|
|
813
|
+
/**
|
|
814
|
+
*/
|
|
815
|
+
function httpPost(path: string | Request, callback?: Function, errorCallback?: Function): Promise;
|
|
816
|
+
|
|
817
|
+
/**
|
|
818
|
+
* Method for executing an HTTP request. If data type is not specified,
|
|
819
|
+
* it will default to `'text'`.This function is meant for more advanced usage of HTTP requests in p5.js. It is
|
|
820
|
+
* best used when a
|
|
821
|
+
* object is passed to the `path` parameter.This method is suitable for fetching files up to size of 64MB when "GET" is used.
|
|
822
|
+
*
|
|
823
|
+
* @param name of the file or url to load
|
|
824
|
+
* @param either "GET", "POST", "PUT", "DELETE",
|
|
825
|
+
* or other HTTP request methods
|
|
826
|
+
* @param "json", "jsonp", "xml", or "text"
|
|
827
|
+
* @param param data passed sent with request
|
|
828
|
+
* @param function to be executed after
|
|
829
|
+
* <a href="#/p5/httpGet">httpGet()</a> completes, data is passed in
|
|
830
|
+
* as first argument
|
|
831
|
+
* @param function to be executed if
|
|
832
|
+
* there is an error, response is passed
|
|
833
|
+
* in as first argument
|
|
834
|
+
* @return A promise that resolves with the data when the operation
|
|
835
|
+
* completes successfully or rejects with the error after
|
|
836
|
+
* one occurs.
|
|
837
|
+
* @example <div>
|
|
838
|
+
* <code>
|
|
839
|
+
* // Examples use USGS Earthquake API:
|
|
840
|
+
* // https://earthquake.usgs.gov/fdsnws/event/1/#methods
|
|
841
|
+
*
|
|
842
|
+
* // displays an animation of all USGS earthquakes
|
|
843
|
+
* let earthquakes;
|
|
844
|
+
* let eqFeatureIndex = 0;
|
|
845
|
+
*
|
|
846
|
+
* function setup() {
|
|
847
|
+
* createCanvas(100,100);
|
|
848
|
+
*
|
|
849
|
+
* let url = 'https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson';
|
|
850
|
+
*
|
|
851
|
+
* const req = new Request(url, {
|
|
852
|
+
* method: 'GET',
|
|
853
|
+
* headers: {authorization: 'Bearer secretKey'}
|
|
854
|
+
* });
|
|
855
|
+
* // httpDo(path, method, datatype, success, error)
|
|
856
|
+
*
|
|
857
|
+
* httpDo(
|
|
858
|
+
* req,
|
|
859
|
+
* 'GET',
|
|
860
|
+
* 'json',
|
|
861
|
+
* res => {
|
|
862
|
+
* earthquakes = res;
|
|
863
|
+
* },
|
|
864
|
+
* err => {
|
|
865
|
+
* console.error('Error loading data:', err);
|
|
866
|
+
* }
|
|
867
|
+
* );
|
|
868
|
+
* }
|
|
869
|
+
*
|
|
870
|
+
* function draw() {
|
|
871
|
+
* // wait until the data is loaded
|
|
872
|
+
* if (!earthquakes || !earthquakes.features[eqFeatureIndex]) {
|
|
873
|
+
* return;
|
|
874
|
+
* }
|
|
875
|
+
* clear();
|
|
876
|
+
*
|
|
877
|
+
* let feature = earthquakes.features[eqFeatureIndex];
|
|
878
|
+
* let mag = feature.properties.mag;
|
|
879
|
+
* let rad = mag / 11 * ((width + height) / 2);
|
|
880
|
+
* fill(255, 0, 0, 100);
|
|
881
|
+
* ellipse(width / 2 + random(-2, 2), height / 2 + random(-2, 2), rad, rad);
|
|
882
|
+
*
|
|
883
|
+
* if (eqFeatureIndex >= earthquakes.features.length) {
|
|
884
|
+
* eqFeatureIndex = 0;
|
|
885
|
+
* } else {
|
|
886
|
+
* eqFeatureIndex += 1;
|
|
887
|
+
* }
|
|
888
|
+
* }
|
|
889
|
+
* </code>
|
|
890
|
+
* </div>
|
|
891
|
+
*/
|
|
892
|
+
function httpDo(path: string | Request, method?: string, datatype?: string, data?: object, callback?: Function, errorCallback?: Function): Promise;
|
|
893
|
+
|
|
894
|
+
/**
|
|
895
|
+
*/
|
|
896
|
+
function httpDo(path: string | Request, callback?: Function, errorCallback?: Function): Promise;
|
|
897
|
+
|
|
898
|
+
/**
|
|
899
|
+
* Creates a new p5.PrintWriter object.p5.PrintWriter objects provide a way to
|
|
900
|
+
* save a sequence of text data, called the , to the user's
|
|
901
|
+
* computer. They're low-level objects that enable precise control of text
|
|
902
|
+
* output. Functions such as
|
|
903
|
+
* saveStrings() and
|
|
904
|
+
* saveJSON() are easier to use for simple file
|
|
905
|
+
* saving.The first parameter, `filename`, is the name of the file to be written. If
|
|
906
|
+
* a string is passed, as in `createWriter('words.txt')`, a new
|
|
907
|
+
* p5.PrintWriter object will be created that
|
|
908
|
+
* writes to a file named `words.txt`.The second parameter, `extension`, is optional. If a string is passed, as
|
|
909
|
+
* in `createWriter('words', 'csv')`, the first parameter will be interpreted
|
|
910
|
+
* as the file name and the second parameter as the extension.
|
|
911
|
+
*
|
|
912
|
+
* @param name of the file to create.
|
|
913
|
+
* @param format to use for the file.
|
|
914
|
+
* @return stream for writing data.
|
|
915
|
+
* @example <div>
|
|
916
|
+
* <code>
|
|
917
|
+
* function setup() {
|
|
918
|
+
* createCanvas(100, 100);
|
|
919
|
+
*
|
|
920
|
+
* background(200);
|
|
921
|
+
*
|
|
922
|
+
* // Style the text.
|
|
923
|
+
* textAlign(LEFT, CENTER);
|
|
924
|
+
* textFont('Courier New');
|
|
925
|
+
* textSize(12);
|
|
926
|
+
*
|
|
927
|
+
* // Display instructions.
|
|
928
|
+
* text('Double-click to save', 5, 50, 90);
|
|
929
|
+
*
|
|
930
|
+
* describe('The text "Double-click to save" written in black on a gray background.');
|
|
931
|
+
* }
|
|
932
|
+
*
|
|
933
|
+
* // Save the file when the user double-clicks.
|
|
934
|
+
* function doubleClicked() {
|
|
935
|
+
* if (mouseX > 0 && mouseX < 100 && mouseY > 0 && mouseY < 100) {
|
|
936
|
+
* // Create a p5.PrintWriter object.
|
|
937
|
+
* let myWriter = createWriter('xo.txt');
|
|
938
|
+
*
|
|
939
|
+
* // Add some lines to the print stream.
|
|
940
|
+
* myWriter.print('XOO');
|
|
941
|
+
* myWriter.print('OXO');
|
|
942
|
+
* myWriter.print('OOX');
|
|
943
|
+
*
|
|
944
|
+
* // Save the file and close the print stream.
|
|
945
|
+
* myWriter.close();
|
|
946
|
+
* }
|
|
947
|
+
* }
|
|
948
|
+
* </code>
|
|
949
|
+
* </div>
|
|
950
|
+
*
|
|
951
|
+
* <div>
|
|
952
|
+
* <code>
|
|
953
|
+
* function setup() {
|
|
954
|
+
* createCanvas(100, 100);
|
|
955
|
+
*
|
|
956
|
+
* background(200);
|
|
957
|
+
*
|
|
958
|
+
* // Style the text.
|
|
959
|
+
* textAlign(LEFT, CENTER);
|
|
960
|
+
* textFont('Courier New');
|
|
961
|
+
* textSize(12);
|
|
962
|
+
*
|
|
963
|
+
* // Display instructions.
|
|
964
|
+
* text('Double-click to save', 5, 50, 90);
|
|
965
|
+
*
|
|
966
|
+
* describe('The text "Double-click to save" written in black on a gray background.');
|
|
967
|
+
* }
|
|
968
|
+
*
|
|
969
|
+
* // Save the file when the user double-clicks.
|
|
970
|
+
* function doubleClicked() {
|
|
971
|
+
* if (mouseX > 0 && mouseX < 100 && mouseY > 0 && mouseY < 100) {
|
|
972
|
+
* // Create a p5.PrintWriter object.
|
|
973
|
+
* // Use the file format .csv.
|
|
974
|
+
* let myWriter = createWriter('mauna_loa_co2', 'csv');
|
|
975
|
+
*
|
|
976
|
+
* // Add some lines to the print stream.
|
|
977
|
+
* myWriter.print('date,ppm_co2');
|
|
978
|
+
* myWriter.print('1960-01-01,316.43');
|
|
979
|
+
* myWriter.print('1970-01-01,325.06');
|
|
980
|
+
* myWriter.print('1980-01-01,337.9');
|
|
981
|
+
* myWriter.print('1990-01-01,353.86');
|
|
982
|
+
* myWriter.print('2000-01-01,369.45');
|
|
983
|
+
* myWriter.print('2020-01-01,413.61');
|
|
984
|
+
*
|
|
985
|
+
* // Save the file and close the print stream.
|
|
986
|
+
* myWriter.close();
|
|
987
|
+
* }
|
|
988
|
+
* }
|
|
989
|
+
* </code>
|
|
990
|
+
* </div>
|
|
991
|
+
*/
|
|
992
|
+
function createWriter(name: string, extension?: string): p5.PrintWriter;
|
|
993
|
+
|
|
994
|
+
/**
|
|
995
|
+
* Writes data to the print stream without adding new lines.The parameter, `data`, is the data to write. `data` can be a number or
|
|
996
|
+
* string, as in `myWriter.write('hi')`, or an array of numbers and strings,
|
|
997
|
+
* as in `myWriter.write([1, 2, 3])`. A comma will be inserted between array
|
|
998
|
+
* array elements when they're added to the print stream.
|
|
999
|
+
*
|
|
1000
|
+
* @param data to be written as a string, number,
|
|
1001
|
+
* or array of strings and numbers.
|
|
1002
|
+
* @example <div>
|
|
1003
|
+
* <code>
|
|
1004
|
+
* function setup() {
|
|
1005
|
+
* createCanvas(100, 100);
|
|
1006
|
+
*
|
|
1007
|
+
* background(200);
|
|
1008
|
+
*
|
|
1009
|
+
* // Style the text.
|
|
1010
|
+
* textAlign(LEFT, CENTER);
|
|
1011
|
+
* textFont('Courier New');
|
|
1012
|
+
* textSize(12);
|
|
1013
|
+
*
|
|
1014
|
+
* // Display instructions.
|
|
1015
|
+
* text('Double-click to save', 5, 50, 90);
|
|
1016
|
+
*
|
|
1017
|
+
* describe('The text "Double-click to save" written in black on a gray background.');
|
|
1018
|
+
* }
|
|
1019
|
+
*
|
|
1020
|
+
* // Save the file when the user double-clicks.
|
|
1021
|
+
* function doubleClicked() {
|
|
1022
|
+
* // Create a p5.PrintWriter object.
|
|
1023
|
+
* let myWriter = createWriter('numbers.txt');
|
|
1024
|
+
*
|
|
1025
|
+
* // Add some data to the print stream.
|
|
1026
|
+
* myWriter.write('1,2,3,');
|
|
1027
|
+
* myWriter.write(['4', '5', '6']);
|
|
1028
|
+
*
|
|
1029
|
+
* // Save the file and close the print stream.
|
|
1030
|
+
* myWriter.close();
|
|
1031
|
+
* }
|
|
1032
|
+
* </code>
|
|
1033
|
+
* </div>
|
|
1034
|
+
*/
|
|
1035
|
+
function write(data: string | number | Array): void;
|
|
1036
|
+
|
|
1037
|
+
/**
|
|
1038
|
+
* Saves the file and closes the print stream.
|
|
1039
|
+
*
|
|
1040
|
+
* @example <div>
|
|
1041
|
+
* <code>
|
|
1042
|
+
* function setup() {
|
|
1043
|
+
* createCanvas(100, 100);
|
|
1044
|
+
*
|
|
1045
|
+
* background(200);
|
|
1046
|
+
*
|
|
1047
|
+
* // Style the text.
|
|
1048
|
+
* textAlign(LEFT, CENTER);
|
|
1049
|
+
* textFont('Courier New');
|
|
1050
|
+
* textSize(12);
|
|
1051
|
+
*
|
|
1052
|
+
* // Display instructions.
|
|
1053
|
+
* text('Double-click to save', 5, 50, 90);
|
|
1054
|
+
*
|
|
1055
|
+
* describe('The text "Double-click to save" written in black on a gray background.');
|
|
1056
|
+
* }
|
|
1057
|
+
*
|
|
1058
|
+
* // Save the file when the user double-clicks.
|
|
1059
|
+
* function doubleClicked() {
|
|
1060
|
+
* // Create a p5.PrintWriter object.
|
|
1061
|
+
* let myWriter = createWriter('cat.txt');
|
|
1062
|
+
*
|
|
1063
|
+
* // Add some data to the print stream.
|
|
1064
|
+
* // ASCII art courtesy Wikipedia:
|
|
1065
|
+
* // https://en.wikipedia.org/wiki/ASCII_art
|
|
1066
|
+
* myWriter.print(' (\\_/) ');
|
|
1067
|
+
* myWriter.print("(='.'=)");
|
|
1068
|
+
* myWriter.print('(")_(")');
|
|
1069
|
+
*
|
|
1070
|
+
* // Save the file and close the print stream.
|
|
1071
|
+
* myWriter.close();
|
|
1072
|
+
* }
|
|
1073
|
+
* </code>
|
|
1074
|
+
* </div>
|
|
1075
|
+
*/
|
|
1076
|
+
function close(): void;
|
|
1077
|
+
|
|
1078
|
+
/**
|
|
1079
|
+
* Saves a given element(image, text, json, csv, wav, or html) to the client's
|
|
1080
|
+
* computer. The first parameter can be a pointer to element we want to save.
|
|
1081
|
+
* The element can be one of p5.Element,an Array of
|
|
1082
|
+
* Strings, an Array of JSON, a JSON object, a p5.Table
|
|
1083
|
+
* , a p5.Image, or a p5.SoundFile (requires
|
|
1084
|
+
* p5.sound). The second parameter is a filename (including extension).The
|
|
1085
|
+
* third parameter is for options specific to this type of object. This method
|
|
1086
|
+
* will save a file that fits the given parameters.
|
|
1087
|
+
* If it is called without specifying an element, by default it will save the
|
|
1088
|
+
* whole canvas as an image file. You can optionally specify a filename as
|
|
1089
|
+
* the first parameter in such a case.
|
|
1090
|
+
*
|
|
1091
|
+
* @param If filename is provided, will
|
|
1092
|
+
* save canvas as an image with
|
|
1093
|
+
* either png or jpg extension
|
|
1094
|
+
* depending on the filename.
|
|
1095
|
+
* If object is provided, will
|
|
1096
|
+
* save depending on the object
|
|
1097
|
+
* and filename (see examples
|
|
1098
|
+
* above).
|
|
1099
|
+
* @param If an object is provided as the first
|
|
1100
|
+
* parameter, then the second parameter
|
|
1101
|
+
* indicates the filename,
|
|
1102
|
+
* and should include an appropriate
|
|
1103
|
+
* file extension (see examples above).
|
|
1104
|
+
* @param Additional options depend on
|
|
1105
|
+
* filetype. For example, when saving JSON,
|
|
1106
|
+
* <code>true</code> indicates that the
|
|
1107
|
+
* output will be optimized for filesize,
|
|
1108
|
+
* rather than readability.
|
|
1109
|
+
* @example <div class="norender"><code>
|
|
1110
|
+
* // Saves the canvas as an image
|
|
1111
|
+
* cnv = createCanvas(300, 300);
|
|
1112
|
+
* save(cnv, 'myCanvas.jpg');
|
|
1113
|
+
*
|
|
1114
|
+
* // Saves the canvas as an image by default
|
|
1115
|
+
* save('myCanvas.jpg');
|
|
1116
|
+
* describe('An example for saving a canvas as an image.');
|
|
1117
|
+
* </code></div>
|
|
1118
|
+
*
|
|
1119
|
+
* <div class="norender"><code>
|
|
1120
|
+
* // Saves p5.Image as an image
|
|
1121
|
+
* img = createImage(10, 10);
|
|
1122
|
+
* save(img, 'myImage.png');
|
|
1123
|
+
* describe('An example for saving a p5.Image element as an image.');
|
|
1124
|
+
* </code></div>
|
|
1125
|
+
*
|
|
1126
|
+
* <div class="norender"><code>
|
|
1127
|
+
* // Saves p5.Renderer object as an image
|
|
1128
|
+
* obj = createGraphics(100, 100);
|
|
1129
|
+
* save(obj, 'myObject.png');
|
|
1130
|
+
* describe('An example for saving a p5.Renderer element.');
|
|
1131
|
+
* </code></div>
|
|
1132
|
+
*
|
|
1133
|
+
* <div class="norender"><code>
|
|
1134
|
+
* let myTable = new p5.Table();
|
|
1135
|
+
* // Saves table as html file
|
|
1136
|
+
* save(myTable, 'myTable.html');
|
|
1137
|
+
*
|
|
1138
|
+
* // Comma Separated Values
|
|
1139
|
+
* save(myTable, 'myTable.csv');
|
|
1140
|
+
*
|
|
1141
|
+
* // Tab Separated Values
|
|
1142
|
+
* save(myTable, 'myTable.tsv');
|
|
1143
|
+
*
|
|
1144
|
+
* describe(`An example showing how to save a table in formats of
|
|
1145
|
+
* HTML, CSV and TSV.`);
|
|
1146
|
+
* </code></div>
|
|
1147
|
+
*
|
|
1148
|
+
* <div class="norender"><code>
|
|
1149
|
+
* let myJSON = { a: 1, b: true };
|
|
1150
|
+
*
|
|
1151
|
+
* // Saves pretty JSON
|
|
1152
|
+
* save(myJSON, 'my.json');
|
|
1153
|
+
*
|
|
1154
|
+
* // Optimizes JSON filesize
|
|
1155
|
+
* save(myJSON, 'my.json', true);
|
|
1156
|
+
*
|
|
1157
|
+
* describe('An example for saving JSON to a txt file with some extra arguments.');
|
|
1158
|
+
* </code></div>
|
|
1159
|
+
*
|
|
1160
|
+
* <div class="norender"><code>
|
|
1161
|
+
* // Saves array of strings to text file with line breaks after each item
|
|
1162
|
+
* let arrayOfStrings = ['a', 'b'];
|
|
1163
|
+
* save(arrayOfStrings, 'my.txt');
|
|
1164
|
+
* describe(`An example for saving an array of strings to text file
|
|
1165
|
+
* with line breaks.`);
|
|
1166
|
+
* </code></div>
|
|
1167
|
+
*/
|
|
1168
|
+
function save(objectOrFilename?: object | string, filename?: string, options?: boolean | string): void;
|
|
1169
|
+
|
|
1170
|
+
/**
|
|
1171
|
+
* Saves an `Object` or `Array` to a JSON file.JavaScript Object Notation
|
|
1172
|
+
* (JSON)
|
|
1173
|
+
* is a standard format for sending data between applications. The format is
|
|
1174
|
+
* based on JavaScript objects which have keys and values. JSON files store
|
|
1175
|
+
* data in an object with strings as keys. Values can be strings, numbers,
|
|
1176
|
+
* Booleans, arrays, `null`, or other objects.The first parameter, `json`, is the data to save. The data can be an array,
|
|
1177
|
+
* as in `[1, 2, 3]`, or an object, as in
|
|
1178
|
+
* `{ x: 50, y: 50, color: 'deeppink' }`.The second parameter, `filename`, is a string that sets the file's name.
|
|
1179
|
+
* For example, calling `saveJSON([1, 2, 3], 'data.json')` saves the array
|
|
1180
|
+
* `[1, 2, 3]` to a file called `data.json` on the user's computer.The third parameter, `optimize`, is optional. If `true` is passed, as in
|
|
1181
|
+
* `saveJSON([1, 2, 3], 'data.json', true)`, then all unneeded whitespace will
|
|
1182
|
+
* be removed to reduce the file size.Note: The browser will either save the file immediately or prompt the user
|
|
1183
|
+
* with a dialogue window.
|
|
1184
|
+
*
|
|
1185
|
+
* @param data to save.
|
|
1186
|
+
* @param name of the file to be saved.
|
|
1187
|
+
* @param whether to trim unneeded whitespace. Defaults
|
|
1188
|
+
* to `true`.
|
|
1189
|
+
* @example <div>
|
|
1190
|
+
* <code>
|
|
1191
|
+
* function setup() {
|
|
1192
|
+
* createCanvas(100, 100);
|
|
1193
|
+
*
|
|
1194
|
+
* background(200);
|
|
1195
|
+
*
|
|
1196
|
+
* // Style the text.
|
|
1197
|
+
* textAlign(LEFT, CENTER);
|
|
1198
|
+
* textFont('Courier New');
|
|
1199
|
+
* textSize(12);
|
|
1200
|
+
*
|
|
1201
|
+
* // Display instructions.
|
|
1202
|
+
* text('Double-click to save', 5, 50, 90);
|
|
1203
|
+
*
|
|
1204
|
+
* describe('The text "Double-click to save" written in black on a gray background.');
|
|
1205
|
+
* }
|
|
1206
|
+
*
|
|
1207
|
+
* // Save the file when the user double-clicks.
|
|
1208
|
+
* function doubleClicked() {
|
|
1209
|
+
* if (mouseX > 0 && mouseX < 100 && mouseY > 0 && mouseY < 100) {
|
|
1210
|
+
* // Create an array.
|
|
1211
|
+
* let data = [1, 2, 3];
|
|
1212
|
+
*
|
|
1213
|
+
* // Save the JSON file.
|
|
1214
|
+
* saveJSON(data, 'numbers.json');
|
|
1215
|
+
* }
|
|
1216
|
+
* }
|
|
1217
|
+
* </code>
|
|
1218
|
+
* </div>
|
|
1219
|
+
*
|
|
1220
|
+
* <div>
|
|
1221
|
+
* <code>
|
|
1222
|
+
* function setup() {
|
|
1223
|
+
* createCanvas(100, 100);
|
|
1224
|
+
*
|
|
1225
|
+
* background(200);
|
|
1226
|
+
*
|
|
1227
|
+
* // Style the text.
|
|
1228
|
+
* textAlign(LEFT, CENTER);
|
|
1229
|
+
* textFont('Courier New');
|
|
1230
|
+
* textSize(12);
|
|
1231
|
+
*
|
|
1232
|
+
* // Display instructions.
|
|
1233
|
+
* text('Double-click to save', 5, 50, 90);
|
|
1234
|
+
*
|
|
1235
|
+
* describe('The text "Double-click to save" written in black on a gray background.');
|
|
1236
|
+
* }
|
|
1237
|
+
*
|
|
1238
|
+
* // Save the file when the user double-clicks.
|
|
1239
|
+
* function doubleClicked() {
|
|
1240
|
+
* if (mouseX > 0 && mouseX < 100 && mouseY > 0 && mouseY < 100) {
|
|
1241
|
+
* // Create an object.
|
|
1242
|
+
* let data = { x: mouseX, y: mouseY };
|
|
1243
|
+
*
|
|
1244
|
+
* // Save the JSON file.
|
|
1245
|
+
* saveJSON(data, 'state.json');
|
|
1246
|
+
* }
|
|
1247
|
+
* }
|
|
1248
|
+
* </code>
|
|
1249
|
+
* </div>
|
|
1250
|
+
*
|
|
1251
|
+
* <div>
|
|
1252
|
+
* <code>
|
|
1253
|
+
* function setup() {
|
|
1254
|
+
* createCanvas(100, 100);
|
|
1255
|
+
*
|
|
1256
|
+
* background(200);
|
|
1257
|
+
*
|
|
1258
|
+
* // Style the text.
|
|
1259
|
+
* textAlign(LEFT, CENTER);
|
|
1260
|
+
* textFont('Courier New');
|
|
1261
|
+
* textSize(12);
|
|
1262
|
+
*
|
|
1263
|
+
* // Display instructions.
|
|
1264
|
+
* text('Double-click to save', 5, 50, 90);
|
|
1265
|
+
*
|
|
1266
|
+
* describe('The text "Double-click to save" written in black on a gray background.');
|
|
1267
|
+
* }
|
|
1268
|
+
*
|
|
1269
|
+
* // Save the file when the user double-clicks.
|
|
1270
|
+
* function doubleClicked() {
|
|
1271
|
+
* if (mouseX > 0 && mouseX < 100 && mouseY > 0 && mouseY < 100) {
|
|
1272
|
+
* // Create an object.
|
|
1273
|
+
* let data = { x: mouseX, y: mouseY };
|
|
1274
|
+
*
|
|
1275
|
+
* // Save the JSON file and reduce its size.
|
|
1276
|
+
* saveJSON(data, 'state.json', true);
|
|
1277
|
+
* }
|
|
1278
|
+
* }
|
|
1279
|
+
* </code>
|
|
1280
|
+
* </div>
|
|
1281
|
+
*/
|
|
1282
|
+
function saveJSON(json: Array | object, filename: string, optimize?: boolean): void;
|
|
1283
|
+
|
|
1284
|
+
/**
|
|
1285
|
+
* Saves an `Array` of `String`s to a file, one per line.The first parameter, `list`, is an array with the strings to save.The second parameter, `filename`, is a string that sets the file's name.
|
|
1286
|
+
* For example, calling `saveStrings(['0', '01', '011'], 'data.txt')` saves
|
|
1287
|
+
* the array `['0', '01', '011']` to a file called `data.txt` on the user's
|
|
1288
|
+
* computer.The third parameter, `extension`, is optional. If a string is passed, as in
|
|
1289
|
+
* `saveStrings(['0', '01', '0`1'], 'data', 'txt')`, the second parameter will
|
|
1290
|
+
* be interpreted as the file name and the third parameter as the extension.The fourth parameter, `isCRLF`, is also optional, If `true` is passed, as
|
|
1291
|
+
* in `saveStrings(['0', '01', '011'], 'data', 'txt', true)`, then two
|
|
1292
|
+
* characters, `\r\n` , will be added to the end of each string to create new
|
|
1293
|
+
* lines in the saved file. `\r` is a carriage return (CR) and `\n` is a line
|
|
1294
|
+
* feed (LF). By default, only `\n` (line feed) is added to each string in
|
|
1295
|
+
* order to create new lines.Note: The browser will either save the file immediately or prompt the user
|
|
1296
|
+
* with a dialogue window.
|
|
1297
|
+
*
|
|
1298
|
+
* @param data to save.
|
|
1299
|
+
* @param name of file to be saved.
|
|
1300
|
+
* @param format to use for the file.
|
|
1301
|
+
* @param whether to add `\r\n` to the end of each
|
|
1302
|
+
* string. Defaults to `false`.
|
|
1303
|
+
* @example <div>
|
|
1304
|
+
* <code>
|
|
1305
|
+
* function setup() {
|
|
1306
|
+
* createCanvas(100, 100);
|
|
1307
|
+
*
|
|
1308
|
+
* background(200);
|
|
1309
|
+
*
|
|
1310
|
+
* // Style the text.
|
|
1311
|
+
* textAlign(LEFT, CENTER);
|
|
1312
|
+
* textFont('Courier New');
|
|
1313
|
+
* textSize(12);
|
|
1314
|
+
*
|
|
1315
|
+
* // Display instructions.
|
|
1316
|
+
* text('Double-click to save', 5, 50, 90);
|
|
1317
|
+
*
|
|
1318
|
+
* describe('The text "Double-click to save" written in black on a gray background.');
|
|
1319
|
+
* }
|
|
1320
|
+
*
|
|
1321
|
+
* // Save the file when the user double-clicks.
|
|
1322
|
+
* function doubleClicked() {
|
|
1323
|
+
* if (mouseX > 0 && mouseX < 100 && mouseY > 0 && mouseY < 100) {
|
|
1324
|
+
* // Create an array.
|
|
1325
|
+
* let data = ['0', '01', '011'];
|
|
1326
|
+
*
|
|
1327
|
+
* // Save the text file.
|
|
1328
|
+
* saveStrings(data, 'data.txt');
|
|
1329
|
+
* }
|
|
1330
|
+
* }
|
|
1331
|
+
* </code>
|
|
1332
|
+
* </div>
|
|
1333
|
+
*
|
|
1334
|
+
* <div>
|
|
1335
|
+
* <code>
|
|
1336
|
+
* function setup() {
|
|
1337
|
+
* createCanvas(100, 100);
|
|
1338
|
+
*
|
|
1339
|
+
* background(200);
|
|
1340
|
+
*
|
|
1341
|
+
* // Style the text.
|
|
1342
|
+
* textAlign(LEFT, CENTER);
|
|
1343
|
+
* textFont('Courier New');
|
|
1344
|
+
* textSize(12);
|
|
1345
|
+
*
|
|
1346
|
+
* // Display instructions.
|
|
1347
|
+
* text('Double-click to save', 5, 50, 90);
|
|
1348
|
+
*
|
|
1349
|
+
* describe('The text "Double-click to save" written in black on a gray background.');
|
|
1350
|
+
* }
|
|
1351
|
+
*
|
|
1352
|
+
* // Save the file when the user double-clicks.
|
|
1353
|
+
* function doubleClicked() {
|
|
1354
|
+
* if (mouseX > 0 && mouseX < 100 && mouseY > 0 && mouseY < 100) {
|
|
1355
|
+
* // Create an array.
|
|
1356
|
+
* // ASCII art courtesy Wikipedia:
|
|
1357
|
+
* // https://en.wikipedia.org/wiki/ASCII_art
|
|
1358
|
+
* let data = [' (\\_/) ', "(='.'=)", '(")_(")'];
|
|
1359
|
+
*
|
|
1360
|
+
* // Save the text file.
|
|
1361
|
+
* saveStrings(data, 'cat', 'txt');
|
|
1362
|
+
* }
|
|
1363
|
+
* }
|
|
1364
|
+
* </code>
|
|
1365
|
+
* </div>
|
|
1366
|
+
*
|
|
1367
|
+
* <div>
|
|
1368
|
+
* <code>
|
|
1369
|
+
* function setup() {
|
|
1370
|
+
* createCanvas(100, 100);
|
|
1371
|
+
*
|
|
1372
|
+
* background(200);
|
|
1373
|
+
*
|
|
1374
|
+
* // Style the text.
|
|
1375
|
+
* textAlign(LEFT, CENTER);
|
|
1376
|
+
* textFont('Courier New');
|
|
1377
|
+
* textSize(12);
|
|
1378
|
+
*
|
|
1379
|
+
* // Display instructions.
|
|
1380
|
+
* text('Double-click to save', 5, 50, 90);
|
|
1381
|
+
*
|
|
1382
|
+
* describe('The text "Double-click to save" written in black on a gray background.');
|
|
1383
|
+
* }
|
|
1384
|
+
*
|
|
1385
|
+
* // Save the file when the user double-clicks.
|
|
1386
|
+
* function doubleClicked() {
|
|
1387
|
+
* if (mouseX > 0 && mouseX < 100 && mouseY > 0 && mouseY < 100) {
|
|
1388
|
+
* // Create an array.
|
|
1389
|
+
* // +--+
|
|
1390
|
+
* // / /|
|
|
1391
|
+
* // +--+ +
|
|
1392
|
+
* // | |/
|
|
1393
|
+
* // +--+
|
|
1394
|
+
* let data = [' +--+', ' / /|', '+--+ +', '| |/', '+--+'];
|
|
1395
|
+
*
|
|
1396
|
+
* // Save the text file.
|
|
1397
|
+
* // Use CRLF for line endings.
|
|
1398
|
+
* saveStrings(data, 'box', 'txt', true);
|
|
1399
|
+
* }
|
|
1400
|
+
* }
|
|
1401
|
+
* </code>
|
|
1402
|
+
* </div>
|
|
1403
|
+
*/
|
|
1404
|
+
function saveStrings(list: string[], filename: string, extension?: string, isCRLF?: boolean): void;
|
|
1405
|
+
|
|
1406
|
+
/**
|
|
1407
|
+
* Writes the contents of a Table object to a file. Defaults to a
|
|
1408
|
+
* text file with comma-separated-values ('csv') but can also
|
|
1409
|
+
* use tab separation ('tsv'), or generate an HTML table ('html').
|
|
1410
|
+
* The file saving process and location of the saved file will
|
|
1411
|
+
* vary between web browsers.
|
|
1412
|
+
*
|
|
1413
|
+
* @deprecated p5.Table will be removed in a future version of p5.js to make way for a new, friendlier version :)
|
|
1414
|
+
* @param the <a href="#/p5.Table">Table</a> object to save to a file
|
|
1415
|
+
* @param the filename to which the Table should be saved
|
|
1416
|
+
* @param can be one of "tsv", "csv", or "html"
|
|
1417
|
+
* @example <div><code>
|
|
1418
|
+
* let table;
|
|
1419
|
+
*
|
|
1420
|
+
* function setup() {
|
|
1421
|
+
* table = new p5.Table();
|
|
1422
|
+
*
|
|
1423
|
+
* table.addColumn('id');
|
|
1424
|
+
* table.addColumn('species');
|
|
1425
|
+
* table.addColumn('name');
|
|
1426
|
+
*
|
|
1427
|
+
* let newRow = table.addRow();
|
|
1428
|
+
* newRow.setNum('id', table.getRowCount() - 1);
|
|
1429
|
+
* newRow.setString('species', 'Panthera leo');
|
|
1430
|
+
* newRow.setString('name', 'Lion');
|
|
1431
|
+
*
|
|
1432
|
+
* // To save, un-comment next line then click 'run'
|
|
1433
|
+
* // saveTable(table, 'new.csv');
|
|
1434
|
+
*
|
|
1435
|
+
* describe('no image displayed');
|
|
1436
|
+
* }
|
|
1437
|
+
*
|
|
1438
|
+
* // Saves the following to a file called 'new.csv':
|
|
1439
|
+
* // id,species,name
|
|
1440
|
+
* // 0,Panthera leo,Lion
|
|
1441
|
+
* </code></div>
|
|
1442
|
+
*/
|
|
1443
|
+
function saveTable(Table: p5.Table, filename: string, options?: string): void;
|
|
1444
|
+
|
|
1445
|
+
}
|
|
1446
|
+
|
|
1447
|
+
export default function files(p5: any, fn: any): void;
|