p5 2.2.2 → 2.2.3-rc.1
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/index.js +5 -5
- package/dist/app.js +5 -5
- package/dist/color/color_conversion.js +5 -5
- package/dist/color/index.js +1 -1
- package/dist/color/setting.js +1 -1
- package/dist/{constants-BxjhKpTv.js → constants-BUwWryrh.js} +1 -1
- package/dist/core/constants.js +1 -1
- package/dist/core/environment.js +7 -3
- package/dist/core/filterShaders.js +1 -1
- package/dist/core/friendly_errors/fes_core.js +1 -1
- package/dist/core/friendly_errors/file_errors.js +1 -1
- package/dist/core/friendly_errors/index.js +1 -1
- package/dist/core/friendly_errors/param_validator.js +2063 -2014
- package/dist/core/friendly_errors/sketch_verifier.js +1 -1
- package/dist/core/helpers.js +1 -1
- package/dist/core/init.js +5 -5
- package/dist/core/internationalization.js +1 -1
- package/dist/core/legacy.js +5 -5
- package/dist/core/main.js +5 -5
- package/dist/core/p5.Graphics.js +3 -3
- package/dist/core/p5.Renderer.js +2 -2
- package/dist/core/p5.Renderer2D.js +5 -5
- package/dist/core/p5.Renderer3D.js +3 -3
- package/dist/core/rendering.js +3 -3
- package/dist/dom/dom.js +1 -1
- package/dist/dom/index.js +1 -1
- package/dist/dom/p5.Element.js +1 -1
- package/dist/dom/p5.MediaElement.js +11 -4
- package/dist/events/pointer.js +4 -0
- package/dist/image/const.js +1 -1
- package/dist/image/filterRenderer2D.js +4 -4
- package/dist/image/image.js +3 -3
- package/dist/image/index.js +3 -3
- package/dist/image/loading_displaying.js +3 -3
- package/dist/image/p5.Image.js +2 -2
- package/dist/io/files.js +3 -3
- package/dist/io/index.js +3 -3
- package/dist/{ir_builders-w12-GSxu.js → ir_builders-Cd6rU9Vm.js} +48 -14
- package/dist/{main-DDs4QOnh.js → main-DFpoFdvM.js} +126 -36
- 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/p5.Matrix.js +1 -1
- package/dist/math/p5.Vector.js +1 -1
- package/dist/math/trigonometry.js +1 -1
- package/dist/{p5.Renderer-BSGddFv7.js → p5.Renderer-D-EuAodU.js} +9 -2
- package/dist/{rendering-C9g7uSQ5.js → rendering-DE9-Hl7Y.js} +103 -78
- package/dist/shape/2d_primitives.js +1 -1
- package/dist/shape/attributes.js +1 -1
- package/dist/shape/custom_shapes.js +1 -1
- package/dist/shape/index.js +1 -1
- package/dist/strands/ir_builders.js +1 -1
- package/dist/strands/ir_dag.js +32 -2
- package/dist/strands/ir_types.js +18 -11
- package/dist/strands/p5.strands.js +24 -35
- package/dist/strands/strands_api.js +86 -41
- package/dist/strands/strands_codegen.js +0 -12
- package/dist/strands/strands_conditionals.js +1 -1
- package/dist/strands/strands_for.js +1 -1
- package/dist/strands/strands_node.js +1 -1
- package/dist/strands/strands_phi_utils.js +27 -9
- package/dist/strands/strands_transpiler.js +1237 -831
- package/dist/type/index.js +2 -2
- package/dist/type/p5.Font.js +7 -5
- package/dist/type/textCore.js +2 -2
- package/dist/webgl/3d_primitives.js +3 -3
- package/dist/webgl/GeometryBuilder.js +1 -1
- package/dist/webgl/ShapeBuilder.js +1 -1
- package/dist/webgl/enums.js +1 -1
- package/dist/webgl/index.js +4 -4
- package/dist/webgl/interaction.js +1 -1
- package/dist/webgl/light.js +3 -3
- package/dist/webgl/loading.js +41 -35
- package/dist/webgl/material.js +3 -3
- package/dist/webgl/p5.Camera.js +3 -3
- package/dist/webgl/p5.Framebuffer.js +3 -3
- 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 +14 -6
- package/dist/webgl/p5.Texture.js +3 -3
- package/dist/webgl/strands_glslBackend.js +1 -1
- package/dist/webgl/text.js +3 -3
- package/dist/webgl/utils.js +3 -3
- package/dist/webgpu/index.js +2 -2
- package/dist/webgpu/p5.RendererWebGPU.js +2 -2
- package/dist/webgpu/strands_wgslBackend.js +13 -4
- package/lib/p5.esm.js +3670 -2951
- package/lib/p5.esm.min.js +1 -1
- package/lib/p5.js +3670 -2951
- package/lib/p5.min.js +1 -1
- package/lib/p5.webgpu.esm.js +43 -21
- package/lib/p5.webgpu.js +43 -21
- package/lib/p5.webgpu.min.js +1 -1
- package/package.json +1 -1
- package/types/global.d.ts +1283 -1301
- package/types/p5.d.ts +655 -657
package/types/p5.d.ts
CHANGED
|
@@ -60,6 +60,14 @@ declare const accelerationX: number;
|
|
|
60
60
|
|
|
61
61
|
declare const __accelerationX: typeof accelerationX;
|
|
62
62
|
|
|
63
|
+
/**
|
|
64
|
+
* The system variable accelerationY always contains the acceleration of the
|
|
65
|
+
* device along the y axis. Value is represented as meters per second squared.
|
|
66
|
+
*/
|
|
67
|
+
declare const accelerationY: number;
|
|
68
|
+
|
|
69
|
+
declare const __accelerationY: typeof accelerationY;
|
|
70
|
+
|
|
63
71
|
/**
|
|
64
72
|
* A `Number` system variable that tracks the mouse's horizontal movement.
|
|
65
73
|
*
|
|
@@ -75,14 +83,6 @@ declare const movedX: number;
|
|
|
75
83
|
|
|
76
84
|
declare const __movedX: typeof movedX;
|
|
77
85
|
|
|
78
|
-
/**
|
|
79
|
-
* The system variable accelerationY always contains the acceleration of the
|
|
80
|
-
* device along the y axis. Value is represented as meters per second squared.
|
|
81
|
-
*/
|
|
82
|
-
declare const accelerationY: number;
|
|
83
|
-
|
|
84
|
-
declare const __accelerationY: typeof accelerationY;
|
|
85
|
-
|
|
86
86
|
/**
|
|
87
87
|
* The system variable accelerationZ always contains the acceleration of the
|
|
88
88
|
* device along the z axis. Value is represented as meters per second squared.
|
|
@@ -263,20 +263,6 @@ declare const pRotationX: number;
|
|
|
263
263
|
|
|
264
264
|
declare const __pRotationX: typeof pRotationX;
|
|
265
265
|
|
|
266
|
-
/**
|
|
267
|
-
* A `Number` system variable that tracks the mouse's vertical position.
|
|
268
|
-
*
|
|
269
|
-
* `mouseY` keeps track of the mouse's position relative to the
|
|
270
|
-
* top-left corner of the canvas. For example, if the mouse is 50 pixels from
|
|
271
|
-
* the top edge of the canvas, then `mouseY` will be 50.
|
|
272
|
-
*
|
|
273
|
-
* If touch is used instead of the mouse, then `mouseY` will hold the
|
|
274
|
-
* y-coordinate of the most recent touch point.
|
|
275
|
-
*/
|
|
276
|
-
declare const mouseY: number;
|
|
277
|
-
|
|
278
|
-
declare const __mouseY: typeof mouseY;
|
|
279
|
-
|
|
280
266
|
/**
|
|
281
267
|
* The system variable pRotationY always contains the rotation of the
|
|
282
268
|
* device along the y axis in the frame previous to the current frame.
|
|
@@ -291,6 +277,20 @@ declare const pRotationY: number;
|
|
|
291
277
|
|
|
292
278
|
declare const __pRotationY: typeof pRotationY;
|
|
293
279
|
|
|
280
|
+
/**
|
|
281
|
+
* A `Number` system variable that tracks the mouse's vertical position.
|
|
282
|
+
*
|
|
283
|
+
* `mouseY` keeps track of the mouse's position relative to the
|
|
284
|
+
* top-left corner of the canvas. For example, if the mouse is 50 pixels from
|
|
285
|
+
* the top edge of the canvas, then `mouseY` will be 50.
|
|
286
|
+
*
|
|
287
|
+
* If touch is used instead of the mouse, then `mouseY` will hold the
|
|
288
|
+
* y-coordinate of the most recent touch point.
|
|
289
|
+
*/
|
|
290
|
+
declare const mouseY: number;
|
|
291
|
+
|
|
292
|
+
declare const __mouseY: typeof mouseY;
|
|
293
|
+
|
|
294
294
|
/**
|
|
295
295
|
* The system variable pRotationZ always contains the rotation of the
|
|
296
296
|
* device along the z axis in the frame previous to the current frame.
|
|
@@ -1099,19 +1099,6 @@ declare const DEG_TO_RAD: number;
|
|
|
1099
1099
|
|
|
1100
1100
|
declare const __DEG_TO_RAD: typeof DEG_TO_RAD;
|
|
1101
1101
|
|
|
1102
|
-
/**
|
|
1103
|
-
* Turns off the parts of the Friendly Error System (FES) that impact performance.
|
|
1104
|
-
*
|
|
1105
|
-
* The <a href="https://github.com/processing/p5.js/blob/main/contributor_docs/friendly_error_system.md" target="_blank">FES</a>
|
|
1106
|
-
* can cause sketches to draw slowly because it does extra work behind the
|
|
1107
|
-
* scenes. For example, the FES checks the arguments passed to functions,
|
|
1108
|
-
* which takes time to process. Disabling the FES can significantly improve
|
|
1109
|
-
* performance by turning off these checks.
|
|
1110
|
-
*/
|
|
1111
|
-
declare let disableFriendlyErrors: boolean;
|
|
1112
|
-
|
|
1113
|
-
declare let __disableFriendlyErrors: typeof disableFriendlyErrors;
|
|
1114
|
-
|
|
1115
1102
|
declare const RAD_TO_DEG: number;
|
|
1116
1103
|
|
|
1117
1104
|
declare const __RAD_TO_DEG: typeof RAD_TO_DEG;
|
|
@@ -1186,6 +1173,19 @@ declare const TRIANGLES: 4;
|
|
|
1186
1173
|
|
|
1187
1174
|
declare const __TRIANGLES: typeof TRIANGLES;
|
|
1188
1175
|
|
|
1176
|
+
/**
|
|
1177
|
+
* Turns off the parts of the Friendly Error System (FES) that impact performance.
|
|
1178
|
+
*
|
|
1179
|
+
* The <a href="https://github.com/processing/p5.js/blob/main/contributor_docs/friendly_error_system.md" target="_blank">FES</a>
|
|
1180
|
+
* can cause sketches to draw slowly because it does extra work behind the
|
|
1181
|
+
* scenes. For example, the FES checks the arguments passed to functions,
|
|
1182
|
+
* which takes time to process. Disabling the FES can significantly improve
|
|
1183
|
+
* performance by turning off these checks.
|
|
1184
|
+
*/
|
|
1185
|
+
declare let disableFriendlyErrors: boolean;
|
|
1186
|
+
|
|
1187
|
+
declare let __disableFriendlyErrors: typeof disableFriendlyErrors;
|
|
1188
|
+
|
|
1189
1189
|
declare const TRIANGLE_FAN: 6;
|
|
1190
1190
|
|
|
1191
1191
|
declare const __TRIANGLE_FAN: typeof TRIANGLE_FAN;
|
|
@@ -2311,6 +2311,65 @@ declare class p5 {
|
|
|
2311
2311
|
*/
|
|
2312
2312
|
beginClip(options?: { invert?: boolean }): void;
|
|
2313
2313
|
|
|
2314
|
+
/**
|
|
2315
|
+
* Creates a light that shines from all directions.
|
|
2316
|
+
*
|
|
2317
|
+
* Ambient light does not come from one direction. Instead, 3D shapes are
|
|
2318
|
+
* lit evenly from all sides. Ambient lights are almost always used in
|
|
2319
|
+
* combination with other types of lights.
|
|
2320
|
+
*
|
|
2321
|
+
* There are three ways to call `ambientLight()` with optional parameters to
|
|
2322
|
+
* set the light’s color.
|
|
2323
|
+
*
|
|
2324
|
+
* The first way to call `ambientLight()` has two parameters, `gray` and
|
|
2325
|
+
* `alpha`. `alpha` is optional. Grayscale and alpha values between 0 and 255
|
|
2326
|
+
* can be passed to set the ambient light’s color, as in `ambientLight(50)` or
|
|
2327
|
+
* `ambientLight(50, 30)`.
|
|
2328
|
+
*
|
|
2329
|
+
* The second way to call `ambientLight()` has one parameter, color. A
|
|
2330
|
+
* <a href="#/p5.Color">p5.Color</a> object, an array of color values, or a
|
|
2331
|
+
* CSS color string, as in `ambientLight('magenta')`, can be passed to set the
|
|
2332
|
+
* ambient light’s color.
|
|
2333
|
+
*
|
|
2334
|
+
* The third way to call `ambientLight()` has four parameters, `v1`, `v2`,
|
|
2335
|
+
* `v3`, and `alpha`. `alpha` is optional. RGBA, HSBA, or HSLA values can be
|
|
2336
|
+
* passed to set the ambient light’s colors, as in `ambientLight(255, 0, 0)`
|
|
2337
|
+
* or `ambientLight(255, 0, 0, 30)`. Color values will be interpreted using
|
|
2338
|
+
* the current <a href="#/p5/colorMode">colorMode()</a>.
|
|
2339
|
+
* @param v1 red or hue value in the current
|
|
2340
|
+
* <a href="#/p5/colorMode">colorMode()</a>.
|
|
2341
|
+
* @param v2 green or saturation value in the current
|
|
2342
|
+
* <a href="#/p5/colorMode">colorMode()</a>.
|
|
2343
|
+
* @param v3 blue, brightness, or lightness value in the current
|
|
2344
|
+
* <a href="#/p5/colorMode">colorMode()</a>.
|
|
2345
|
+
* @param alpha alpha (transparency) value in the current
|
|
2346
|
+
* <a href="#/p5/colorMode">colorMode()</a>.
|
|
2347
|
+
*/
|
|
2348
|
+
ambientLight(v1: number, v2: number, v3: number, alpha?: number): void;
|
|
2349
|
+
ambientLight(gray: number, alpha?: number): void;
|
|
2350
|
+
ambientLight(value: string): void;
|
|
2351
|
+
ambientLight(values: number[]): void;
|
|
2352
|
+
ambientLight(color: p5.Color): void;
|
|
2353
|
+
|
|
2354
|
+
/**
|
|
2355
|
+
* Searches the page for all elements that matches the given
|
|
2356
|
+
* <a href="https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web/CSS_basics#different_types_of_selectors" target="_blank">CSS selector string</a>.
|
|
2357
|
+
*
|
|
2358
|
+
* The selector string can be an ID, class, tag name, or a combination.
|
|
2359
|
+
* `selectAll()` returns an array of <a href="#/p5.Element">p5.Element</a>
|
|
2360
|
+
* objects if it finds any matches and an empty array if none are found.
|
|
2361
|
+
*
|
|
2362
|
+
* The second parameter, `container`, is optional. It specifies a container to
|
|
2363
|
+
* search within. `container` can be CSS selector string, a
|
|
2364
|
+
* <a href="#/p5.Element">p5.Element</a> object, or an
|
|
2365
|
+
* <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement" target="_blank">HTMLElement</a> object.
|
|
2366
|
+
* @param selectors CSS selector string of element to search for.
|
|
2367
|
+
* @param container CSS selector string, <a href="#/p5.Element">p5.Element</a>, or
|
|
2368
|
+
* <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement" target="_blank">HTMLElement</a> to search within.
|
|
2369
|
+
* @returns array of <a href="#/p5.Element">p5.Element</a>s containing any elements found.
|
|
2370
|
+
*/
|
|
2371
|
+
selectAll(selectors: string, container?: string | p5.Element | HTMLElement): p5.Element[];
|
|
2372
|
+
|
|
2314
2373
|
/**
|
|
2315
2374
|
* A shader function that performs smooth Hermite interpolation between `0.0`
|
|
2316
2375
|
* and `1.0`.
|
|
@@ -2383,65 +2442,6 @@ declare class p5 {
|
|
|
2383
2442
|
|
|
2384
2443
|
getCameraInputs(callback: Function): void;
|
|
2385
2444
|
|
|
2386
|
-
/**
|
|
2387
|
-
* Creates a light that shines from all directions.
|
|
2388
|
-
*
|
|
2389
|
-
* Ambient light does not come from one direction. Instead, 3D shapes are
|
|
2390
|
-
* lit evenly from all sides. Ambient lights are almost always used in
|
|
2391
|
-
* combination with other types of lights.
|
|
2392
|
-
*
|
|
2393
|
-
* There are three ways to call `ambientLight()` with optional parameters to
|
|
2394
|
-
* set the light’s color.
|
|
2395
|
-
*
|
|
2396
|
-
* The first way to call `ambientLight()` has two parameters, `gray` and
|
|
2397
|
-
* `alpha`. `alpha` is optional. Grayscale and alpha values between 0 and 255
|
|
2398
|
-
* can be passed to set the ambient light’s color, as in `ambientLight(50)` or
|
|
2399
|
-
* `ambientLight(50, 30)`.
|
|
2400
|
-
*
|
|
2401
|
-
* The second way to call `ambientLight()` has one parameter, color. A
|
|
2402
|
-
* <a href="#/p5.Color">p5.Color</a> object, an array of color values, or a
|
|
2403
|
-
* CSS color string, as in `ambientLight('magenta')`, can be passed to set the
|
|
2404
|
-
* ambient light’s color.
|
|
2405
|
-
*
|
|
2406
|
-
* The third way to call `ambientLight()` has four parameters, `v1`, `v2`,
|
|
2407
|
-
* `v3`, and `alpha`. `alpha` is optional. RGBA, HSBA, or HSLA values can be
|
|
2408
|
-
* passed to set the ambient light’s colors, as in `ambientLight(255, 0, 0)`
|
|
2409
|
-
* or `ambientLight(255, 0, 0, 30)`. Color values will be interpreted using
|
|
2410
|
-
* the current <a href="#/p5/colorMode">colorMode()</a>.
|
|
2411
|
-
* @param v1 red or hue value in the current
|
|
2412
|
-
* <a href="#/p5/colorMode">colorMode()</a>.
|
|
2413
|
-
* @param v2 green or saturation value in the current
|
|
2414
|
-
* <a href="#/p5/colorMode">colorMode()</a>.
|
|
2415
|
-
* @param v3 blue, brightness, or lightness value in the current
|
|
2416
|
-
* <a href="#/p5/colorMode">colorMode()</a>.
|
|
2417
|
-
* @param alpha alpha (transparency) value in the current
|
|
2418
|
-
* <a href="#/p5/colorMode">colorMode()</a>.
|
|
2419
|
-
*/
|
|
2420
|
-
ambientLight(v1: number, v2: number, v3: number, alpha?: number): void;
|
|
2421
|
-
ambientLight(gray: number, alpha?: number): void;
|
|
2422
|
-
ambientLight(value: string): void;
|
|
2423
|
-
ambientLight(values: number[]): void;
|
|
2424
|
-
ambientLight(color: p5.Color): void;
|
|
2425
|
-
|
|
2426
|
-
/**
|
|
2427
|
-
* Searches the page for all elements that matches the given
|
|
2428
|
-
* <a href="https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web/CSS_basics#different_types_of_selectors" target="_blank">CSS selector string</a>.
|
|
2429
|
-
*
|
|
2430
|
-
* The selector string can be an ID, class, tag name, or a combination.
|
|
2431
|
-
* `selectAll()` returns an array of <a href="#/p5.Element">p5.Element</a>
|
|
2432
|
-
* objects if it finds any matches and an empty array if none are found.
|
|
2433
|
-
*
|
|
2434
|
-
* The second parameter, `container`, is optional. It specifies a container to
|
|
2435
|
-
* search within. `container` can be CSS selector string, a
|
|
2436
|
-
* <a href="#/p5.Element">p5.Element</a> object, or an
|
|
2437
|
-
* <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement" target="_blank">HTMLElement</a> object.
|
|
2438
|
-
* @param selectors CSS selector string of element to search for.
|
|
2439
|
-
* @param container CSS selector string, <a href="#/p5.Element">p5.Element</a>, or
|
|
2440
|
-
* <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement" target="_blank">HTMLElement</a> to search within.
|
|
2441
|
-
* @returns array of <a href="#/p5.Element">p5.Element</a>s containing any elements found.
|
|
2442
|
-
*/
|
|
2443
|
-
selectAll(selectors: string, container?: string | p5.Element | HTMLElement): p5.Element[];
|
|
2444
|
-
|
|
2445
2445
|
/**
|
|
2446
2446
|
* Draws a Bézier curve.
|
|
2447
2447
|
*
|
|
@@ -4375,7 +4375,7 @@ declare class p5 {
|
|
|
4375
4375
|
* // Make a version of the shader with a hook overridden
|
|
4376
4376
|
* modifiedShader = myShader.modify(() => {
|
|
4377
4377
|
* // Create new uniforms and override the getColor hook
|
|
4378
|
-
* let t =
|
|
4378
|
+
* let t = millis() / 1000;
|
|
4379
4379
|
* getColor(() => {
|
|
4380
4380
|
* return [0, 0.5 + 0.5 * sin(t), 1, 1];
|
|
4381
4381
|
* });
|
|
@@ -4828,55 +4828,6 @@ declare class p5 {
|
|
|
4828
4828
|
*/
|
|
4829
4829
|
rotateX(angle: number): void;
|
|
4830
4830
|
|
|
4831
|
-
/**
|
|
4832
|
-
* A function that's called once when the sketch begins running.
|
|
4833
|
-
*
|
|
4834
|
-
* Declaring the function `setup()` sets a code block to run once
|
|
4835
|
-
* automatically when the sketch starts running. It's used to perform
|
|
4836
|
-
* setup tasks such as creating the canvas and initializing variables:
|
|
4837
|
-
*
|
|
4838
|
-
* `function setup() {
|
|
4839
|
-
* // Code to run once at the start of the sketch.
|
|
4840
|
-
* }`Code placed in `setup()` will run once before code placed in
|
|
4841
|
-
* <a href="#/p5/draw">draw()</a> begins looping.
|
|
4842
|
-
* If `setup()` is declared `async` (e.g. `async function setup()`),
|
|
4843
|
-
* execution pauses at each `await` until its promise resolves.
|
|
4844
|
-
* For example, `font = await loadFont(...)` waits for the font asset
|
|
4845
|
-
* to load because `loadFont()` function returns a promise, and the await
|
|
4846
|
-
* keyword means the program will wait for the promise to resolve.
|
|
4847
|
-
* This ensures that all assets are fully loaded before the sketch continues.
|
|
4848
|
-
*
|
|
4849
|
-
* loading assets.
|
|
4850
|
-
*
|
|
4851
|
-
* Note: `setup()` doesn’t have to be declared, but it’s common practice to do so.
|
|
4852
|
-
*/
|
|
4853
|
-
setup(): void;
|
|
4854
|
-
|
|
4855
|
-
/**
|
|
4856
|
-
* A function that's called repeatedly while the sketch runs.
|
|
4857
|
-
*
|
|
4858
|
-
* Declaring the function `draw()` sets a code block to run repeatedly
|
|
4859
|
-
* once the sketch starts. It’s used to create animations and respond to
|
|
4860
|
-
* user inputs:
|
|
4861
|
-
*
|
|
4862
|
-
* `function draw() {
|
|
4863
|
-
* // Code to run repeatedly.
|
|
4864
|
-
* }`This is often called the "draw loop" because p5.js calls the code in
|
|
4865
|
-
* `draw()` in a loop behind the scenes. By default, `draw()` tries to run
|
|
4866
|
-
* 60 times per second. The actual rate depends on many factors. The
|
|
4867
|
-
* drawing rate, called the "frame rate", can be controlled by calling
|
|
4868
|
-
* <a href="#/p5/frameRate">frameRate()</a>. The number of times `draw()`
|
|
4869
|
-
* has run is stored in the system variable
|
|
4870
|
-
* <a href="#/p5/frameCount">frameCount()</a>.
|
|
4871
|
-
*
|
|
4872
|
-
* Code placed within `draw()` begins looping after
|
|
4873
|
-
* <a href="#/p5/setup">setup()</a> runs. `draw()` will run until the user
|
|
4874
|
-
* closes the sketch. `draw()` can be stopped by calling the
|
|
4875
|
-
* <a href="#/p5/noLoop">noLoop()</a> function. `draw()` can be resumed by
|
|
4876
|
-
* calling the <a href="#/p5/loop">loop()</a> function.
|
|
4877
|
-
*/
|
|
4878
|
-
draw(): void;
|
|
4879
|
-
|
|
4880
4831
|
/**
|
|
4881
4832
|
* Re-maps a number from one range to another.
|
|
4882
4833
|
*
|
|
@@ -5297,23 +5248,72 @@ declare class p5 {
|
|
|
5297
5248
|
line(x1: number, y1: number, z1: number, x2: number, y2: number, z2: number): void;
|
|
5298
5249
|
|
|
5299
5250
|
/**
|
|
5300
|
-
*
|
|
5251
|
+
* A function that's called once when the sketch begins running.
|
|
5301
5252
|
*
|
|
5302
|
-
* `
|
|
5303
|
-
*
|
|
5304
|
-
*
|
|
5305
|
-
* <a href="#/p5/createVideo">createVideo()</a>, and
|
|
5306
|
-
* <a href="#/p5/createImg">createImg()</a>. These objects will remain
|
|
5307
|
-
* unchanged after calling `clear()` and can be redrawn.
|
|
5253
|
+
* Declaring the function `setup()` sets a code block to run once
|
|
5254
|
+
* automatically when the sketch starts running. It's used to perform
|
|
5255
|
+
* setup tasks such as creating the canvas and initializing variables:
|
|
5308
5256
|
*
|
|
5309
|
-
*
|
|
5310
|
-
*
|
|
5311
|
-
*
|
|
5312
|
-
*
|
|
5313
|
-
*
|
|
5314
|
-
*
|
|
5315
|
-
*
|
|
5316
|
-
*
|
|
5257
|
+
* `function setup() {
|
|
5258
|
+
* // Code to run once at the start of the sketch.
|
|
5259
|
+
* }`Code placed in `setup()` will run once before code placed in
|
|
5260
|
+
* <a href="#/p5/draw">draw()</a> begins looping.
|
|
5261
|
+
* If `setup()` is declared `async` (e.g. `async function setup()`),
|
|
5262
|
+
* execution pauses at each `await` until its promise resolves.
|
|
5263
|
+
* For example, `font = await loadFont(...)` waits for the font asset
|
|
5264
|
+
* to load because `loadFont()` function returns a promise, and the await
|
|
5265
|
+
* keyword means the program will wait for the promise to resolve.
|
|
5266
|
+
* This ensures that all assets are fully loaded before the sketch continues.
|
|
5267
|
+
*
|
|
5268
|
+
* loading assets.
|
|
5269
|
+
*
|
|
5270
|
+
* Note: `setup()` doesn’t have to be declared, but it’s common practice to do so.
|
|
5271
|
+
*/
|
|
5272
|
+
setup(): void;
|
|
5273
|
+
|
|
5274
|
+
/**
|
|
5275
|
+
* A function that's called repeatedly while the sketch runs.
|
|
5276
|
+
*
|
|
5277
|
+
* Declaring the function `draw()` sets a code block to run repeatedly
|
|
5278
|
+
* once the sketch starts. It’s used to create animations and respond to
|
|
5279
|
+
* user inputs:
|
|
5280
|
+
*
|
|
5281
|
+
* `function draw() {
|
|
5282
|
+
* // Code to run repeatedly.
|
|
5283
|
+
* }`This is often called the "draw loop" because p5.js calls the code in
|
|
5284
|
+
* `draw()` in a loop behind the scenes. By default, `draw()` tries to run
|
|
5285
|
+
* 60 times per second. The actual rate depends on many factors. The
|
|
5286
|
+
* drawing rate, called the "frame rate", can be controlled by calling
|
|
5287
|
+
* <a href="#/p5/frameRate">frameRate()</a>. The number of times `draw()`
|
|
5288
|
+
* has run is stored in the system variable
|
|
5289
|
+
* <a href="#/p5/frameCount">frameCount()</a>.
|
|
5290
|
+
*
|
|
5291
|
+
* Code placed within `draw()` begins looping after
|
|
5292
|
+
* <a href="#/p5/setup">setup()</a> runs. `draw()` will run until the user
|
|
5293
|
+
* closes the sketch. `draw()` can be stopped by calling the
|
|
5294
|
+
* <a href="#/p5/noLoop">noLoop()</a> function. `draw()` can be resumed by
|
|
5295
|
+
* calling the <a href="#/p5/loop">loop()</a> function.
|
|
5296
|
+
*/
|
|
5297
|
+
draw(): void;
|
|
5298
|
+
|
|
5299
|
+
/**
|
|
5300
|
+
* Clears the pixels on the canvas.
|
|
5301
|
+
*
|
|
5302
|
+
* `clear()` makes every pixel 100% transparent. Calling `clear()` doesn't
|
|
5303
|
+
* clear objects created by `createX()` functions such as
|
|
5304
|
+
* <a href="#/p5/createGraphics">createGraphics()</a>,
|
|
5305
|
+
* <a href="#/p5/createVideo">createVideo()</a>, and
|
|
5306
|
+
* <a href="#/p5/createImg">createImg()</a>. These objects will remain
|
|
5307
|
+
* unchanged after calling `clear()` and can be redrawn.
|
|
5308
|
+
*
|
|
5309
|
+
* In WebGL mode, this function can clear the screen to a specific color. It
|
|
5310
|
+
* interprets four numeric parameters as normalized RGBA color values. It also
|
|
5311
|
+
* clears the depth buffer. If you are not using the WebGL renderer, these
|
|
5312
|
+
* parameters will have no effect.
|
|
5313
|
+
* @param r normalized red value.
|
|
5314
|
+
* @param g normalized green value.
|
|
5315
|
+
* @param b normalized blue value.
|
|
5316
|
+
* @param a normalized alpha value.
|
|
5317
5317
|
*/
|
|
5318
5318
|
clear(r?: number, g?: number, b?: number, a?: number): void;
|
|
5319
5319
|
clear(): void;
|
|
@@ -5612,17 +5612,6 @@ declare class p5 {
|
|
|
5612
5612
|
*/
|
|
5613
5613
|
shuffle<T>(array: T[], modify?: boolean): T[];
|
|
5614
5614
|
|
|
5615
|
-
/**
|
|
5616
|
-
* This method is suitable for fetching files up to size of 64MB.
|
|
5617
|
-
* @param file name of the file or URL to load
|
|
5618
|
-
* @param callback function to be executed after <a href="#/p5/loadBytes">loadBytes()</a>
|
|
5619
|
-
* completes
|
|
5620
|
-
* @param errorCallback function to be executed if there
|
|
5621
|
-
* is an error
|
|
5622
|
-
* @returns a Uint8Array containing the loaded buffer
|
|
5623
|
-
*/
|
|
5624
|
-
loadBytes(file: string | Request, callback?: Function, errorCallback?: Function): Promise<Uint8Array>;
|
|
5625
|
-
|
|
5626
5615
|
/**
|
|
5627
5616
|
* Turns off <a href="#/p5/debugMode">debugMode()</a> in a 3D sketch.
|
|
5628
5617
|
*/
|
|
@@ -5783,7 +5772,7 @@ declare class p5 {
|
|
|
5783
5772
|
* filterColor.texCoord.x // x coordinate, from 0 to 1
|
|
5784
5773
|
* ));
|
|
5785
5774
|
* filterColor.end();
|
|
5786
|
-
* }`You can also animate your filters over time
|
|
5775
|
+
* }`You can also animate your filters over time using the `millis()` function.
|
|
5787
5776
|
*
|
|
5788
5777
|
* `let myFilter;
|
|
5789
5778
|
* function setup() {
|
|
@@ -5793,7 +5782,7 @@ declare class p5 {
|
|
|
5793
5782
|
* }
|
|
5794
5783
|
*
|
|
5795
5784
|
* function gradient() {
|
|
5796
|
-
* let time =
|
|
5785
|
+
* let time = millis();
|
|
5797
5786
|
* filterColor.begin();
|
|
5798
5787
|
* filterColor.set(mix(
|
|
5799
5788
|
* [1, 0, 0, 1], // Red
|
|
@@ -5804,9 +5793,8 @@ declare class p5 {
|
|
|
5804
5793
|
* }
|
|
5805
5794
|
*
|
|
5806
5795
|
* function draw() {
|
|
5807
|
-
* myFilter.setUniform('time', millis());
|
|
5808
5796
|
* filter(myFilter);
|
|
5809
|
-
* }`We can use the `noise()` function built into strands to generate a color for each pixel. (Again no need here for underlying content for the filter to operate on.) Again we'll animate by
|
|
5797
|
+
* }`We can use the `noise()` function built into strands to generate a color for each pixel. (Again no need here for underlying content for the filter to operate on.) Again we'll animate by using the millis() function to get an up-to-date time value.
|
|
5810
5798
|
*
|
|
5811
5799
|
* `let myFilter;
|
|
5812
5800
|
*
|
|
@@ -5817,7 +5805,7 @@ declare class p5 {
|
|
|
5817
5805
|
* }
|
|
5818
5806
|
*
|
|
5819
5807
|
* function noiseShaderCallback() {
|
|
5820
|
-
* let time =
|
|
5808
|
+
* let time = millis();
|
|
5821
5809
|
* filterColor.begin();
|
|
5822
5810
|
* let coord = filterColor.texCoord;
|
|
5823
5811
|
*
|
|
@@ -5834,7 +5822,6 @@ declare class p5 {
|
|
|
5834
5822
|
* }
|
|
5835
5823
|
*
|
|
5836
5824
|
* function draw() {
|
|
5837
|
-
* myFilter.setUniform("time", millis());
|
|
5838
5825
|
* filter(myFilter);
|
|
5839
5826
|
* }`Like the `modify()` method on shaders,
|
|
5840
5827
|
* advanced users can also fill in `filterColor` using <a href="https://developer.mozilla.org/en-US/docs/Games/Techniques/3D_on_the_web/GLSL_Shaders" target="_blank">GLSL</a>
|
|
@@ -5852,6 +5839,17 @@ declare class p5 {
|
|
|
5852
5839
|
buildFilterShader(callback: Function, scope?: object): p5.Shader;
|
|
5853
5840
|
buildFilterShader(hooks: object, scope?: object): p5.Shader;
|
|
5854
5841
|
|
|
5842
|
+
/**
|
|
5843
|
+
* This method is suitable for fetching files up to size of 64MB.
|
|
5844
|
+
* @param file name of the file or URL to load
|
|
5845
|
+
* @param callback function to be executed after <a href="#/p5/loadBytes">loadBytes()</a>
|
|
5846
|
+
* completes
|
|
5847
|
+
* @param errorCallback function to be executed if there
|
|
5848
|
+
* is an error
|
|
5849
|
+
* @returns a Uint8Array containing the loaded buffer
|
|
5850
|
+
*/
|
|
5851
|
+
loadBytes(file: string | Request, callback?: Function, errorCallback?: Function): Promise<Uint8Array>;
|
|
5852
|
+
|
|
5855
5853
|
/**
|
|
5856
5854
|
* Creates a slider `<input></input>` element.
|
|
5857
5855
|
*
|
|
@@ -5971,22 +5969,6 @@ declare class p5 {
|
|
|
5971
5969
|
*/
|
|
5972
5970
|
rotateZ(angle: number): void;
|
|
5973
5971
|
|
|
5974
|
-
/**
|
|
5975
|
-
* Loads a file at the given path as a Blob, then returns the resulting data or
|
|
5976
|
-
* passes it to a success callback function, if provided. On load, this function
|
|
5977
|
-
* returns a `Promise` that resolves to a Blob containing the file data.
|
|
5978
|
-
* @param path The path or Request object pointing to the file
|
|
5979
|
-
* you want to load.
|
|
5980
|
-
* @param successCallback Optional. A function to be called if the
|
|
5981
|
-
* file successfully loads, receiving the
|
|
5982
|
-
* resulting Blob as its only argument.
|
|
5983
|
-
* @param errorCallback Optional. A function to be called if an
|
|
5984
|
-
* error occurs during loading; receives the
|
|
5985
|
-
* error object as its only argument.
|
|
5986
|
-
* @returns A promise that resolves with the loaded Blob.
|
|
5987
|
-
*/
|
|
5988
|
-
loadBlob(path: string | Request, successCallback?: Function, errorCallback?: Function): Promise<Blob>;
|
|
5989
|
-
|
|
5990
5972
|
/**
|
|
5991
5973
|
* Calculates exponential expressions such as <var>2<sup>3</sup></var>.
|
|
5992
5974
|
*
|
|
@@ -6015,6 +5997,22 @@ declare class p5 {
|
|
|
6015
5997
|
*/
|
|
6016
5998
|
fullscreen(val?: boolean): boolean;
|
|
6017
5999
|
|
|
6000
|
+
/**
|
|
6001
|
+
* Loads a file at the given path as a Blob, then returns the resulting data or
|
|
6002
|
+
* passes it to a success callback function, if provided. On load, this function
|
|
6003
|
+
* returns a `Promise` that resolves to a Blob containing the file data.
|
|
6004
|
+
* @param path The path or Request object pointing to the file
|
|
6005
|
+
* you want to load.
|
|
6006
|
+
* @param successCallback Optional. A function to be called if the
|
|
6007
|
+
* file successfully loads, receiving the
|
|
6008
|
+
* resulting Blob as its only argument.
|
|
6009
|
+
* @param errorCallback Optional. A function to be called if an
|
|
6010
|
+
* error occurs during loading; receives the
|
|
6011
|
+
* error object as its only argument.
|
|
6012
|
+
* @returns A promise that resolves with the loaded Blob.
|
|
6013
|
+
*/
|
|
6014
|
+
loadBlob(path: string | Request, successCallback?: Function, errorCallback?: Function): Promise<Blob>;
|
|
6015
|
+
|
|
6018
6016
|
/**
|
|
6019
6017
|
* Creates a light that shines from a point in all directions.
|
|
6020
6018
|
*
|
|
@@ -6292,26 +6290,20 @@ declare class p5 {
|
|
|
6292
6290
|
splinePoint(a: number, b: number, c: number, d: number, t: number): number;
|
|
6293
6291
|
|
|
6294
6292
|
/**
|
|
6295
|
-
*
|
|
6296
|
-
*
|
|
6297
|
-
*
|
|
6298
|
-
*
|
|
6299
|
-
*
|
|
6300
|
-
*
|
|
6301
|
-
*
|
|
6302
|
-
*
|
|
6303
|
-
*
|
|
6304
|
-
* <a href="#/p5
|
|
6305
|
-
* as
|
|
6306
|
-
* @param
|
|
6307
|
-
* there is an error, response is passed
|
|
6308
|
-
* in as first argument
|
|
6309
|
-
* @returns A promise that resolves with the data when the operation
|
|
6310
|
-
* completes successfully or rejects with the error after
|
|
6311
|
-
* one occurs.
|
|
6293
|
+
* Creates an ambient light from an image.
|
|
6294
|
+
*
|
|
6295
|
+
* `imageLight()` simulates a light shining from all directions. The effect is
|
|
6296
|
+
* like placing the sketch at the center of a giant sphere that uses the image
|
|
6297
|
+
* as its texture. The image's diffuse light will be affected by
|
|
6298
|
+
* <a href="#/p5/fill">fill()</a> and the specular reflections will be
|
|
6299
|
+
* affected by <a href="#/p5/specularMaterial">specularMaterial()</a> and
|
|
6300
|
+
* <a href="#/p5/shininess">shininess()</a>.
|
|
6301
|
+
*
|
|
6302
|
+
* The parameter, `img`, is the <a href="#/p5.Image">p5.Image</a> object to
|
|
6303
|
+
* use as the light source.
|
|
6304
|
+
* @param img image to use as the light source.
|
|
6312
6305
|
*/
|
|
6313
|
-
|
|
6314
|
-
httpGet(path: string | Request, callback: Function, errorCallback?: Function): Promise<any>;
|
|
6306
|
+
imageLight(img: p5.Image): void;
|
|
6315
6307
|
|
|
6316
6308
|
/**
|
|
6317
6309
|
* Sets the pixel density or returns the current density.
|
|
@@ -6334,20 +6326,26 @@ declare class p5 {
|
|
|
6334
6326
|
pixelDensity(): number;
|
|
6335
6327
|
|
|
6336
6328
|
/**
|
|
6337
|
-
*
|
|
6338
|
-
*
|
|
6339
|
-
*
|
|
6340
|
-
*
|
|
6341
|
-
*
|
|
6342
|
-
*
|
|
6343
|
-
*
|
|
6344
|
-
*
|
|
6345
|
-
*
|
|
6346
|
-
*
|
|
6347
|
-
*
|
|
6348
|
-
* @param
|
|
6329
|
+
* Method for executing an HTTP GET request. If data type is not specified,
|
|
6330
|
+
* it will default to `'text'`. This is equivalent to
|
|
6331
|
+
* calling <code>httpDo(path, 'GET')</code>. The 'binary' datatype will return
|
|
6332
|
+
* a Blob object, and the 'arrayBuffer' datatype will return an ArrayBuffer
|
|
6333
|
+
* which can be used to initialize typed arrays (such as Uint8Array).
|
|
6334
|
+
* @param path name of the file or url to load
|
|
6335
|
+
* @param datatype "json", "jsonp", "binary", "arrayBuffer",
|
|
6336
|
+
* "xml", or "text"
|
|
6337
|
+
* @param callback function to be executed after
|
|
6338
|
+
* <a href="#/p5/httpGet">httpGet()</a> completes, data is passed in
|
|
6339
|
+
* as first argument
|
|
6340
|
+
* @param errorCallback function to be executed if
|
|
6341
|
+
* there is an error, response is passed
|
|
6342
|
+
* in as first argument
|
|
6343
|
+
* @returns A promise that resolves with the data when the operation
|
|
6344
|
+
* completes successfully or rejects with the error after
|
|
6345
|
+
* one occurs.
|
|
6349
6346
|
*/
|
|
6350
|
-
|
|
6347
|
+
httpGet(path: string | Request, datatype?: string, callback?: Function, errorCallback?: Function): Promise<any>;
|
|
6348
|
+
httpGet(path: string | Request, callback: Function, errorCallback?: Function): Promise<any>;
|
|
6351
6349
|
|
|
6352
6350
|
/**
|
|
6353
6351
|
* Updates the canvas with the RGBA values in the
|
|
@@ -6512,28 +6510,6 @@ declare class p5 {
|
|
|
6512
6510
|
scale(s: number | p5.Vector | number[], y?: number, z?: number): void;
|
|
6513
6511
|
scale(scales: p5.Vector | number[]): void;
|
|
6514
6512
|
|
|
6515
|
-
/**
|
|
6516
|
-
* Method for executing an HTTP POST request. If data type is not specified,
|
|
6517
|
-
* it will default to `'text'`. This is equivalent to
|
|
6518
|
-
* calling <code>httpDo(path, 'POST')</code>.
|
|
6519
|
-
* @param path name of the file or url to load
|
|
6520
|
-
* @param data param data passed sent with request
|
|
6521
|
-
* @param datatype "json", "jsonp", "xml", or "text".
|
|
6522
|
-
* If omitted, <a href="#/p5/httpPost">httpPost()</a> will guess.
|
|
6523
|
-
* @param callback function to be executed after
|
|
6524
|
-
* <a href="#/p5/httpPost">httpPost()</a> completes, data is passed in
|
|
6525
|
-
* as first argument
|
|
6526
|
-
* @param errorCallback function to be executed if
|
|
6527
|
-
* there is an error, response is passed
|
|
6528
|
-
* in as first argument
|
|
6529
|
-
* @returns A promise that resolves with the data when the operation
|
|
6530
|
-
* completes successfully or rejects with the error after
|
|
6531
|
-
* one occurs.
|
|
6532
|
-
*/
|
|
6533
|
-
httpPost(path: string | Request, data?: object | boolean, datatype?: string, callback?: Function, errorCallback?: Function): Promise<any>;
|
|
6534
|
-
httpPost(path: string | Request, data: object | boolean, callback?: Function, errorCallback?: Function): Promise<any>;
|
|
6535
|
-
httpPost(path: string | Request, callback?: Function, errorCallback?: Function): Promise<any>;
|
|
6536
|
-
|
|
6537
6513
|
/**
|
|
6538
6514
|
* Converts a `String` with a hexadecimal value to a `Number`.
|
|
6539
6515
|
*
|
|
@@ -6593,6 +6569,28 @@ declare class p5 {
|
|
|
6593
6569
|
*/
|
|
6594
6570
|
sqrt(n: number): number;
|
|
6595
6571
|
|
|
6572
|
+
/**
|
|
6573
|
+
* Method for executing an HTTP POST request. If data type is not specified,
|
|
6574
|
+
* it will default to `'text'`. This is equivalent to
|
|
6575
|
+
* calling <code>httpDo(path, 'POST')</code>.
|
|
6576
|
+
* @param path name of the file or url to load
|
|
6577
|
+
* @param data param data passed sent with request
|
|
6578
|
+
* @param datatype "json", "jsonp", "xml", or "text".
|
|
6579
|
+
* If omitted, <a href="#/p5/httpPost">httpPost()</a> will guess.
|
|
6580
|
+
* @param callback function to be executed after
|
|
6581
|
+
* <a href="#/p5/httpPost">httpPost()</a> completes, data is passed in
|
|
6582
|
+
* as first argument
|
|
6583
|
+
* @param errorCallback function to be executed if
|
|
6584
|
+
* there is an error, response is passed
|
|
6585
|
+
* in as first argument
|
|
6586
|
+
* @returns A promise that resolves with the data when the operation
|
|
6587
|
+
* completes successfully or rejects with the error after
|
|
6588
|
+
* one occurs.
|
|
6589
|
+
*/
|
|
6590
|
+
httpPost(path: string | Request, data?: object | boolean, datatype?: string, callback?: Function, errorCallback?: Function): Promise<any>;
|
|
6591
|
+
httpPost(path: string | Request, data: object | boolean, callback?: Function, errorCallback?: Function): Promise<any>;
|
|
6592
|
+
httpPost(path: string | Request, callback?: Function, errorCallback?: Function): Promise<any>;
|
|
6593
|
+
|
|
6596
6594
|
/**
|
|
6597
6595
|
* Draws a cylinder.
|
|
6598
6596
|
*
|
|
@@ -6838,18 +6836,6 @@ declare class p5 {
|
|
|
6838
6836
|
image(img: p5.Image | p5.Element | p5.Texture | p5.Framebuffer | p5.FramebufferTexture | p5.Renderer | p5.Graphics, x: number, y: number, width?: number, height?: number): void;
|
|
6839
6837
|
image(img: p5.Image | p5.Element | p5.Texture | p5.Framebuffer | p5.FramebufferTexture, dx: number, dy: number, dWidth: number, dHeight: number, sx: number, sy: number, sWidth?: number, sHeight?: number, fit?: typeof p5.CONTAIN | typeof p5.COVER, xAlign?: typeof p5.LEFT | typeof p5.RIGHT | typeof p5.CENTER, yAlign?: typeof p5.TOP | typeof p5.BOTTOM | typeof p5.CENTER): void;
|
|
6840
6838
|
|
|
6841
|
-
/**
|
|
6842
|
-
* Returns the current
|
|
6843
|
-
* <a href="https://developer.mozilla.org/en-US/docs/Learn/Common_questions/Web_mechanics/What_is_a_URL#parameters" target="_blank">URL parameters</a>
|
|
6844
|
-
* in an `Object`.
|
|
6845
|
-
*
|
|
6846
|
-
* For example, calling `getURLParams()` in a sketch hosted at the URL
|
|
6847
|
-
* `https://p5js.org?year=2014&month=May&day=15` returns
|
|
6848
|
-
* `{ year: 2014, month: 'May', day: 15 }`.
|
|
6849
|
-
* @returns URL params
|
|
6850
|
-
*/
|
|
6851
|
-
getURLParams(): object;
|
|
6852
|
-
|
|
6853
6839
|
/**
|
|
6854
6840
|
* Changes the way color values are interpreted.
|
|
6855
6841
|
*
|
|
@@ -6923,6 +6909,18 @@ declare class p5 {
|
|
|
6923
6909
|
colorMode(mode: typeof p5.RGB | typeof p5.HSB | typeof p5.HSL | typeof p5.RGBHDR | typeof p5.HWB | typeof p5.LAB | typeof p5.LCH | typeof p5.OKLAB | typeof p5.OKLCH, max1: number, max2: number, max3: number, maxA?: number): typeof p5.RGB | typeof p5.HSB | typeof p5.HSL | typeof p5.RGBHDR | typeof p5.HWB | typeof p5.LAB | typeof p5.LCH | typeof p5.OKLAB | typeof p5.OKLCH;
|
|
6924
6910
|
colorMode(): typeof p5.RGB | typeof p5.HSB | typeof p5.HSL | typeof p5.RGBHDR | typeof p5.HWB | typeof p5.LAB | typeof p5.LCH | typeof p5.OKLAB | typeof p5.OKLCH;
|
|
6925
6911
|
|
|
6912
|
+
/**
|
|
6913
|
+
* Returns the current
|
|
6914
|
+
* <a href="https://developer.mozilla.org/en-US/docs/Learn/Common_questions/Web_mechanics/What_is_a_URL#parameters" target="_blank">URL parameters</a>
|
|
6915
|
+
* in an `Object`.
|
|
6916
|
+
*
|
|
6917
|
+
* For example, calling `getURLParams()` in a sketch hosted at the URL
|
|
6918
|
+
* `https://p5js.org?year=2014&month=May&day=15` returns
|
|
6919
|
+
* `{ year: 2014, month: 'May', day: 15 }`.
|
|
6920
|
+
* @returns URL params
|
|
6921
|
+
*/
|
|
6922
|
+
getURLParams(): object;
|
|
6923
|
+
|
|
6926
6924
|
/**
|
|
6927
6925
|
* Shears the x-axis so that shapes appear skewed.
|
|
6928
6926
|
*
|
|
@@ -6970,104 +6968,6 @@ declare class p5 {
|
|
|
6970
6968
|
*/
|
|
6971
6969
|
lightFalloff(constant: number, linear: number, quadratic: number): void;
|
|
6972
6970
|
|
|
6973
|
-
/**
|
|
6974
|
-
* A function that's called when the mouse moves.
|
|
6975
|
-
*
|
|
6976
|
-
* Declaring the function `mouseMoved()` sets a code block to run
|
|
6977
|
-
* automatically when the user moves the mouse without clicking any mouse
|
|
6978
|
-
* buttons:
|
|
6979
|
-
*
|
|
6980
|
-
* `function mouseMoved() {
|
|
6981
|
-
* // Code to run.
|
|
6982
|
-
* }`The mouse system variables, such as <a href="#/p5/mouseX">mouseX</a> and
|
|
6983
|
-
* <a href="#/p5/mouseY">mouseY</a>, will be updated with their most recent
|
|
6984
|
-
* value when `mouseMoved()` is called by p5.js:
|
|
6985
|
-
*
|
|
6986
|
-
* `function mouseMoved() {
|
|
6987
|
-
* if (mouseX < 50) {
|
|
6988
|
-
* // Code to run if the mouse is on the left.
|
|
6989
|
-
* }
|
|
6990
|
-
*
|
|
6991
|
-
* if (mouseY > 50) {
|
|
6992
|
-
* // Code to run if the mouse is near the bottom.
|
|
6993
|
-
* }
|
|
6994
|
-
* }`The parameter, `event`, is optional. `mouseMoved()` is always passed a
|
|
6995
|
-
* <a href="https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent" target="_blank">MouseEvent</a>
|
|
6996
|
-
* object with properties that describe the mouse move event:
|
|
6997
|
-
*
|
|
6998
|
-
* `function mouseMoved(event) {
|
|
6999
|
-
* // Code to run that uses the event.
|
|
7000
|
-
* console.log(event);
|
|
7001
|
-
* }`Browsers may have default behaviors attached to various mouse events. For
|
|
7002
|
-
* example, some browsers highlight text when the user moves the mouse while
|
|
7003
|
-
* pressing a mouse button. To prevent any default behavior for this event,
|
|
7004
|
-
* add `return false;` to the end of the function.
|
|
7005
|
-
* @param event optional `MouseEvent` argument.
|
|
7006
|
-
*/
|
|
7007
|
-
mouseMoved(event?: MouseEvent): void;
|
|
7008
|
-
|
|
7009
|
-
/**
|
|
7010
|
-
* A function that's called when the mouse moves while a button is pressed.
|
|
7011
|
-
*
|
|
7012
|
-
* Declaring the function `mouseDragged()` sets a code block to run
|
|
7013
|
-
* automatically when the user clicks and drags the mouse:
|
|
7014
|
-
*
|
|
7015
|
-
* `function mouseDragged() {
|
|
7016
|
-
* // Code to run.
|
|
7017
|
-
* }`The mouse system variables, such as <a href="#/p5/mouseX">mouseX</a> and
|
|
7018
|
-
* <a href="#/p5/mouseY">mouseY</a>, will be updated with their most recent
|
|
7019
|
-
* value when `mouseDragged()` is called by p5.js:
|
|
7020
|
-
*
|
|
7021
|
-
* `function mouseDragged() {
|
|
7022
|
-
* if (mouseX < 50) {
|
|
7023
|
-
* // Code to run if the mouse is on the left.
|
|
7024
|
-
* }
|
|
7025
|
-
*
|
|
7026
|
-
* if (mouseY > 50) {
|
|
7027
|
-
* // Code to run if the mouse is near the bottom.
|
|
7028
|
-
* }
|
|
7029
|
-
* }`The parameter, `event`, is optional. `mouseDragged()` is always passed a
|
|
7030
|
-
* <a href="https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent" target="_blank">MouseEvent</a>
|
|
7031
|
-
* object with properties that describe the mouse drag event:
|
|
7032
|
-
*
|
|
7033
|
-
* `function mouseDragged(event) {
|
|
7034
|
-
* // Code to run that uses the event.
|
|
7035
|
-
* console.log(event);
|
|
7036
|
-
* }`On touchscreen devices, `mouseDragged()` will run when a user moves a touch
|
|
7037
|
-
* point.
|
|
7038
|
-
*
|
|
7039
|
-
* Browsers may have default behaviors attached to various mouse events. For
|
|
7040
|
-
* example, some browsers highlight text when the user moves the mouse while
|
|
7041
|
-
* pressing a mouse button. To prevent any default behavior for this event,
|
|
7042
|
-
* add `return false;` to the end of the function.
|
|
7043
|
-
* @param event optional `MouseEvent` argument.
|
|
7044
|
-
*/
|
|
7045
|
-
mouseDragged(event?: MouseEvent): void;
|
|
7046
|
-
|
|
7047
|
-
/**
|
|
7048
|
-
* Returns `true` if the key it’s checking is pressed and `false` if not.
|
|
7049
|
-
*
|
|
7050
|
-
* `keyIsDown()` is helpful when checking for multiple different key presses.
|
|
7051
|
-
* For example, `keyIsDown()` can be used to check if both `LEFT_ARROW` and
|
|
7052
|
-
* `UP_ARROW` are pressed:
|
|
7053
|
-
*
|
|
7054
|
-
* `if (keyIsDown(LEFT_ARROW) && keyIsDown(UP_ARROW)) {
|
|
7055
|
-
* // Move diagonally.
|
|
7056
|
-
* }``keyIsDown()` can check for key presses using strings based on
|
|
7057
|
-
* <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key" target="_blank">KeyboardEvent.key</a>
|
|
7058
|
-
* or <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code" target="_blank">KeyboardEvent.code</a> values,
|
|
7059
|
-
* such as `keyIsDown('x')` or `keyIsDown('ArrowLeft')`.
|
|
7060
|
-
*
|
|
7061
|
-
* Note: In p5.js 2.0 and newer, numeric keycodes (such as 88 for 'X') are no longer supported.
|
|
7062
|
-
* This is a breaking change from previous versions.
|
|
7063
|
-
*
|
|
7064
|
-
* You can still use the p5 constants like `LEFT_ARROW` which now map to string values
|
|
7065
|
-
* internally rather than numeric codes.
|
|
7066
|
-
* @param code key to check.
|
|
7067
|
-
* @returns whether the key is down or not.
|
|
7068
|
-
*/
|
|
7069
|
-
keyIsDown(code: number | string): boolean;
|
|
7070
|
-
|
|
7071
6971
|
/**
|
|
7072
6972
|
* Sets the <a href="#/p5.Shader">p5.Shader</a> object to apply while drawing.
|
|
7073
6973
|
*
|
|
@@ -7107,7 +7007,7 @@ declare class p5 {
|
|
|
7107
7007
|
* }
|
|
7108
7008
|
*
|
|
7109
7009
|
* function material() {
|
|
7110
|
-
* let time =
|
|
7010
|
+
* let time = millis() / 1000;
|
|
7111
7011
|
* finalColor.begin();
|
|
7112
7012
|
* let r = 0.2 + 0.5 * abs(sin(time + 0));
|
|
7113
7013
|
* let g = 0.2 + 0.5 * abs(sin(time + 1));
|
|
@@ -7118,7 +7018,6 @@ declare class p5 {
|
|
|
7118
7018
|
*
|
|
7119
7019
|
* function draw() {
|
|
7120
7020
|
* background(245, 245, 220);
|
|
7121
|
-
* myShader.setUniform('time', millis() / 1000);
|
|
7122
7021
|
* shader(myShader);
|
|
7123
7022
|
*
|
|
7124
7023
|
* rectMode(CENTER);
|
|
@@ -7232,21 +7131,102 @@ declare class p5 {
|
|
|
7232
7131
|
shader(s: p5.Shader): void;
|
|
7233
7132
|
|
|
7234
7133
|
/**
|
|
7235
|
-
*
|
|
7134
|
+
* A function that's called when the mouse moves.
|
|
7236
7135
|
*
|
|
7237
|
-
*
|
|
7238
|
-
*
|
|
7239
|
-
*
|
|
7240
|
-
* <a href="#/p5/buildGeometry">buildGeometry()</a>, or
|
|
7241
|
-
* <a href="#/p5/beginGeometry">beginGeometry()</a> and
|
|
7242
|
-
* <a href="#/p5/endGeometry">endGeometry()</a>. They can also be loaded from
|
|
7243
|
-
* a file with <a href="#/p5/loadGeometry">loadGeometry()</a>.
|
|
7136
|
+
* Declaring the function `mouseMoved()` sets a code block to run
|
|
7137
|
+
* automatically when the user moves the mouse without clicking any mouse
|
|
7138
|
+
* buttons:
|
|
7244
7139
|
*
|
|
7245
|
-
*
|
|
7246
|
-
*
|
|
7247
|
-
*
|
|
7140
|
+
* `function mouseMoved() {
|
|
7141
|
+
* // Code to run.
|
|
7142
|
+
* }`The mouse system variables, such as <a href="#/p5/mouseX">mouseX</a> and
|
|
7143
|
+
* <a href="#/p5/mouseY">mouseY</a>, will be updated with their most recent
|
|
7144
|
+
* value when `mouseMoved()` is called by p5.js:
|
|
7145
|
+
*
|
|
7146
|
+
* `function mouseMoved() {
|
|
7147
|
+
* if (mouseX < 50) {
|
|
7148
|
+
* // Code to run if the mouse is on the left.
|
|
7149
|
+
* }
|
|
7150
|
+
*
|
|
7151
|
+
* if (mouseY > 50) {
|
|
7152
|
+
* // Code to run if the mouse is near the bottom.
|
|
7153
|
+
* }
|
|
7154
|
+
* }`The parameter, `event`, is optional. `mouseMoved()` is always passed a
|
|
7155
|
+
* <a href="https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent" target="_blank">MouseEvent</a>
|
|
7156
|
+
* object with properties that describe the mouse move event:
|
|
7157
|
+
*
|
|
7158
|
+
* `function mouseMoved(event) {
|
|
7159
|
+
* // Code to run that uses the event.
|
|
7160
|
+
* console.log(event);
|
|
7161
|
+
* }`Browsers may have default behaviors attached to various mouse events. For
|
|
7162
|
+
* example, some browsers highlight text when the user moves the mouse while
|
|
7163
|
+
* pressing a mouse button. To prevent any default behavior for this event,
|
|
7164
|
+
* add `return false;` to the end of the function.
|
|
7165
|
+
* @param event optional `MouseEvent` argument.
|
|
7248
7166
|
*/
|
|
7249
|
-
|
|
7167
|
+
mouseMoved(event?: MouseEvent): void;
|
|
7168
|
+
|
|
7169
|
+
/**
|
|
7170
|
+
* A function that's called when the mouse moves while a button is pressed.
|
|
7171
|
+
*
|
|
7172
|
+
* Declaring the function `mouseDragged()` sets a code block to run
|
|
7173
|
+
* automatically when the user clicks and drags the mouse:
|
|
7174
|
+
*
|
|
7175
|
+
* `function mouseDragged() {
|
|
7176
|
+
* // Code to run.
|
|
7177
|
+
* }`The mouse system variables, such as <a href="#/p5/mouseX">mouseX</a> and
|
|
7178
|
+
* <a href="#/p5/mouseY">mouseY</a>, will be updated with their most recent
|
|
7179
|
+
* value when `mouseDragged()` is called by p5.js:
|
|
7180
|
+
*
|
|
7181
|
+
* `function mouseDragged() {
|
|
7182
|
+
* if (mouseX < 50) {
|
|
7183
|
+
* // Code to run if the mouse is on the left.
|
|
7184
|
+
* }
|
|
7185
|
+
*
|
|
7186
|
+
* if (mouseY > 50) {
|
|
7187
|
+
* // Code to run if the mouse is near the bottom.
|
|
7188
|
+
* }
|
|
7189
|
+
* }`The parameter, `event`, is optional. `mouseDragged()` is always passed a
|
|
7190
|
+
* <a href="https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent" target="_blank">MouseEvent</a>
|
|
7191
|
+
* object with properties that describe the mouse drag event:
|
|
7192
|
+
*
|
|
7193
|
+
* `function mouseDragged(event) {
|
|
7194
|
+
* // Code to run that uses the event.
|
|
7195
|
+
* console.log(event);
|
|
7196
|
+
* }`On touchscreen devices, `mouseDragged()` will run when a user moves a touch
|
|
7197
|
+
* point.
|
|
7198
|
+
*
|
|
7199
|
+
* Browsers may have default behaviors attached to various mouse events. For
|
|
7200
|
+
* example, some browsers highlight text when the user moves the mouse while
|
|
7201
|
+
* pressing a mouse button. To prevent any default behavior for this event,
|
|
7202
|
+
* add `return false;` to the end of the function.
|
|
7203
|
+
* @param event optional `MouseEvent` argument.
|
|
7204
|
+
*/
|
|
7205
|
+
mouseDragged(event?: MouseEvent): void;
|
|
7206
|
+
|
|
7207
|
+
/**
|
|
7208
|
+
* Returns `true` if the key it’s checking is pressed and `false` if not.
|
|
7209
|
+
*
|
|
7210
|
+
* `keyIsDown()` is helpful when checking for multiple different key presses.
|
|
7211
|
+
* For example, `keyIsDown()` can be used to check if both `LEFT_ARROW` and
|
|
7212
|
+
* `UP_ARROW` are pressed:
|
|
7213
|
+
*
|
|
7214
|
+
* `if (keyIsDown(LEFT_ARROW) && keyIsDown(UP_ARROW)) {
|
|
7215
|
+
* // Move diagonally.
|
|
7216
|
+
* }``keyIsDown()` can check for key presses using strings based on
|
|
7217
|
+
* <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key" target="_blank">KeyboardEvent.key</a>
|
|
7218
|
+
* or <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code" target="_blank">KeyboardEvent.code</a> values,
|
|
7219
|
+
* such as `keyIsDown('x')` or `keyIsDown('ArrowLeft')`.
|
|
7220
|
+
*
|
|
7221
|
+
* Note: In p5.js 2.0 and newer, numeric keycodes (such as 88 for 'X') are no longer supported.
|
|
7222
|
+
* This is a breaking change from previous versions.
|
|
7223
|
+
*
|
|
7224
|
+
* You can still use the p5 constants like `LEFT_ARROW` which now map to string values
|
|
7225
|
+
* internally rather than numeric codes.
|
|
7226
|
+
* @param code key to check.
|
|
7227
|
+
* @returns whether the key is down or not.
|
|
7228
|
+
*/
|
|
7229
|
+
keyIsDown(code: number | string): boolean;
|
|
7250
7230
|
|
|
7251
7231
|
/**
|
|
7252
7232
|
* Sets the element's content.
|
|
@@ -7260,31 +7240,21 @@ declare class p5 {
|
|
|
7260
7240
|
setContent(content: string): void;
|
|
7261
7241
|
|
|
7262
7242
|
/**
|
|
7263
|
-
*
|
|
7264
|
-
* it will default to `'text'`.
|
|
7243
|
+
* Draws a <a href="#/p5.Geometry">p5.Geometry</a> object to the canvas.
|
|
7265
7244
|
*
|
|
7266
|
-
*
|
|
7267
|
-
*
|
|
7268
|
-
*
|
|
7245
|
+
* The parameter, `model`, is the
|
|
7246
|
+
* <a href="#/p5.Geometry">p5.Geometry</a> object to draw.
|
|
7247
|
+
* <a href="#/p5.Geometry">p5.Geometry</a> objects can be built with
|
|
7248
|
+
* <a href="#/p5/buildGeometry">buildGeometry()</a>, or
|
|
7249
|
+
* <a href="#/p5/beginGeometry">beginGeometry()</a> and
|
|
7250
|
+
* <a href="#/p5/endGeometry">endGeometry()</a>. They can also be loaded from
|
|
7251
|
+
* a file with <a href="#/p5/loadGeometry">loadGeometry()</a>.
|
|
7269
7252
|
*
|
|
7270
|
-
*
|
|
7271
|
-
* @param
|
|
7272
|
-
* @param
|
|
7273
|
-
* or other HTTP request methods
|
|
7274
|
-
* @param datatype "json", "jsonp", "xml", or "text"
|
|
7275
|
-
* @param data param data passed sent with request
|
|
7276
|
-
* @param callback function to be executed after
|
|
7277
|
-
* <a href="#/p5/httpGet">httpGet()</a> completes, data is passed in
|
|
7278
|
-
* as first argument
|
|
7279
|
-
* @param errorCallback function to be executed if
|
|
7280
|
-
* there is an error, response is passed
|
|
7281
|
-
* in as first argument
|
|
7282
|
-
* @returns A promise that resolves with the data when the operation
|
|
7283
|
-
* completes successfully or rejects with the error after
|
|
7284
|
-
* one occurs.
|
|
7253
|
+
* Note: `model()` can only be used in WebGL mode.
|
|
7254
|
+
* @param model 3D shape to be drawn.
|
|
7255
|
+
* @param count number of instances to draw.
|
|
7285
7256
|
*/
|
|
7286
|
-
|
|
7287
|
-
httpDo(path: string | Request, callback?: Function, errorCallback?: Function): Promise<any>;
|
|
7257
|
+
model(model: p5.Geometry, count?: number): void;
|
|
7288
7258
|
|
|
7289
7259
|
/**
|
|
7290
7260
|
* Draws a rectangle.
|
|
@@ -7312,8 +7282,35 @@ declare class p5 {
|
|
|
7312
7282
|
* @param br optional radius of bottom-right corner.
|
|
7313
7283
|
* @param bl optional radius of bottom-left corner.
|
|
7314
7284
|
*/
|
|
7315
|
-
rect(x: number, y: number, w: number, h?: number, tl?: number, tr?: number, br?: number, bl?: number): void;
|
|
7316
|
-
rect(x: number, y: number, w: number, h: number, detailX?: number, detailY?: number): void;
|
|
7285
|
+
rect(x: number, y: number, w: number, h?: number, tl?: number, tr?: number, br?: number, bl?: number): void;
|
|
7286
|
+
rect(x: number, y: number, w: number, h: number, detailX?: number, detailY?: number): void;
|
|
7287
|
+
|
|
7288
|
+
/**
|
|
7289
|
+
* Method for executing an HTTP request. If data type is not specified,
|
|
7290
|
+
* it will default to `'text'`.
|
|
7291
|
+
*
|
|
7292
|
+
* This function is meant for more advanced usage of HTTP requests in p5.js. It is
|
|
7293
|
+
* best used when a `Request`
|
|
7294
|
+
* object is passed to the `path` parameter.
|
|
7295
|
+
*
|
|
7296
|
+
* This method is suitable for fetching files up to size of 64MB when "GET" is used.
|
|
7297
|
+
* @param path name of the file or url to load
|
|
7298
|
+
* @param method either "GET", "POST", "PUT", "DELETE",
|
|
7299
|
+
* or other HTTP request methods
|
|
7300
|
+
* @param datatype "json", "jsonp", "xml", or "text"
|
|
7301
|
+
* @param data param data passed sent with request
|
|
7302
|
+
* @param callback function to be executed after
|
|
7303
|
+
* <a href="#/p5/httpGet">httpGet()</a> completes, data is passed in
|
|
7304
|
+
* as first argument
|
|
7305
|
+
* @param errorCallback function to be executed if
|
|
7306
|
+
* there is an error, response is passed
|
|
7307
|
+
* in as first argument
|
|
7308
|
+
* @returns A promise that resolves with the data when the operation
|
|
7309
|
+
* completes successfully or rejects with the error after
|
|
7310
|
+
* one occurs.
|
|
7311
|
+
*/
|
|
7312
|
+
httpDo(path: string | Request, method?: string, datatype?: string, data?: object, callback?: Function, errorCallback?: Function): Promise<any>;
|
|
7313
|
+
httpDo(path: string | Request, callback?: Function, errorCallback?: Function): Promise<any>;
|
|
7317
7314
|
|
|
7318
7315
|
/**
|
|
7319
7316
|
* Shears the y-axis so that shapes appear skewed.
|
|
@@ -7619,6 +7616,22 @@ declare class p5 {
|
|
|
7619
7616
|
*/
|
|
7620
7617
|
strokeShader(s: p5.Shader): void;
|
|
7621
7618
|
|
|
7619
|
+
/**
|
|
7620
|
+
* Gets the brightness value of a color.
|
|
7621
|
+
*
|
|
7622
|
+
* `brightness()` extracts the HSB brightness value from a
|
|
7623
|
+
* <a href="/reference/p5/p5.Color/">p5.Color</a> object, an array of color components, or
|
|
7624
|
+
* a CSS color string.
|
|
7625
|
+
*
|
|
7626
|
+
* By default, `brightness()` returns a color's HSB brightness in the range 0
|
|
7627
|
+
* to 100. If the <a href="/reference/p5/colorMode/">colorMode()</a> is set to HSB, it
|
|
7628
|
+
* returns the brightness value in the given range.
|
|
7629
|
+
* @param color <a href="/reference/p5/p5.Color/">p5.Color</a> object, array of
|
|
7630
|
+
* color components, or CSS color string.
|
|
7631
|
+
* @returns the brightness value.
|
|
7632
|
+
*/
|
|
7633
|
+
brightness(color: p5.Color | number[] | string): number;
|
|
7634
|
+
|
|
7622
7635
|
/**
|
|
7623
7636
|
* Tints images using a color.
|
|
7624
7637
|
*
|
|
@@ -7647,47 +7660,6 @@ declare class p5 {
|
|
|
7647
7660
|
tint(values: number[]): void;
|
|
7648
7661
|
tint(color: p5.Color): void;
|
|
7649
7662
|
|
|
7650
|
-
/**
|
|
7651
|
-
* Gets the brightness value of a color.
|
|
7652
|
-
*
|
|
7653
|
-
* `brightness()` extracts the HSB brightness value from a
|
|
7654
|
-
* <a href="/reference/p5/p5.Color/">p5.Color</a> object, an array of color components, or
|
|
7655
|
-
* a CSS color string.
|
|
7656
|
-
*
|
|
7657
|
-
* By default, `brightness()` returns a color's HSB brightness in the range 0
|
|
7658
|
-
* to 100. If the <a href="/reference/p5/colorMode/">colorMode()</a> is set to HSB, it
|
|
7659
|
-
* returns the brightness value in the given range.
|
|
7660
|
-
* @param color <a href="/reference/p5/p5.Color/">p5.Color</a> object, array of
|
|
7661
|
-
* color components, or CSS color string.
|
|
7662
|
-
* @returns the brightness value.
|
|
7663
|
-
*/
|
|
7664
|
-
brightness(color: p5.Color | number[] | string): number;
|
|
7665
|
-
|
|
7666
|
-
/**
|
|
7667
|
-
* Creates a new <a href="#/p5.PrintWriter">p5.PrintWriter</a> object.
|
|
7668
|
-
*
|
|
7669
|
-
* <a href="#/p5.PrintWriter">p5.PrintWriter</a> objects provide a way to
|
|
7670
|
-
* save a sequence of text data, called the print stream, to the user's
|
|
7671
|
-
* computer. They're low-level objects that enable precise control of text
|
|
7672
|
-
* output. Functions such as
|
|
7673
|
-
* <a href="#/p5/saveStrings">saveStrings()</a> and
|
|
7674
|
-
* <a href="#/p5/saveJSON">saveJSON()</a> are easier to use for simple file
|
|
7675
|
-
* saving.
|
|
7676
|
-
*
|
|
7677
|
-
* The first parameter, `filename`, is the name of the file to be written. If
|
|
7678
|
-
* a string is passed, as in `createWriter('words.txt')`, a new
|
|
7679
|
-
* <a href="#/p5.PrintWriter">p5.PrintWriter</a> object will be created that
|
|
7680
|
-
* writes to a file named `words.txt`.
|
|
7681
|
-
*
|
|
7682
|
-
* The second parameter, `extension`, is optional. If a string is passed, as
|
|
7683
|
-
* in `createWriter('words', 'csv')`, the first parameter will be interpreted
|
|
7684
|
-
* as the file name and the second parameter as the extension.
|
|
7685
|
-
* @param name name of the file to create.
|
|
7686
|
-
* @param extension format to use for the file.
|
|
7687
|
-
* @returns stream for writing data.
|
|
7688
|
-
*/
|
|
7689
|
-
createWriter(name: string, extension?: string): p5.PrintWriter;
|
|
7690
|
-
|
|
7691
7663
|
/**
|
|
7692
7664
|
* Creates a light that shines from a point in one direction.
|
|
7693
7665
|
*
|
|
@@ -7736,6 +7708,31 @@ declare class p5 {
|
|
|
7736
7708
|
spotLight(v1: number, v2: number, v3: number, position: p5.Vector, rx: number, ry: number, rz: number, angle?: number, concentration?: number): void;
|
|
7737
7709
|
spotLight(color: p5.Color | number[] | string, x: number, y: number, z: number, rx: number, ry: number, rz: number, angle?: number, concentration?: number): void;
|
|
7738
7710
|
|
|
7711
|
+
/**
|
|
7712
|
+
* Creates a new <a href="#/p5.PrintWriter">p5.PrintWriter</a> object.
|
|
7713
|
+
*
|
|
7714
|
+
* <a href="#/p5.PrintWriter">p5.PrintWriter</a> objects provide a way to
|
|
7715
|
+
* save a sequence of text data, called the print stream, to the user's
|
|
7716
|
+
* computer. They're low-level objects that enable precise control of text
|
|
7717
|
+
* output. Functions such as
|
|
7718
|
+
* <a href="#/p5/saveStrings">saveStrings()</a> and
|
|
7719
|
+
* <a href="#/p5/saveJSON">saveJSON()</a> are easier to use for simple file
|
|
7720
|
+
* saving.
|
|
7721
|
+
*
|
|
7722
|
+
* The first parameter, `filename`, is the name of the file to be written. If
|
|
7723
|
+
* a string is passed, as in `createWriter('words.txt')`, a new
|
|
7724
|
+
* <a href="#/p5.PrintWriter">p5.PrintWriter</a> object will be created that
|
|
7725
|
+
* writes to a file named `words.txt`.
|
|
7726
|
+
*
|
|
7727
|
+
* The second parameter, `extension`, is optional. If a string is passed, as
|
|
7728
|
+
* in `createWriter('words', 'csv')`, the first parameter will be interpreted
|
|
7729
|
+
* as the file name and the second parameter as the extension.
|
|
7730
|
+
* @param name name of the file to create.
|
|
7731
|
+
* @param extension format to use for the file.
|
|
7732
|
+
* @returns stream for writing data.
|
|
7733
|
+
*/
|
|
7734
|
+
createWriter(name: string, extension?: string): p5.PrintWriter;
|
|
7735
|
+
|
|
7739
7736
|
/**
|
|
7740
7737
|
* Translates the coordinate system.
|
|
7741
7738
|
*
|
|
@@ -8228,18 +8225,6 @@ declare class p5 {
|
|
|
8228
8225
|
*/
|
|
8229
8226
|
noLights(): void;
|
|
8230
8227
|
|
|
8231
|
-
/**
|
|
8232
|
-
* Writes data to the print stream without adding new lines.
|
|
8233
|
-
*
|
|
8234
|
-
* The parameter, `data`, is the data to write. `data` can be a number or
|
|
8235
|
-
* string, as in `myWriter.write('hi')`, or an array of numbers and strings,
|
|
8236
|
-
* as in `myWriter.write([1, 2, 3])`. A comma will be inserted between array
|
|
8237
|
-
* array elements when they're added to the print stream.
|
|
8238
|
-
* @param data data to be written as a string, number,
|
|
8239
|
-
* or array of strings and numbers.
|
|
8240
|
-
*/
|
|
8241
|
-
write(data: string | number | any[]): void;
|
|
8242
|
-
|
|
8243
8228
|
/**
|
|
8244
8229
|
* Gets the lightness value of a color.
|
|
8245
8230
|
*
|
|
@@ -8256,6 +8241,25 @@ declare class p5 {
|
|
|
8256
8241
|
*/
|
|
8257
8242
|
lightness(color: p5.Color | number[] | string): number;
|
|
8258
8243
|
|
|
8244
|
+
/**
|
|
8245
|
+
* Sets the <a href="#/p5.Shader">p5.Shader</a> object to apply for images.
|
|
8246
|
+
*
|
|
8247
|
+
* This method allows the user to apply a custom shader to images, enabling
|
|
8248
|
+
* advanced visual effects such as pixel manipulation, color adjustments,
|
|
8249
|
+
* or dynamic behavior. The shader will be applied to the image drawn using
|
|
8250
|
+
* the <a href="#/p5/image">image()</a> function.
|
|
8251
|
+
*
|
|
8252
|
+
* The shader will be used exclusively for:
|
|
8253
|
+
*
|
|
8254
|
+
* - `image()` calls, applying only when drawing 2D images.
|
|
8255
|
+
*
|
|
8256
|
+
* - This shader will NOT apply to images used in <a href="#/p5/texture">texture()</a> or other 3D contexts.
|
|
8257
|
+
* Any attempts to use the imageShader in these cases will be ignored.
|
|
8258
|
+
* @param s <a href="#/p5.Shader">p5.Shader</a> object
|
|
8259
|
+
* to apply for images.
|
|
8260
|
+
*/
|
|
8261
|
+
imageShader(s: p5.Shader): void;
|
|
8262
|
+
|
|
8259
8263
|
/**
|
|
8260
8264
|
* Changes the location from which images are drawn when
|
|
8261
8265
|
* <a href="#/p5/image">image()</a> is called.
|
|
@@ -8324,23 +8328,16 @@ declare class p5 {
|
|
|
8324
8328
|
mouseReleased(event?: MouseEvent): void;
|
|
8325
8329
|
|
|
8326
8330
|
/**
|
|
8327
|
-
*
|
|
8328
|
-
*
|
|
8329
|
-
* This method allows the user to apply a custom shader to images, enabling
|
|
8330
|
-
* advanced visual effects such as pixel manipulation, color adjustments,
|
|
8331
|
-
* or dynamic behavior. The shader will be applied to the image drawn using
|
|
8332
|
-
* the <a href="#/p5/image">image()</a> function.
|
|
8333
|
-
*
|
|
8334
|
-
* The shader will be used exclusively for:
|
|
8335
|
-
*
|
|
8336
|
-
* - `image()` calls, applying only when drawing 2D images.
|
|
8331
|
+
* Writes data to the print stream without adding new lines.
|
|
8337
8332
|
*
|
|
8338
|
-
*
|
|
8339
|
-
*
|
|
8340
|
-
*
|
|
8341
|
-
* to
|
|
8333
|
+
* The parameter, `data`, is the data to write. `data` can be a number or
|
|
8334
|
+
* string, as in `myWriter.write('hi')`, or an array of numbers and strings,
|
|
8335
|
+
* as in `myWriter.write([1, 2, 3])`. A comma will be inserted between array
|
|
8336
|
+
* array elements when they're added to the print stream.
|
|
8337
|
+
* @param data data to be written as a string, number,
|
|
8338
|
+
* or array of strings and numbers.
|
|
8342
8339
|
*/
|
|
8343
|
-
|
|
8340
|
+
write(data: string | number | any[]): void;
|
|
8344
8341
|
|
|
8345
8342
|
/**
|
|
8346
8343
|
* Disables drawing points, lines, and the outlines of shapes.
|
|
@@ -8630,7 +8627,7 @@ declare class p5 {
|
|
|
8630
8627
|
* }
|
|
8631
8628
|
*
|
|
8632
8629
|
* function material() {
|
|
8633
|
-
* let time =
|
|
8630
|
+
* let time = millis();
|
|
8634
8631
|
* worldInputs.begin();
|
|
8635
8632
|
* worldInputs.position.y +=
|
|
8636
8633
|
* 20 * sin(time * 0.001 + worldInputs.position.x * 0.05);
|
|
@@ -8640,7 +8637,6 @@ declare class p5 {
|
|
|
8640
8637
|
* function draw() {
|
|
8641
8638
|
* background(255);
|
|
8642
8639
|
* shader(myShader);
|
|
8643
|
-
* myShader.setUniform('time', millis());
|
|
8644
8640
|
* lights();
|
|
8645
8641
|
* noStroke();
|
|
8646
8642
|
* fill('red');
|
|
@@ -8858,42 +8854,6 @@ declare class p5 {
|
|
|
8858
8854
|
*/
|
|
8859
8855
|
createColorPicker(value?: string | p5.Color): p5.Element;
|
|
8860
8856
|
|
|
8861
|
-
/**
|
|
8862
|
-
* Saves a given element(image, text, json, csv, wav, or html) to the client's
|
|
8863
|
-
* computer. The first parameter can be a pointer to element we want to save.
|
|
8864
|
-
* The element can be one of <a href="#/p5.Element">p5.Element</a>,an Array of
|
|
8865
|
-
* Strings, an Array of JSON, a JSON object, a <a href="#/p5.Table">p5.Table
|
|
8866
|
-
* </a>, a <a href="#/p5.Image">p5.Image</a>, or a p5.SoundFile (requires
|
|
8867
|
-
* p5.sound). The second parameter is a filename (including extension).The
|
|
8868
|
-
* third parameter is for options specific to this type of object. This method
|
|
8869
|
-
* will save a file that fits the given parameters.
|
|
8870
|
-
* If it is called without specifying an element, by default it will save the
|
|
8871
|
-
* whole canvas as an image file. You can optionally specify a filename as
|
|
8872
|
-
* the first parameter in such a case.
|
|
8873
|
-
* Note that it is not recommended to
|
|
8874
|
-
* call this method within draw, as it will open a new save dialog on every
|
|
8875
|
-
* render.
|
|
8876
|
-
* @param objectOrFilename If filename is provided, will
|
|
8877
|
-
* save canvas as an image with
|
|
8878
|
-
* either png or jpg extension
|
|
8879
|
-
* depending on the filename.
|
|
8880
|
-
* If object is provided, will
|
|
8881
|
-
* save depending on the object
|
|
8882
|
-
* and filename (see examples
|
|
8883
|
-
* above).
|
|
8884
|
-
* @param filename If an object is provided as the first
|
|
8885
|
-
* parameter, then the second parameter
|
|
8886
|
-
* indicates the filename,
|
|
8887
|
-
* and should include an appropriate
|
|
8888
|
-
* file extension (see examples above).
|
|
8889
|
-
* @param options Additional options depend on
|
|
8890
|
-
* filetype. For example, when saving JSON,
|
|
8891
|
-
* <code>true</code> indicates that the
|
|
8892
|
-
* output will be optimized for filesize,
|
|
8893
|
-
* rather than readability.
|
|
8894
|
-
*/
|
|
8895
|
-
save(objectOrFilename?: object | string, filename?: string, options?: boolean | string): void;
|
|
8896
|
-
|
|
8897
8857
|
/**
|
|
8898
8858
|
* Loads a new shader from a file that can change how fills are drawn. Pass the resulting
|
|
8899
8859
|
* shader into the <a href="#/p5/shader">`shader()`</a> function to apply it
|
|
@@ -8911,7 +8871,6 @@ declare class p5 {
|
|
|
8911
8871
|
* function draw() {
|
|
8912
8872
|
* background(255);
|
|
8913
8873
|
* shader(myShader);
|
|
8914
|
-
* myShader.setUniform('time', millis());
|
|
8915
8874
|
* lights();
|
|
8916
8875
|
* noStroke();
|
|
8917
8876
|
* fill('red');
|
|
@@ -8921,7 +8880,7 @@ declare class p5 {
|
|
|
8921
8880
|
* might use the `pixelInputs` hook to change each pixel on the surface of a shape.
|
|
8922
8881
|
*
|
|
8923
8882
|
* `// myMaterial.js
|
|
8924
|
-
* let time =
|
|
8883
|
+
* let time = millis();
|
|
8925
8884
|
* worldInputs.begin();
|
|
8926
8885
|
* worldInputs.position.y +=
|
|
8927
8886
|
* 20 * sin(time * 0.001 + worldInputs.position.x * 0.05);
|
|
@@ -8941,6 +8900,42 @@ declare class p5 {
|
|
|
8941
8900
|
*/
|
|
8942
8901
|
loadMaterialShader(url: string, onSuccess?: Function, onFailure?: Function): Promise<p5.Shader>;
|
|
8943
8902
|
|
|
8903
|
+
/**
|
|
8904
|
+
* Saves a given element(image, text, json, csv, wav, or html) to the client's
|
|
8905
|
+
* computer. The first parameter can be a pointer to element we want to save.
|
|
8906
|
+
* The element can be one of <a href="#/p5.Element">p5.Element</a>,an Array of
|
|
8907
|
+
* Strings, an Array of JSON, a JSON object, a <a href="#/p5.Table">p5.Table
|
|
8908
|
+
* </a>, a <a href="#/p5.Image">p5.Image</a>, or a p5.SoundFile (requires
|
|
8909
|
+
* p5.sound). The second parameter is a filename (including extension).The
|
|
8910
|
+
* third parameter is for options specific to this type of object. This method
|
|
8911
|
+
* will save a file that fits the given parameters.
|
|
8912
|
+
* If it is called without specifying an element, by default it will save the
|
|
8913
|
+
* whole canvas as an image file. You can optionally specify a filename as
|
|
8914
|
+
* the first parameter in such a case.
|
|
8915
|
+
* Note that it is not recommended to
|
|
8916
|
+
* call this method within draw, as it will open a new save dialog on every
|
|
8917
|
+
* render.
|
|
8918
|
+
* @param objectOrFilename If filename is provided, will
|
|
8919
|
+
* save canvas as an image with
|
|
8920
|
+
* either png or jpg extension
|
|
8921
|
+
* depending on the filename.
|
|
8922
|
+
* If object is provided, will
|
|
8923
|
+
* save depending on the object
|
|
8924
|
+
* and filename (see examples
|
|
8925
|
+
* above).
|
|
8926
|
+
* @param filename If an object is provided as the first
|
|
8927
|
+
* parameter, then the second parameter
|
|
8928
|
+
* indicates the filename,
|
|
8929
|
+
* and should include an appropriate
|
|
8930
|
+
* file extension (see examples above).
|
|
8931
|
+
* @param options Additional options depend on
|
|
8932
|
+
* filetype. For example, when saving JSON,
|
|
8933
|
+
* <code>true</code> indicates that the
|
|
8934
|
+
* output will be optimized for filesize,
|
|
8935
|
+
* rather than readability.
|
|
8936
|
+
*/
|
|
8937
|
+
save(objectOrFilename?: object | string, filename?: string, options?: boolean | string): void;
|
|
8938
|
+
|
|
8944
8939
|
/**
|
|
8945
8940
|
* Influences the shape of the Bézier curve segment in a custom shape.
|
|
8946
8941
|
* By default, this is 3; the other possible parameter is 2. This
|
|
@@ -9023,6 +9018,19 @@ declare class p5 {
|
|
|
9023
9018
|
*/
|
|
9024
9019
|
baseMaterialShader(): p5.Shader;
|
|
9025
9020
|
|
|
9021
|
+
/**
|
|
9022
|
+
* Returns the base shader used for filters.
|
|
9023
|
+
*
|
|
9024
|
+
* Calling <a href="#/p5/buildFilterShader">`buildFilterShader(shaderFunction)`</a>
|
|
9025
|
+
* is equivalent to calling `baseFilterShader().modify(shaderFunction)`.
|
|
9026
|
+
*
|
|
9027
|
+
* Read <a href="#/p5/buildFilterShader">the `buildFilterShader` reference</a> or
|
|
9028
|
+
* call `baseFilterShader().inspectHooks()` for more information on what you can do with
|
|
9029
|
+
* the base filter shader.
|
|
9030
|
+
* @returns The base filter shader.
|
|
9031
|
+
*/
|
|
9032
|
+
baseFilterShader(): p5.Shader;
|
|
9033
|
+
|
|
9026
9034
|
/**
|
|
9027
9035
|
* Starts using shapes to erase parts of the canvas.
|
|
9028
9036
|
*
|
|
@@ -9046,29 +9054,16 @@ declare class p5 {
|
|
|
9046
9054
|
*
|
|
9047
9055
|
* To cancel the erasing effect, use the <a href="#/p5/noErase">noErase()</a>
|
|
9048
9056
|
* function.
|
|
9049
|
-
*
|
|
9050
|
-
* `erase()` has no effect on drawing done with the
|
|
9051
|
-
* <a href="#/p5/image">image()</a> and
|
|
9052
|
-
* <a href="#/p5/background">background()</a> functions.
|
|
9053
|
-
* @param strengthFill a number (0-255) for the strength of erasing under a shape's interior.
|
|
9054
|
-
* Defaults to 255, which is full strength.
|
|
9055
|
-
* @param strengthStroke a number (0-255) for the strength of erasing under a shape's edge.
|
|
9056
|
-
* Defaults to 255, which is full strength.
|
|
9057
|
-
*/
|
|
9058
|
-
erase(strengthFill?: number, strengthStroke?: number): void;
|
|
9059
|
-
|
|
9060
|
-
/**
|
|
9061
|
-
* Returns the base shader used for filters.
|
|
9062
|
-
*
|
|
9063
|
-
* Calling <a href="#/p5/buildFilterShader">`buildFilterShader(shaderFunction)`</a>
|
|
9064
|
-
* is equivalent to calling `baseFilterShader().modify(shaderFunction)`.
|
|
9065
|
-
*
|
|
9066
|
-
* Read <a href="#/p5/buildFilterShader">the `buildFilterShader` reference</a> or
|
|
9067
|
-
* call `baseFilterShader().inspectHooks()` for more information on what you can do with
|
|
9068
|
-
* the base filter shader.
|
|
9069
|
-
* @returns The base filter shader.
|
|
9057
|
+
*
|
|
9058
|
+
* `erase()` has no effect on drawing done with the
|
|
9059
|
+
* <a href="#/p5/image">image()</a> and
|
|
9060
|
+
* <a href="#/p5/background">background()</a> functions.
|
|
9061
|
+
* @param strengthFill a number (0-255) for the strength of erasing under a shape's interior.
|
|
9062
|
+
* Defaults to 255, which is full strength.
|
|
9063
|
+
* @param strengthStroke a number (0-255) for the strength of erasing under a shape's edge.
|
|
9064
|
+
* Defaults to 255, which is full strength.
|
|
9070
9065
|
*/
|
|
9071
|
-
|
|
9066
|
+
erase(strengthFill?: number, strengthStroke?: number): void;
|
|
9072
9067
|
|
|
9073
9068
|
/**
|
|
9074
9069
|
* Ends erasing that was started with <a href="#/p5/erase">erase()</a>.
|
|
@@ -9098,37 +9093,6 @@ declare class p5 {
|
|
|
9098
9093
|
createInput(value?: string, type?: string): p5.Element;
|
|
9099
9094
|
createInput(value?: string): p5.Element;
|
|
9100
9095
|
|
|
9101
|
-
/**
|
|
9102
|
-
* Saves an `Object` or `Array` to a JSON file.
|
|
9103
|
-
*
|
|
9104
|
-
* JavaScript Object Notation
|
|
9105
|
-
* (<a href="https://developer.mozilla.org/en-US/docs/Glossary/JSON" target="_blank">JSON</a>)
|
|
9106
|
-
* is a standard format for sending data between applications. The format is
|
|
9107
|
-
* based on JavaScript objects which have keys and values. JSON files store
|
|
9108
|
-
* data in an object with strings as keys. Values can be strings, numbers,
|
|
9109
|
-
* Booleans, arrays, `null`, or other objects.
|
|
9110
|
-
*
|
|
9111
|
-
* The first parameter, `json`, is the data to save. The data can be an array,
|
|
9112
|
-
* as in `[1, 2, 3]`, or an object, as in
|
|
9113
|
-
* `{ x: 50, y: 50, color: 'deeppink' }`.
|
|
9114
|
-
*
|
|
9115
|
-
* The second parameter, `filename`, is a string that sets the file's name.
|
|
9116
|
-
* For example, calling `saveJSON([1, 2, 3], 'data.json')` saves the array
|
|
9117
|
-
* `[1, 2, 3]` to a file called `data.json` on the user's computer.
|
|
9118
|
-
*
|
|
9119
|
-
* The third parameter, `optimize`, is optional. If `true` is passed, as in
|
|
9120
|
-
* `saveJSON([1, 2, 3], 'data.json', true)`, then all unneeded whitespace will
|
|
9121
|
-
* be removed to reduce the file size.
|
|
9122
|
-
*
|
|
9123
|
-
* Note: The browser will either save the file immediately or prompt the user
|
|
9124
|
-
* with a dialogue window.
|
|
9125
|
-
* @param json data to save.
|
|
9126
|
-
* @param filename name of the file to be saved.
|
|
9127
|
-
* @param optimize whether to trim unneeded whitespace. Defaults
|
|
9128
|
-
* to `true`.
|
|
9129
|
-
*/
|
|
9130
|
-
saveJSON(json: any[] | object, filename: string, optimize?: boolean): void;
|
|
9131
|
-
|
|
9132
9096
|
/**
|
|
9133
9097
|
* Create a new shader that can change how fills are drawn, based on the material used
|
|
9134
9098
|
* when <a href="#/p5/normalMaterial">`normalMaterial()`</a> is active. Pass the resulting
|
|
@@ -9161,7 +9125,7 @@ declare class p5 {
|
|
|
9161
9125
|
* }
|
|
9162
9126
|
*
|
|
9163
9127
|
* function material() {
|
|
9164
|
-
* let time =
|
|
9128
|
+
* let time = millis();
|
|
9165
9129
|
* worldInputs.begin();
|
|
9166
9130
|
* worldInputs.position.y +=
|
|
9167
9131
|
* 20. * sin(time * 0.001 + worldInputs.position.x * 0.05);
|
|
@@ -9171,7 +9135,6 @@ declare class p5 {
|
|
|
9171
9135
|
* function draw() {
|
|
9172
9136
|
* background(255);
|
|
9173
9137
|
* shader(myShader);
|
|
9174
|
-
* myShader.setUniform('time', millis());
|
|
9175
9138
|
* noStroke();
|
|
9176
9139
|
* sphere(50);
|
|
9177
9140
|
* }`You may also want to change the colors used. By default, the x, y, and z values of the orientation
|
|
@@ -9264,6 +9227,37 @@ declare class p5 {
|
|
|
9264
9227
|
*/
|
|
9265
9228
|
mouseWheel(event?: WheelEvent): void;
|
|
9266
9229
|
|
|
9230
|
+
/**
|
|
9231
|
+
* Saves an `Object` or `Array` to a JSON file.
|
|
9232
|
+
*
|
|
9233
|
+
* JavaScript Object Notation
|
|
9234
|
+
* (<a href="https://developer.mozilla.org/en-US/docs/Glossary/JSON" target="_blank">JSON</a>)
|
|
9235
|
+
* is a standard format for sending data between applications. The format is
|
|
9236
|
+
* based on JavaScript objects which have keys and values. JSON files store
|
|
9237
|
+
* data in an object with strings as keys. Values can be strings, numbers,
|
|
9238
|
+
* Booleans, arrays, `null`, or other objects.
|
|
9239
|
+
*
|
|
9240
|
+
* The first parameter, `json`, is the data to save. The data can be an array,
|
|
9241
|
+
* as in `[1, 2, 3]`, or an object, as in
|
|
9242
|
+
* `{ x: 50, y: 50, color: 'deeppink' }`.
|
|
9243
|
+
*
|
|
9244
|
+
* The second parameter, `filename`, is a string that sets the file's name.
|
|
9245
|
+
* For example, calling `saveJSON([1, 2, 3], 'data.json')` saves the array
|
|
9246
|
+
* `[1, 2, 3]` to a file called `data.json` on the user's computer.
|
|
9247
|
+
*
|
|
9248
|
+
* The third parameter, `optimize`, is optional. If `true` is passed, as in
|
|
9249
|
+
* `saveJSON([1, 2, 3], 'data.json', true)`, then all unneeded whitespace will
|
|
9250
|
+
* be removed to reduce the file size.
|
|
9251
|
+
*
|
|
9252
|
+
* Note: The browser will either save the file immediately or prompt the user
|
|
9253
|
+
* with a dialogue window.
|
|
9254
|
+
* @param json data to save.
|
|
9255
|
+
* @param filename name of the file to be saved.
|
|
9256
|
+
* @param optimize whether to trim unneeded whitespace. Defaults
|
|
9257
|
+
* to `true`.
|
|
9258
|
+
*/
|
|
9259
|
+
saveJSON(json: any[] | object, filename: string, optimize?: boolean): void;
|
|
9260
|
+
|
|
9267
9261
|
/**
|
|
9268
9262
|
* Ends a drawing group that contains its own styles and transformations.
|
|
9269
9263
|
*
|
|
@@ -9447,25 +9441,6 @@ declare class p5 {
|
|
|
9447
9441
|
*/
|
|
9448
9442
|
createFileInput(callback: (input: p5.File) => any, multiple?: boolean): p5.Element;
|
|
9449
9443
|
|
|
9450
|
-
/**
|
|
9451
|
-
* Locks the mouse pointer to its current position and makes it invisible.
|
|
9452
|
-
*
|
|
9453
|
-
* `requestPointerLock()` allows the mouse to move forever without leaving the
|
|
9454
|
-
* screen. Calling `requestPointerLock()` locks the values of
|
|
9455
|
-
* <a href="#/p5/mouseX">mouseX</a>, <a href="#/p5/mouseY">mouseY</a>,
|
|
9456
|
-
* <a href="#/p5/pmouseX">pmouseX</a>, and <a href="#/p5/pmouseY">pmouseY</a>.
|
|
9457
|
-
* <a href="#/p5/movedX">movedX</a> and <a href="#/p5/movedY">movedY</a>
|
|
9458
|
-
* continue updating and can be used to get the distance the mouse moved since
|
|
9459
|
-
* the last frame was drawn. Calling
|
|
9460
|
-
* <a href="#/p5/exitPointerLock">exitPointerLock()</a> resumes updating the
|
|
9461
|
-
* mouse system variables.
|
|
9462
|
-
*
|
|
9463
|
-
* Note: Most browsers require an input, such as a click, before calling
|
|
9464
|
-
* `requestPointerLock()`. It’s recommended to call `requestPointerLock()` in
|
|
9465
|
-
* an event function such as <a href="#/p5/doubleClicked">doubleClicked()</a>.
|
|
9466
|
-
*/
|
|
9467
|
-
requestPointerLock(): void;
|
|
9468
|
-
|
|
9469
9444
|
/**
|
|
9470
9445
|
* Loads a new shader from a file that can change how fills are drawn, based on the material used
|
|
9471
9446
|
* when <a href="#/p5/normalMaterial">`normalMaterial()`</a> is active. Pass the resulting
|
|
@@ -9484,7 +9459,6 @@ declare class p5 {
|
|
|
9484
9459
|
* function draw() {
|
|
9485
9460
|
* background(255);
|
|
9486
9461
|
* shader(myShader);
|
|
9487
|
-
* myShader.setUniform('time', millis());
|
|
9488
9462
|
* lights();
|
|
9489
9463
|
* noStroke();
|
|
9490
9464
|
* fill('red');
|
|
@@ -9494,7 +9468,7 @@ declare class p5 {
|
|
|
9494
9468
|
* might use the `finalColor` hook to change the color of each pixel on the surface of a shape.
|
|
9495
9469
|
*
|
|
9496
9470
|
* `// myMaterial.js
|
|
9497
|
-
* let time =
|
|
9471
|
+
* let time = millis();
|
|
9498
9472
|
* worldInputs.begin();
|
|
9499
9473
|
* worldInputs.position.y +=
|
|
9500
9474
|
* 20 * sin(time * 0.001 + worldInputs.position.x * 0.05);
|
|
@@ -9514,6 +9488,25 @@ declare class p5 {
|
|
|
9514
9488
|
*/
|
|
9515
9489
|
loadNormalShader(url: string, onSuccess?: Function, onFailure?: Function): Promise<p5.Shader>;
|
|
9516
9490
|
|
|
9491
|
+
/**
|
|
9492
|
+
* Locks the mouse pointer to its current position and makes it invisible.
|
|
9493
|
+
*
|
|
9494
|
+
* `requestPointerLock()` allows the mouse to move forever without leaving the
|
|
9495
|
+
* screen. Calling `requestPointerLock()` locks the values of
|
|
9496
|
+
* <a href="#/p5/mouseX">mouseX</a>, <a href="#/p5/mouseY">mouseY</a>,
|
|
9497
|
+
* <a href="#/p5/pmouseX">pmouseX</a>, and <a href="#/p5/pmouseY">pmouseY</a>.
|
|
9498
|
+
* <a href="#/p5/movedX">movedX</a> and <a href="#/p5/movedY">movedY</a>
|
|
9499
|
+
* continue updating and can be used to get the distance the mouse moved since
|
|
9500
|
+
* the last frame was drawn. Calling
|
|
9501
|
+
* <a href="#/p5/exitPointerLock">exitPointerLock()</a> resumes updating the
|
|
9502
|
+
* mouse system variables.
|
|
9503
|
+
*
|
|
9504
|
+
* Note: Most browsers require an input, such as a click, before calling
|
|
9505
|
+
* `requestPointerLock()`. It’s recommended to call `requestPointerLock()` in
|
|
9506
|
+
* an event function such as <a href="#/p5/doubleClicked">doubleClicked()</a>.
|
|
9507
|
+
*/
|
|
9508
|
+
requestPointerLock(): void;
|
|
9509
|
+
|
|
9517
9510
|
/**
|
|
9518
9511
|
* Returns the default shader used for fills when
|
|
9519
9512
|
* <a href="#/p5/normalMaterial">`normalMaterial()`</a> is activated.
|
|
@@ -9606,7 +9599,7 @@ declare class p5 {
|
|
|
9606
9599
|
* }
|
|
9607
9600
|
*
|
|
9608
9601
|
* function material() {
|
|
9609
|
-
* let time =
|
|
9602
|
+
* let time = millis();
|
|
9610
9603
|
* worldInputs.begin();
|
|
9611
9604
|
* worldInputs.position.y +=
|
|
9612
9605
|
* 20 * sin(time * 0.001 + worldInputs.position.x * 0.05);
|
|
@@ -9616,7 +9609,6 @@ declare class p5 {
|
|
|
9616
9609
|
* function draw() {
|
|
9617
9610
|
* background(255);
|
|
9618
9611
|
* shader(myShader);
|
|
9619
|
-
* myShader.setUniform('time', millis());
|
|
9620
9612
|
* noStroke();
|
|
9621
9613
|
* fill('red');
|
|
9622
9614
|
* circle(0, 0, 50);
|
|
@@ -9730,7 +9722,6 @@ declare class p5 {
|
|
|
9730
9722
|
* function draw() {
|
|
9731
9723
|
* background(255);
|
|
9732
9724
|
* shader(myShader);
|
|
9733
|
-
* myShader.setUniform('time', millis());
|
|
9734
9725
|
* lights();
|
|
9735
9726
|
* noStroke();
|
|
9736
9727
|
* fill('red');
|
|
@@ -9740,7 +9731,7 @@ declare class p5 {
|
|
|
9740
9731
|
* might use the `finalColor` hook to change the color of each pixel on the surface of a shape.
|
|
9741
9732
|
*
|
|
9742
9733
|
* `// myMaterial.js
|
|
9743
|
-
* let time =
|
|
9734
|
+
* let time = millis();
|
|
9744
9735
|
* worldInputs.begin();
|
|
9745
9736
|
* worldInputs.position.y +=
|
|
9746
9737
|
* 20 * sin(time * 0.001 + worldInputs.position.x * 0.05);
|
|
@@ -10025,7 +10016,7 @@ declare class p5 {
|
|
|
10025
10016
|
* }
|
|
10026
10017
|
*
|
|
10027
10018
|
* function material() {
|
|
10028
|
-
* let time =
|
|
10019
|
+
* let time = millis();
|
|
10029
10020
|
* worldInputs.begin();
|
|
10030
10021
|
* // Add a somewhat random offset to the weight
|
|
10031
10022
|
* // that varies based on position and time
|
|
@@ -10041,7 +10032,6 @@ declare class p5 {
|
|
|
10041
10032
|
* function draw() {
|
|
10042
10033
|
* background(255);
|
|
10043
10034
|
* strokeShader(myShader);
|
|
10044
|
-
* myShader.setUniform('time', millis());
|
|
10045
10035
|
* strokeWeight(10);
|
|
10046
10036
|
* beginShape();
|
|
10047
10037
|
* for (let i = 0; i <= 50; i++) {
|
|
@@ -10132,6 +10122,58 @@ declare class p5 {
|
|
|
10132
10122
|
splineProperty(property: string, value: any): void;
|
|
10133
10123
|
splineProperty(property: string): void;
|
|
10134
10124
|
|
|
10125
|
+
/**
|
|
10126
|
+
* Loads a new shader from a file that can change how strokes are drawn. Pass the resulting
|
|
10127
|
+
* shader into the <a href="#/p5/strokeShader">`strokeShader()`</a> function to apply it
|
|
10128
|
+
* to any strokes you draw.
|
|
10129
|
+
*
|
|
10130
|
+
* Since this function loads data from another file, it returns a `Promise`.
|
|
10131
|
+
* Use it in an `async function setup`, and `await` its result.
|
|
10132
|
+
*
|
|
10133
|
+
* `let myShader;
|
|
10134
|
+
* async function setup() {
|
|
10135
|
+
* createCanvas(200, 200, WEBGL);
|
|
10136
|
+
* myShader = await loadStrokeShader('myMaterial.js');
|
|
10137
|
+
* }
|
|
10138
|
+
*
|
|
10139
|
+
* function draw() {
|
|
10140
|
+
* background(255);
|
|
10141
|
+
* strokeShader(myShader);
|
|
10142
|
+
* strokeWeight(30);
|
|
10143
|
+
* line(
|
|
10144
|
+
* -width/3,
|
|
10145
|
+
* sin(millis()*0.001) * height/4,
|
|
10146
|
+
* width/3,
|
|
10147
|
+
* sin(millis()*0.001 + 1) * height/4
|
|
10148
|
+
* );
|
|
10149
|
+
* }`Inside your shader file, you can call p5.strands hooks to change parts of the shader. For
|
|
10150
|
+
* example, you might use the `worldInputs` hook to change each vertex, or you
|
|
10151
|
+
* might use the `pixelInputs` hook to change each pixel on the surface of a stroke.
|
|
10152
|
+
*
|
|
10153
|
+
* `// myMaterial.js
|
|
10154
|
+
* pixelInputs.begin();
|
|
10155
|
+
* let opacity = 1 - smoothstep(
|
|
10156
|
+
* 0,
|
|
10157
|
+
* 15,
|
|
10158
|
+
* length(pixelInputs.position - pixelInputs.center)
|
|
10159
|
+
* );
|
|
10160
|
+
* pixelInputs.color.a *= opacity;
|
|
10161
|
+
* pixelInputs.end();`Read the reference for <a href="#/p5/buildStrokeShader">`buildStrokeShader`</a>,
|
|
10162
|
+
* the version of `loadStrokeShader` that takes in a function instead of a separate file,
|
|
10163
|
+
* for a full list of hooks you can use and examples for each.
|
|
10164
|
+
*
|
|
10165
|
+
* The second parameter, `successCallback`, is optional. If a function is passed, as in
|
|
10166
|
+
* `loadStrokeShader('myShader.js', onLoaded)`, then the `onLoaded()` function will be called
|
|
10167
|
+
* once the shader loads. The shader will be passed to `onLoaded()` as its only argument.
|
|
10168
|
+
* The return value of `handleData()`, if present, will be used as the final return value of
|
|
10169
|
+
* `loadStrokeShader('myShader.js', onLoaded)`.
|
|
10170
|
+
* @param url The URL of your p5.strands JavaScript file.
|
|
10171
|
+
* @param onSuccess A callback function to run when loading completes.
|
|
10172
|
+
* @param onFailure A callback function to run when loading fails.
|
|
10173
|
+
* @returns The stroke shader.
|
|
10174
|
+
*/
|
|
10175
|
+
loadStrokeShader(url: string, onSuccess?: Function, onFailure?: Function): Promise<p5.Shader>;
|
|
10176
|
+
|
|
10135
10177
|
/**
|
|
10136
10178
|
* Sets a perspective projection for the current camera in a 3D sketch.
|
|
10137
10179
|
*
|
|
@@ -10186,58 +10228,6 @@ declare class p5 {
|
|
|
10186
10228
|
*/
|
|
10187
10229
|
perspective(fovy?: number, aspect?: number, near?: number, far?: number): void;
|
|
10188
10230
|
|
|
10189
|
-
/**
|
|
10190
|
-
* Loads a new shader from a file that can change how strokes are drawn. Pass the resulting
|
|
10191
|
-
* shader into the <a href="#/p5/strokeShader">`strokeShader()`</a> function to apply it
|
|
10192
|
-
* to any strokes you draw.
|
|
10193
|
-
*
|
|
10194
|
-
* Since this function loads data from another file, it returns a `Promise`.
|
|
10195
|
-
* Use it in an `async function setup`, and `await` its result.
|
|
10196
|
-
*
|
|
10197
|
-
* `let myShader;
|
|
10198
|
-
* async function setup() {
|
|
10199
|
-
* createCanvas(200, 200, WEBGL);
|
|
10200
|
-
* myShader = await loadStrokeShader('myMaterial.js');
|
|
10201
|
-
* }
|
|
10202
|
-
*
|
|
10203
|
-
* function draw() {
|
|
10204
|
-
* background(255);
|
|
10205
|
-
* strokeShader(myShader);
|
|
10206
|
-
* strokeWeight(30);
|
|
10207
|
-
* line(
|
|
10208
|
-
* -width/3,
|
|
10209
|
-
* sin(millis()*0.001) * height/4,
|
|
10210
|
-
* width/3,
|
|
10211
|
-
* sin(millis()*0.001 + 1) * height/4
|
|
10212
|
-
* );
|
|
10213
|
-
* }`Inside your shader file, you can call p5.strands hooks to change parts of the shader. For
|
|
10214
|
-
* example, you might use the `worldInputs` hook to change each vertex, or you
|
|
10215
|
-
* might use the `pixelInputs` hook to change each pixel on the surface of a stroke.
|
|
10216
|
-
*
|
|
10217
|
-
* `// myMaterial.js
|
|
10218
|
-
* pixelInputs.begin();
|
|
10219
|
-
* let opacity = 1 - smoothstep(
|
|
10220
|
-
* 0,
|
|
10221
|
-
* 15,
|
|
10222
|
-
* length(pixelInputs.position - pixelInputs.center)
|
|
10223
|
-
* );
|
|
10224
|
-
* pixelInputs.color.a *= opacity;
|
|
10225
|
-
* pixelInputs.end();`Read the reference for <a href="#/p5/buildStrokeShader">`buildStrokeShader`</a>,
|
|
10226
|
-
* the version of `loadStrokeShader` that takes in a function instead of a separate file,
|
|
10227
|
-
* for a full list of hooks you can use and examples for each.
|
|
10228
|
-
*
|
|
10229
|
-
* The second parameter, `successCallback`, is optional. If a function is passed, as in
|
|
10230
|
-
* `loadStrokeShader('myShader.js', onLoaded)`, then the `onLoaded()` function will be called
|
|
10231
|
-
* once the shader loads. The shader will be passed to `onLoaded()` as its only argument.
|
|
10232
|
-
* The return value of `handleData()`, if present, will be used as the final return value of
|
|
10233
|
-
* `loadStrokeShader('myShader.js', onLoaded)`.
|
|
10234
|
-
* @param url The URL of your p5.strands JavaScript file.
|
|
10235
|
-
* @param onSuccess A callback function to run when loading completes.
|
|
10236
|
-
* @param onFailure A callback function to run when loading fails.
|
|
10237
|
-
* @returns The stroke shader.
|
|
10238
|
-
*/
|
|
10239
|
-
loadStrokeShader(url: string, onSuccess?: Function, onFailure?: Function): Promise<p5.Shader>;
|
|
10240
|
-
|
|
10241
10231
|
/**
|
|
10242
10232
|
* Returns the default shader used for strokes.
|
|
10243
10233
|
*
|
|
@@ -10282,6 +10272,17 @@ declare class p5 {
|
|
|
10282
10272
|
*/
|
|
10283
10273
|
splineProperties(values: object): object;
|
|
10284
10274
|
|
|
10275
|
+
/**
|
|
10276
|
+
* Restores the default shaders.
|
|
10277
|
+
*
|
|
10278
|
+
* `resetShader()` deactivates any shaders previously applied by
|
|
10279
|
+
* <a href="#/p5/shader">shader()</a>, <a href="#/p5/strokeShader">strokeShader()</a>,
|
|
10280
|
+
* or <a href="#/p5/imageShader">imageShader()</a>.
|
|
10281
|
+
*
|
|
10282
|
+
* Note: Shaders can only be used in WebGL mode.
|
|
10283
|
+
*/
|
|
10284
|
+
resetShader(): void;
|
|
10285
|
+
|
|
10285
10286
|
/**
|
|
10286
10287
|
* Enables or disables perspective for lines in 3D sketches.
|
|
10287
10288
|
*
|
|
@@ -10319,17 +10320,6 @@ declare class p5 {
|
|
|
10319
10320
|
linePerspective(enable: boolean): boolean;
|
|
10320
10321
|
linePerspective(): boolean;
|
|
10321
10322
|
|
|
10322
|
-
/**
|
|
10323
|
-
* Restores the default shaders.
|
|
10324
|
-
*
|
|
10325
|
-
* `resetShader()` deactivates any shaders previously applied by
|
|
10326
|
-
* <a href="#/p5/shader">shader()</a>, <a href="#/p5/strokeShader">strokeShader()</a>,
|
|
10327
|
-
* or <a href="#/p5/imageShader">imageShader()</a>.
|
|
10328
|
-
*
|
|
10329
|
-
* Note: Shaders can only be used in WebGL mode.
|
|
10330
|
-
*/
|
|
10331
|
-
resetShader(): void;
|
|
10332
|
-
|
|
10333
10323
|
/**
|
|
10334
10324
|
* Sets an orthographic projection for the current camera in a 3D sketch.
|
|
10335
10325
|
*
|
|
@@ -11679,8 +11669,8 @@ declare class p5 {
|
|
|
11679
11669
|
readonly HSB: typeof HSB;
|
|
11680
11670
|
readonly deviceOrientation: typeof deviceOrientation;
|
|
11681
11671
|
readonly accelerationX: typeof accelerationX;
|
|
11682
|
-
readonly movedX: typeof movedX;
|
|
11683
11672
|
readonly accelerationY: typeof accelerationY;
|
|
11673
|
+
readonly movedX: typeof movedX;
|
|
11684
11674
|
readonly accelerationZ: typeof accelerationZ;
|
|
11685
11675
|
readonly pAccelerationX: typeof pAccelerationX;
|
|
11686
11676
|
readonly pAccelerationY: typeof pAccelerationY;
|
|
@@ -11696,8 +11686,8 @@ declare class p5 {
|
|
|
11696
11686
|
readonly mouseX: typeof mouseX;
|
|
11697
11687
|
readonly rotationZ: typeof rotationZ;
|
|
11698
11688
|
readonly pRotationX: typeof pRotationX;
|
|
11699
|
-
readonly mouseY: typeof mouseY;
|
|
11700
11689
|
readonly pRotationY: typeof pRotationY;
|
|
11690
|
+
readonly mouseY: typeof mouseY;
|
|
11701
11691
|
readonly pRotationZ: typeof pRotationZ;
|
|
11702
11692
|
readonly pmouseX: typeof pmouseX;
|
|
11703
11693
|
readonly code: typeof code;
|
|
@@ -11750,7 +11740,6 @@ declare class p5 {
|
|
|
11750
11740
|
readonly TAU: typeof TAU;
|
|
11751
11741
|
readonly TWO_PI: typeof TWO_PI;
|
|
11752
11742
|
readonly DEG_TO_RAD: typeof DEG_TO_RAD;
|
|
11753
|
-
disableFriendlyErrors: typeof disableFriendlyErrors;
|
|
11754
11743
|
readonly RAD_TO_DEG: typeof RAD_TO_DEG;
|
|
11755
11744
|
readonly CORNER: typeof CORNER;
|
|
11756
11745
|
readonly CORNERS: typeof CORNERS;
|
|
@@ -11767,6 +11756,7 @@ declare class p5 {
|
|
|
11767
11756
|
readonly LINE_STRIP: typeof LINE_STRIP;
|
|
11768
11757
|
readonly LINE_LOOP: typeof LINE_LOOP;
|
|
11769
11758
|
readonly TRIANGLES: typeof TRIANGLES;
|
|
11759
|
+
disableFriendlyErrors: typeof disableFriendlyErrors;
|
|
11770
11760
|
readonly TRIANGLE_FAN: typeof TRIANGLE_FAN;
|
|
11771
11761
|
readonly TRIANGLE_STRIP: typeof TRIANGLE_STRIP;
|
|
11772
11762
|
readonly QUADS: typeof QUADS;
|
|
@@ -11876,8 +11866,8 @@ const P2D: typeof __P2D;
|
|
|
11876
11866
|
const HSB: typeof __HSB;
|
|
11877
11867
|
const deviceOrientation: typeof __deviceOrientation;
|
|
11878
11868
|
const accelerationX: typeof __accelerationX;
|
|
11879
|
-
const movedX: typeof __movedX;
|
|
11880
11869
|
const accelerationY: typeof __accelerationY;
|
|
11870
|
+
const movedX: typeof __movedX;
|
|
11881
11871
|
const accelerationZ: typeof __accelerationZ;
|
|
11882
11872
|
const pAccelerationX: typeof __pAccelerationX;
|
|
11883
11873
|
const pAccelerationY: typeof __pAccelerationY;
|
|
@@ -11893,8 +11883,8 @@ const focused: typeof __focused;
|
|
|
11893
11883
|
const mouseX: typeof __mouseX;
|
|
11894
11884
|
const rotationZ: typeof __rotationZ;
|
|
11895
11885
|
const pRotationX: typeof __pRotationX;
|
|
11896
|
-
const mouseY: typeof __mouseY;
|
|
11897
11886
|
const pRotationY: typeof __pRotationY;
|
|
11887
|
+
const mouseY: typeof __mouseY;
|
|
11898
11888
|
const pRotationZ: typeof __pRotationZ;
|
|
11899
11889
|
const pmouseX: typeof __pmouseX;
|
|
11900
11890
|
const code: typeof __code;
|
|
@@ -11947,7 +11937,6 @@ const QUARTER_PI: typeof __QUARTER_PI;
|
|
|
11947
11937
|
const TAU: typeof __TAU;
|
|
11948
11938
|
const TWO_PI: typeof __TWO_PI;
|
|
11949
11939
|
const DEG_TO_RAD: typeof __DEG_TO_RAD;
|
|
11950
|
-
let disableFriendlyErrors: typeof __disableFriendlyErrors;
|
|
11951
11940
|
const RAD_TO_DEG: typeof __RAD_TO_DEG;
|
|
11952
11941
|
const CORNER: typeof __CORNER;
|
|
11953
11942
|
const CORNERS: typeof __CORNERS;
|
|
@@ -11964,6 +11953,7 @@ const LINES: typeof __LINES;
|
|
|
11964
11953
|
const LINE_STRIP: typeof __LINE_STRIP;
|
|
11965
11954
|
const LINE_LOOP: typeof __LINE_LOOP;
|
|
11966
11955
|
const TRIANGLES: typeof __TRIANGLES;
|
|
11956
|
+
let disableFriendlyErrors: typeof __disableFriendlyErrors;
|
|
11967
11957
|
const TRIANGLE_FAN: typeof __TRIANGLE_FAN;
|
|
11968
11958
|
const TRIANGLE_STRIP: typeof __TRIANGLE_STRIP;
|
|
11969
11959
|
const QUADS: typeof __QUADS;
|
|
@@ -13020,23 +13010,27 @@ const EXCLUDE: typeof __EXCLUDE;
|
|
|
13020
13010
|
* plane(width, height); // Draw a plane with the shader applied
|
|
13021
13011
|
* }`In addition to calling hooks, you can create uniforms, which are special variables
|
|
13022
13012
|
* used to pass data from p5.js into the shader. They can be created by calling `uniform` + the
|
|
13023
|
-
* type of the data, such as `uniformFloat` for a number
|
|
13013
|
+
* type of the data, such as `uniformFloat` for a number or `uniformVector2` for a two-component vector.
|
|
13024
13014
|
* They take in a function that returns the data for the variable. You can then reference these
|
|
13025
13015
|
* variables in your hooks, and their values will update every time you apply
|
|
13026
13016
|
* the shader with the result of your function.
|
|
13027
13017
|
*
|
|
13018
|
+
* Move the mouse over this sketch to increase the moveCounter which will be passed to the shader as a uniform.
|
|
13019
|
+
*
|
|
13028
13020
|
* `let myShader;
|
|
13021
|
+
* //count of frames in which mouse has been moved
|
|
13022
|
+
* let moveCounter = 0;
|
|
13029
13023
|
*
|
|
13030
13024
|
* function setup() {
|
|
13031
13025
|
* createCanvas(200, 200, WEBGL);
|
|
13032
13026
|
* myShader = baseMaterialShader().modify(() => {
|
|
13033
|
-
* // Get the
|
|
13034
|
-
* let
|
|
13027
|
+
* // Get the move counter from our sketch
|
|
13028
|
+
* let count = uniformFloat(() => moveCounter);
|
|
13035
13029
|
*
|
|
13036
13030
|
* getPixelInputs((inputs) => {
|
|
13037
13031
|
* inputs.color = [
|
|
13038
13032
|
* inputs.texCoord,
|
|
13039
|
-
* sin(
|
|
13033
|
+
* sin(count/100) / 2 + 0.5,
|
|
13040
13034
|
* 1,
|
|
13041
13035
|
* ];
|
|
13042
13036
|
* return inputs;
|
|
@@ -13044,6 +13038,10 @@ const EXCLUDE: typeof __EXCLUDE;
|
|
|
13044
13038
|
* });
|
|
13045
13039
|
* }
|
|
13046
13040
|
*
|
|
13041
|
+
* function mouseDragged(){
|
|
13042
|
+
* moveCounter += 1;
|
|
13043
|
+
* }
|
|
13044
|
+
*
|
|
13047
13045
|
* function draw() {
|
|
13048
13046
|
* background(255);
|
|
13049
13047
|
* noStroke(255);
|