p5 2.2.1 → 2.2.2-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.
Files changed (94) hide show
  1. package/dist/accessibility/color_namer.js +6 -6
  2. package/dist/accessibility/index.js +6 -6
  3. package/dist/app.js +6 -6
  4. package/dist/color/color_conversion.js +6 -6
  5. package/dist/color/creating_reading.js +1 -1
  6. package/dist/color/index.js +2 -2
  7. package/dist/color/p5.Color.js +1 -1
  8. package/dist/color/setting.js +2 -2
  9. package/dist/{constants-DQyACdzq.js → constants-DAnmXDew.js} +1 -1
  10. package/dist/core/constants.js +1 -1
  11. package/dist/core/environment.js +1 -1
  12. package/dist/core/filterShaders.js +1 -1
  13. package/dist/core/friendly_errors/fes_core.js +1 -1
  14. package/dist/core/friendly_errors/file_errors.js +1 -1
  15. package/dist/core/friendly_errors/index.js +1 -1
  16. package/dist/core/friendly_errors/param_validator.js +1 -1
  17. package/dist/core/friendly_errors/sketch_verifier.js +2 -2
  18. package/dist/core/helpers.js +1 -1
  19. package/dist/core/init.js +6 -6
  20. package/dist/core/internationalization.js +1 -1
  21. package/dist/core/legacy.js +6 -6
  22. package/dist/core/main.js +6 -6
  23. package/dist/core/p5.Graphics.js +4 -4
  24. package/dist/core/p5.Renderer.js +3 -3
  25. package/dist/core/p5.Renderer2D.js +6 -6
  26. package/dist/core/p5.Renderer3D.js +4 -4
  27. package/dist/core/rendering.js +4 -4
  28. package/dist/{creating_reading-ZXzcZEsb.js → creating_reading-C7hu6sg1.js} +2 -2
  29. package/dist/dom/dom.js +2 -2
  30. package/dist/dom/index.js +2 -2
  31. package/dist/dom/p5.Element.js +2 -2
  32. package/dist/dom/p5.MediaElement.js +2 -2
  33. package/dist/image/const.js +1 -1
  34. package/dist/image/filterRenderer2D.js +5 -5
  35. package/dist/image/image.js +4 -4
  36. package/dist/image/index.js +4 -4
  37. package/dist/image/loading_displaying.js +4 -4
  38. package/dist/image/p5.Image.js +3 -3
  39. package/dist/io/files.js +4 -4
  40. package/dist/io/index.js +4 -4
  41. package/dist/{ir_builders-DXNgaB9N.js → ir_builders-w12-GSxu.js} +37 -5
  42. package/dist/{main-DvN69W3f.js → main-E-swj5tF.js} +4 -4
  43. package/dist/math/Matrices/Matrix.js +1 -1
  44. package/dist/math/Matrices/MatrixNumjs.js +1 -1
  45. package/dist/math/index.js +1 -1
  46. package/dist/math/p5.Matrix.js +1 -1
  47. package/dist/math/p5.Vector.js +1 -1
  48. package/dist/math/trigonometry.js +1 -1
  49. package/dist/{p5.Renderer-D-5LdCRz.js → p5.Renderer-DOk9UW65.js} +2 -2
  50. package/dist/{rendering-h9unX5K0.js → rendering-B8V5Zt4k.js} +58 -14
  51. package/dist/shape/2d_primitives.js +1 -1
  52. package/dist/shape/attributes.js +1 -1
  53. package/dist/shape/custom_shapes.js +2 -2
  54. package/dist/shape/index.js +2 -2
  55. package/dist/strands/ir_builders.js +1 -1
  56. package/dist/strands/p5.strands.js +1 -1
  57. package/dist/strands/strands_api.js +91 -31
  58. package/dist/strands/strands_conditionals.js +1 -1
  59. package/dist/strands/strands_for.js +2 -2
  60. package/dist/strands/strands_node.js +1 -1
  61. package/dist/type/index.js +3 -3
  62. package/dist/type/p5.Font.js +3 -3
  63. package/dist/type/textCore.js +3 -3
  64. package/dist/webgl/3d_primitives.js +4 -4
  65. package/dist/webgl/GeometryBuilder.js +1 -1
  66. package/dist/webgl/ShapeBuilder.js +1 -1
  67. package/dist/webgl/enums.js +1 -1
  68. package/dist/webgl/index.js +5 -5
  69. package/dist/webgl/interaction.js +1 -1
  70. package/dist/webgl/light.js +4 -4
  71. package/dist/webgl/loading.js +12 -14
  72. package/dist/webgl/material.js +4 -4
  73. package/dist/webgl/p5.Camera.js +4 -4
  74. package/dist/webgl/p5.Framebuffer.js +4 -4
  75. package/dist/webgl/p5.Geometry.js +1 -1
  76. package/dist/webgl/p5.Quat.js +1 -1
  77. package/dist/webgl/p5.RendererGL.js +5 -5
  78. package/dist/webgl/p5.Texture.js +4 -4
  79. package/dist/webgl/strands_glslBackend.js +1 -1
  80. package/dist/webgl/text.js +5 -5
  81. package/dist/webgl/utils.js +4 -4
  82. package/dist/webgpu/index.js +2 -2
  83. package/dist/webgpu/p5.RendererWebGPU.js +13 -4
  84. package/dist/webgpu/strands_wgslBackend.js +5 -4
  85. package/lib/p5.esm.js +196 -62
  86. package/lib/p5.esm.min.js +1 -1
  87. package/lib/p5.js +196 -62
  88. package/lib/p5.min.js +1 -1
  89. package/lib/p5.webgpu.esm.js +51 -9
  90. package/lib/p5.webgpu.js +51 -9
  91. package/lib/p5.webgpu.min.js +1 -1
  92. package/package.json +1 -1
  93. package/types/global.d.ts +1453 -1383
  94. package/types/p5.d.ts +729 -694
package/types/global.d.ts CHANGED
@@ -5153,6 +5153,112 @@ EXCLUDE: typeof P5.EXCLUDE;
5153
5153
  min(n0: number, n1: number): number;
5154
5154
  min(nums: number[]): number;
5155
5155
 
5156
+ /**
5157
+ * A function that's called when the browser window is resized.
5158
+ *
5159
+ * Code placed in the body of `windowResized()` will run when the
5160
+ * browser window's size changes. It's a good place to call
5161
+ * <a href="#/p5/resizeCanvas">resizeCanvas()</a> or make other
5162
+ * adjustments to accommodate the new window size.
5163
+ *
5164
+ * The `event` parameter is optional. If added to the function declaration, it
5165
+ * can be used for debugging or other purposes.
5166
+ * @param event optional resize Event.
5167
+ */
5168
+ windowResized(event?: Event): void;
5169
+
5170
+ /**
5171
+ * Shuffles the elements of an array.
5172
+ *
5173
+ * The first parameter, `array`, is the array to be shuffled. For example,
5174
+ * calling `shuffle(myArray)` will shuffle the elements of `myArray`. By
5175
+ * default, the original array won’t be modified. Instead, a copy will be
5176
+ * created, shuffled, and returned.
5177
+ *
5178
+ * The second parameter, `modify`, is optional. If `true` is passed, as in
5179
+ * `shuffle(myArray, true)`, then the array will be shuffled in place without
5180
+ * making a copy.
5181
+ * @param array array to shuffle.
5182
+ * @param modify if `true`, shuffle the original array in place. Defaults to `false`.
5183
+ * @returns shuffled array.
5184
+ */
5185
+ shuffle<T>(array: T[], modify?: boolean): T[];
5186
+
5187
+ /**
5188
+ * This method is suitable for fetching files up to size of 64MB.
5189
+ * @param file name of the file or URL to load
5190
+ * @param callback function to be executed after <a href="#/p5/loadBytes">loadBytes()</a>
5191
+ * completes
5192
+ * @param errorCallback function to be executed if there
5193
+ * is an error
5194
+ * @returns a Uint8Array containing the loaded buffer
5195
+ */
5196
+ loadBytes(file: string | Request, callback?: Function, errorCallback?: Function): Promise<Uint8Array>;
5197
+
5198
+ /**
5199
+ * Turns off <a href="#/p5/debugMode">debugMode()</a> in a 3D sketch.
5200
+ */
5201
+ noDebugMode(): void;
5202
+
5203
+ /**
5204
+ * Gets the blue value of a color.
5205
+ *
5206
+ * `blue()` extracts the blue value from a
5207
+ * <a href="/reference/p5/p5.Color/">p5.Color</a> object, an array of color components, or
5208
+ * a CSS color string.
5209
+ *
5210
+ * By default, `blue()` returns a color's blue value in the range 0
5211
+ * to 255. If the <a href="/reference/p5/colorMode/">colorMode()</a> is set to RGB, it
5212
+ * returns the blue value in the given range.
5213
+ * @param color <a href="/reference/p5/p5.Color/">p5.Color</a> object, array of
5214
+ * color components, or CSS color string.
5215
+ * @returns the blue value.
5216
+ */
5217
+ blue(color: P5.Color | number[] | string): number;
5218
+
5219
+ /**
5220
+ * Converts a single-character `String` to a `Number`.
5221
+ *
5222
+ * `unchar()` converts single-character strings to their corresponding
5223
+ * integer (whole number).
5224
+ *
5225
+ * The parameter, `n`, is the character to convert. For example,
5226
+ * `unchar('A')`, returns the number 65. If an array is passed, as in
5227
+ * `unchar(['A', 'B', 'C'])`, an array of integers is returned.
5228
+ * @param n value to convert.
5229
+ * @returns converted number.
5230
+ */
5231
+ unchar(n: string): number;
5232
+ unchar(ns: string[]): number[];
5233
+
5234
+ /**
5235
+ * Changes the unit system used to measure angles.
5236
+ *
5237
+ * Degrees and radians are both units for measuring angles. There are 360˚ in
5238
+ * one full rotation. A full rotation is 2 × π (about 6.28) radians.
5239
+ *
5240
+ * Functions such as <a href="#/p5/rotate">rotate()</a> and
5241
+ * <a href="#/p5/sin">sin()</a> expect angles measured radians by default.
5242
+ * Calling `angleMode(DEGREES)` switches to degrees. Calling
5243
+ * `angleMode(RADIANS)` switches back to radians.
5244
+ *
5245
+ * Calling `angleMode()` with no arguments returns current angle mode, which
5246
+ * is either `RADIANS` or `DEGREES`.
5247
+ * @param mode either RADIANS or DEGREES.
5248
+ * @returns mode either RADIANS or DEGREES
5249
+ */
5250
+ angleMode(mode: typeof P5.RADIANS | typeof P5.DEGREES): typeof P5.RADIANS | typeof P5.DEGREES;
5251
+ angleMode(): typeof P5.RADIANS | typeof P5.DEGREES;
5252
+
5253
+ /**
5254
+ * Loads the current value of each pixel on the canvas into the
5255
+ * <a href="#/p5/pixels">pixels</a> array.
5256
+ *
5257
+ * `loadPixels()` must be called before reading from or writing to
5258
+ * <a href="#/p5/pixels">pixels</a>.
5259
+ */
5260
+ loadPixels(): void;
5261
+
5156
5262
  /**
5157
5263
  * Creates a <a href="#/p5.Shader">p5.Shader</a> object to be used with the
5158
5264
  * <a href="#/p5/filter">filter()</a> function.
@@ -5272,6 +5378,36 @@ EXCLUDE: typeof P5.EXCLUDE;
5272
5378
  * function draw() {
5273
5379
  * myFilter.setUniform('time', millis());
5274
5380
  * filter(myFilter);
5381
+ * }`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 passing in an announced uniform variable `time` with `setUniform()`, each frame.
5382
+ *
5383
+ * `let myFilter;
5384
+ *
5385
+ * function setup() {
5386
+ * createCanvas(100, 100, WEBGL);
5387
+ * myFilter = buildFilterShader(noiseShaderCallback);
5388
+ * describe('Evolving animated cloud-like noise in cyan and magenta');
5389
+ * }
5390
+ *
5391
+ * function noiseShaderCallback() {
5392
+ * let time = uniformFloat();
5393
+ * filterColor.begin();
5394
+ * let coord = filterColor.texCoord;
5395
+ *
5396
+ * //generate a value roughly between 0 and 1
5397
+ * let noiseVal = noise(coord.x, coord.y, time / 2000);
5398
+ *
5399
+ * let result = mix(
5400
+ * [1, 0, 1, 1], // Magenta
5401
+ * [0, 1, 1, 1], // Cyan
5402
+ * noiseVal
5403
+ * );
5404
+ * filterColor.set(result);
5405
+ * filterColor.end();
5406
+ * }
5407
+ *
5408
+ * function draw() {
5409
+ * myFilter.setUniform("time", millis());
5410
+ * filter(myFilter);
5275
5411
  * }`Like the `modify()` method on shaders,
5276
5412
  * 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>
5277
5413
  * instead of JavaScript.
@@ -5282,116 +5418,11 @@ EXCLUDE: typeof P5.EXCLUDE;
5282
5418
  * For more info about filters and shaders, see Adam Ferriss' <a href="https://github.com/aferriss/p5jsShaderExamples">repo of shader examples</a>
5283
5419
  * or the <a href="https://p5js.org/learn/getting-started-in-webgl-shaders.html">Introduction to Shaders</a> tutorial.
5284
5420
  * @param callback A function building a p5.strands shader.
5421
+ * @param scope An optional scope object passed to .modify().
5285
5422
  * @returns The material shader
5286
5423
  */
5287
- buildFilterShader(callback: Function): P5.Shader;
5288
- buildFilterShader(hooks: object): P5.Shader;
5289
-
5290
- /**
5291
- * A function that's called when the browser window is resized.
5292
- *
5293
- * Code placed in the body of `windowResized()` will run when the
5294
- * browser window's size changes. It's a good place to call
5295
- * <a href="#/p5/resizeCanvas">resizeCanvas()</a> or make other
5296
- * adjustments to accommodate the new window size.
5297
- *
5298
- * The `event` parameter is optional. If added to the function declaration, it
5299
- * can be used for debugging or other purposes.
5300
- * @param event optional resize Event.
5301
- */
5302
- windowResized(event?: Event): void;
5303
-
5304
- /**
5305
- * Shuffles the elements of an array.
5306
- *
5307
- * The first parameter, `array`, is the array to be shuffled. For example,
5308
- * calling `shuffle(myArray)` will shuffle the elements of `myArray`. By
5309
- * default, the original array won’t be modified. Instead, a copy will be
5310
- * created, shuffled, and returned.
5311
- *
5312
- * The second parameter, `modify`, is optional. If `true` is passed, as in
5313
- * `shuffle(myArray, true)`, then the array will be shuffled in place without
5314
- * making a copy.
5315
- * @param array array to shuffle.
5316
- * @param modify if `true`, shuffle the original array in place. Defaults to `false`.
5317
- * @returns shuffled array.
5318
- */
5319
- shuffle<T>(array: T[], modify?: boolean): T[];
5320
-
5321
- /**
5322
- * This method is suitable for fetching files up to size of 64MB.
5323
- * @param file name of the file or URL to load
5324
- * @param callback function to be executed after <a href="#/p5/loadBytes">loadBytes()</a>
5325
- * completes
5326
- * @param errorCallback function to be executed if there
5327
- * is an error
5328
- * @returns a Uint8Array containing the loaded buffer
5329
- */
5330
- loadBytes(file: string | Request, callback?: Function, errorCallback?: Function): Promise<Uint8Array>;
5331
-
5332
- /**
5333
- * Turns off <a href="#/p5/debugMode">debugMode()</a> in a 3D sketch.
5334
- */
5335
- noDebugMode(): void;
5336
-
5337
- /**
5338
- * Gets the blue value of a color.
5339
- *
5340
- * `blue()` extracts the blue value from a
5341
- * <a href="/reference/p5/p5.Color/">p5.Color</a> object, an array of color components, or
5342
- * a CSS color string.
5343
- *
5344
- * By default, `blue()` returns a color's blue value in the range 0
5345
- * to 255. If the <a href="/reference/p5/colorMode/">colorMode()</a> is set to RGB, it
5346
- * returns the blue value in the given range.
5347
- * @param color <a href="/reference/p5/p5.Color/">p5.Color</a> object, array of
5348
- * color components, or CSS color string.
5349
- * @returns the blue value.
5350
- */
5351
- blue(color: P5.Color | number[] | string): number;
5352
-
5353
- /**
5354
- * Converts a single-character `String` to a `Number`.
5355
- *
5356
- * `unchar()` converts single-character strings to their corresponding
5357
- * integer (whole number).
5358
- *
5359
- * The parameter, `n`, is the character to convert. For example,
5360
- * `unchar('A')`, returns the number 65. If an array is passed, as in
5361
- * `unchar(['A', 'B', 'C'])`, an array of integers is returned.
5362
- * @param n value to convert.
5363
- * @returns converted number.
5364
- */
5365
- unchar(n: string): number;
5366
- unchar(ns: string[]): number[];
5367
-
5368
- /**
5369
- * Changes the unit system used to measure angles.
5370
- *
5371
- * Degrees and radians are both units for measuring angles. There are 360˚ in
5372
- * one full rotation. A full rotation is 2 × π (about 6.28) radians.
5373
- *
5374
- * Functions such as <a href="#/p5/rotate">rotate()</a> and
5375
- * <a href="#/p5/sin">sin()</a> expect angles measured radians by default.
5376
- * Calling `angleMode(DEGREES)` switches to degrees. Calling
5377
- * `angleMode(RADIANS)` switches back to radians.
5378
- *
5379
- * Calling `angleMode()` with no arguments returns current angle mode, which
5380
- * is either `RADIANS` or `DEGREES`.
5381
- * @param mode either RADIANS or DEGREES.
5382
- * @returns mode either RADIANS or DEGREES
5383
- */
5384
- angleMode(mode: typeof P5.RADIANS | typeof P5.DEGREES): typeof P5.RADIANS | typeof P5.DEGREES;
5385
- angleMode(): typeof P5.RADIANS | typeof P5.DEGREES;
5386
-
5387
- /**
5388
- * Loads the current value of each pixel on the canvas into the
5389
- * <a href="#/p5/pixels">pixels</a> array.
5390
- *
5391
- * `loadPixels()` must be called before reading from or writing to
5392
- * <a href="#/p5/pixels">pixels</a>.
5393
- */
5394
- loadPixels(): void;
5424
+ buildFilterShader(callback: Function, scope?: object): P5.Shader;
5425
+ buildFilterShader(hooks: object, scope?: object): P5.Shader;
5395
5426
 
5396
5427
  /**
5397
5428
  * Creates a slider `&lt;input&gt;&lt;/input&gt;` element.
@@ -5557,53 +5588,14 @@ EXCLUDE: typeof P5.EXCLUDE;
5557
5588
  fullscreen(val?: boolean): boolean;
5558
5589
 
5559
5590
  /**
5560
- * Creates a <a href="#/p5.Shader">p5.Shader</a> object to be used with the
5561
- * <a href="#/p5/filter">filter()</a> function using GLSL.
5562
- *
5563
- * Since this method requires you to write your shaders in GLSL, it is most suitable
5564
- * for advanced use cases. Consider using <a href="#/p5/buildFilterShader">`buildFilterShader`</a>
5565
- * first, as a way to create filters in JavaScript using p5.strands.
5566
- *
5567
- * `createFilterShader()` works like
5568
- * <a href="#/p5/createShader">createShader()</a> but has a default vertex
5569
- * shader included. `createFilterShader()` is intended to be used along with
5570
- * <a href="#/p5/filter">filter()</a> for filtering the contents of a canvas.
5571
- * A filter shader will be applied to the whole canvas instead of just
5572
- * <a href="#/p5.Geometry">p5.Geometry</a> objects.
5591
+ * Creates a light that shines from a point in all directions.
5573
5592
  *
5574
- * The parameter, `fragSrc`, sets the fragment shader. It’s a string that
5575
- * contains the fragment shader program written in
5576
- * <a href="https://developer.mozilla.org/en-US/docs/Games/Techniques/3D_on_the_web/GLSL_Shaders" target="_blank">GLSL</a>.
5593
+ * Point lights are like light bulbs that shine in all directions. They can be
5594
+ * placed at different positions to achieve different lighting effects. A
5595
+ * maximum of 5 point lights can be active at once.
5577
5596
  *
5578
- * The <a href="#/p5.Shader">p5.Shader</a> object that's created has some
5579
- * uniforms that can be set:
5580
- *
5581
- * - `sampler2D tex0`, which contains the canvas contents as a texture.
5582
- *
5583
- * - `vec2 canvasSize`, which is the width and height of the canvas, not including pixel density.
5584
- *
5585
- * - `vec2 texelSize`, which is the size of a physical pixel including pixel density. This is calculated as `1.0 / (width * density)` for the pixel width and `1.0 / (height * density)` for the pixel height.
5586
- *
5587
- * The <a href="#/p5.Shader">p5.Shader</a> that's created also provides
5588
- * `varying vec2 vTexCoord`, a coordinate with values between 0 and 1.
5589
- * `vTexCoord` describes where on the canvas the pixel will be drawn.
5590
- *
5591
- * For more info about filters and shaders, see Adam Ferriss' <a href="https://github.com/aferriss/p5jsShaderExamples">repo of shader examples</a>
5592
- * or the <a href="https://p5js.org/learn/getting-started-in-webgl-shaders.html">Introduction to Shaders</a> tutorial.
5593
- * @param fragSrc source code for the fragment shader.
5594
- * @returns new shader object created from the fragment shader.
5595
- */
5596
- createFilterShader(fragSrc: string): P5.Shader;
5597
-
5598
- /**
5599
- * Creates a light that shines from a point in all directions.
5600
- *
5601
- * Point lights are like light bulbs that shine in all directions. They can be
5602
- * placed at different positions to achieve different lighting effects. A
5603
- * maximum of 5 point lights can be active at once.
5604
- *
5605
- * There are four ways to call `pointLight()` with parameters to set the
5606
- * light’s color and position.
5597
+ * There are four ways to call `pointLight()` with parameters to set the
5598
+ * light’s color and position.
5607
5599
  *
5608
5600
  * The first way to call `pointLight()` has six parameters. The first three
5609
5601
  * parameters, `v1`, `v2`, and `v3`, set the light’s color using the current
@@ -5702,6 +5694,45 @@ EXCLUDE: typeof P5.EXCLUDE;
5702
5694
  */
5703
5695
  createButton(label: string, value?: string): P5.Element;
5704
5696
 
5697
+ /**
5698
+ * Creates a <a href="#/p5.Shader">p5.Shader</a> object to be used with the
5699
+ * <a href="#/p5/filter">filter()</a> function using GLSL.
5700
+ *
5701
+ * Since this method requires you to write your shaders in GLSL, it is most suitable
5702
+ * for advanced use cases. Consider using <a href="#/p5/buildFilterShader">`buildFilterShader`</a>
5703
+ * first, as a way to create filters in JavaScript using p5.strands.
5704
+ *
5705
+ * `createFilterShader()` works like
5706
+ * <a href="#/p5/createShader">createShader()</a> but has a default vertex
5707
+ * shader included. `createFilterShader()` is intended to be used along with
5708
+ * <a href="#/p5/filter">filter()</a> for filtering the contents of a canvas.
5709
+ * A filter shader will be applied to the whole canvas instead of just
5710
+ * <a href="#/p5.Geometry">p5.Geometry</a> objects.
5711
+ *
5712
+ * The parameter, `fragSrc`, sets the fragment shader. It’s a string that
5713
+ * contains the fragment shader program written in
5714
+ * <a href="https://developer.mozilla.org/en-US/docs/Games/Techniques/3D_on_the_web/GLSL_Shaders" target="_blank">GLSL</a>.
5715
+ *
5716
+ * The <a href="#/p5.Shader">p5.Shader</a> object that's created has some
5717
+ * uniforms that can be set:
5718
+ *
5719
+ * - `sampler2D tex0`, which contains the canvas contents as a texture.
5720
+ *
5721
+ * - `vec2 canvasSize`, which is the width and height of the canvas, not including pixel density.
5722
+ *
5723
+ * - `vec2 texelSize`, which is the size of a physical pixel including pixel density. This is calculated as `1.0 / (width * density)` for the pixel width and `1.0 / (height * density)` for the pixel height.
5724
+ *
5725
+ * The <a href="#/p5.Shader">p5.Shader</a> that's created also provides
5726
+ * `varying vec2 vTexCoord`, a coordinate with values between 0 and 1.
5727
+ * `vTexCoord` describes where on the canvas the pixel will be drawn.
5728
+ *
5729
+ * For more info about filters and shaders, see Adam Ferriss' <a href="https://github.com/aferriss/p5jsShaderExamples">repo of shader examples</a>
5730
+ * or the <a href="https://p5js.org/learn/getting-started-in-webgl-shaders.html">Introduction to Shaders</a> tutorial.
5731
+ * @param fragSrc source code for the fragment shader.
5732
+ * @returns new shader object created from the fragment shader.
5733
+ */
5734
+ createFilterShader(fragSrc: string): P5.Shader;
5735
+
5705
5736
  /**
5706
5737
  * Concludes the vertices of a custom shape.
5707
5738
  *
@@ -6379,169 +6410,6 @@ EXCLUDE: typeof P5.EXCLUDE;
6379
6410
  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;
6380
6411
  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;
6381
6412
 
6382
- /**
6383
- * Sets the <a href="#/p5.Shader">p5.Shader</a> object to apply while drawing.
6384
- *
6385
- * Shaders are programs that run on the graphics processing unit (GPU). They
6386
- * can process many pixels or vertices at the same time, making them fast for
6387
- * many graphics tasks.
6388
- *
6389
- * You can make new shaders using p5.strands with the
6390
- * <a href="#/p5/buildMaterialShader">`buildMaterialShader`</a>,
6391
- * <a href="#/p5/buildColorShader">`buildColorShader`</a>, and
6392
- * <a href="#/p5/buildNormalShader">`buildNormalShader`</a> functions. You can also use
6393
- * <a href="#/p5/buildFilterShader">`buildFilterShader`</a> alongside
6394
- * <a href="#/p5/filter">`filter`</a>, and
6395
- * <a href="#/p5/buildStrokeShader">`buildStrokeShader`</a> alongside
6396
- * <a href="#/p5/stroke">`stroke`</a>.
6397
- *
6398
- * The parameter, `s`, is the <a href="#/p5.Shader">p5.Shader</a> object to
6399
- * apply. For example, calling `shader(myShader)` applies `myShader` to
6400
- * process each pixel on the canvas. This only changes the fill (the inner part of shapes),
6401
- * but does not affect the outlines (strokes) or any images drawn using the `image()` function.
6402
- * The source code from a <a href="#/p5.Shader">p5.Shader</a> object's
6403
- * fragment and vertex shaders will be compiled the first time it's passed to
6404
- * `shader()`.
6405
- *
6406
- * Calling <a href="#/p5/resetShader">resetShader()</a> restores a sketch’s
6407
- * default shaders.
6408
- *
6409
- * Note: Shaders can only be used in WebGL mode.
6410
- *
6411
- * `let myShader;
6412
- *
6413
- * function setup() {
6414
- * createCanvas(200, 200, WEBGL);
6415
- * myShader = buildMaterialShader(material);
6416
- * noStroke();
6417
- * describe('A square with dynamically changing colors on a beige background.');
6418
- * }
6419
- *
6420
- * function material() {
6421
- * let time = uniformFloat();
6422
- * finalColor.begin();
6423
- * let r = 0.2 + 0.5 * abs(sin(time + 0));
6424
- * let g = 0.2 + 0.5 * abs(sin(time + 1));
6425
- * let b = 0.2 + 0.5 * abs(sin(time + 2));
6426
- * finalColor.set([r, g, b, 1]);
6427
- * finalColor.end();
6428
- * }
6429
- *
6430
- * function draw() {
6431
- * background(245, 245, 220);
6432
- * myShader.setUniform('time', millis() / 1000);
6433
- * shader(myShader);
6434
- *
6435
- * rectMode(CENTER);
6436
- * rect(0, 0, 50, 50);
6437
- * }`For advanced usage, shaders can be written in a language called
6438
- * <a href="https://developer.mozilla.org/en-US/docs/Games/Techniques/3D_on_the_web/GLSL_Shaders" target="_blank">GLSL</a>.
6439
- * <a href="#/p5.Shader">p5.Shader</a> objects can be created in this way using the
6440
- * <a href="#/p5/createShader">createShader()</a> and
6441
- * <a href="#/p5/loadShader">loadShader()</a> functions.
6442
- *
6443
- * `let fillShader;
6444
- *
6445
- * let vertSrc = `
6446
- * precision highp float;
6447
- * attribute vec3 aPosition;
6448
- * uniform mat4 uModelViewMatrix;
6449
- * uniform mat4 uProjectionMatrix;
6450
- * varying vec3 vPosition;
6451
- *
6452
- * void main() {
6453
- * vPosition = aPosition;
6454
- * gl_Position = uProjectionMatrix * uModelViewMatrix * vec4(aPosition, 1.0);
6455
- * }
6456
- * `;
6457
- *
6458
- * let fragSrc = `
6459
- * precision highp float;
6460
- * uniform vec3 uLightDir;
6461
- * varying vec3 vPosition;
6462
- *
6463
- * void main() {
6464
- * vec3 lightDir = normalize(uLightDir);
6465
- * float brightness = dot(lightDir, normalize(vPosition));
6466
- * brightness = clamp(brightness, 0.4, 1.0);
6467
- * vec3 color = vec3(0.3, 0.5, 1.0);
6468
- * color = color * brightness * 3.0;
6469
- * gl_FragColor = vec4(color, 1.0);
6470
- * }
6471
- * `;
6472
- *
6473
- * function setup() {
6474
- * createCanvas(200, 200, WEBGL);
6475
- * fillShader = createShader(vertSrc, fragSrc);
6476
- * noStroke();
6477
- * describe('A rotating torus with simulated directional lighting.');
6478
- * }
6479
- *
6480
- * function draw() {
6481
- * background(20, 20, 40);
6482
- * let lightDir = [0.5, 0.5, 1.0];
6483
- * fillShader.setUniform('uLightDir', lightDir);
6484
- * shader(fillShader);
6485
- * rotateY(frameCount * 0.02);
6486
- * rotateX(frameCount * 0.02);
6487
- * torus(25, 10, 30, 30);
6488
- * }``let fillShader;
6489
- *
6490
- * let vertSrc = `
6491
- * precision highp float;
6492
- * attribute vec3 aPosition;
6493
- * uniform mat4 uProjectionMatrix;
6494
- * uniform mat4 uModelViewMatrix;
6495
- * varying vec3 vPosition;
6496
- * void main() {
6497
- * vPosition = aPosition;
6498
- * gl_Position = uProjectionMatrix * uModelViewMatrix * vec4(aPosition, 1.0);
6499
- * }
6500
- * `;
6501
- *
6502
- * let fragSrc = `
6503
- * precision highp float;
6504
- * uniform vec3 uLightPos;
6505
- * uniform vec3 uFillColor;
6506
- * varying vec3 vPosition;
6507
- * void main() {
6508
- * float brightness = dot(normalize(uLightPos), normalize(vPosition));
6509
- * brightness = clamp(brightness, 0.0, 1.0);
6510
- * vec3 color = uFillColor * brightness;
6511
- * gl_FragColor = vec4(color, 1.0);
6512
- * }
6513
- * `;
6514
- *
6515
- * function setup() {
6516
- * createCanvas(200, 200, WEBGL);
6517
- * fillShader = createShader(vertSrc, fragSrc);
6518
- * shader(fillShader);
6519
- * noStroke();
6520
- * describe('A square affected by both fill color and lighting, with lights controlled by mouse.');
6521
- * }
6522
- *
6523
- * function draw() {
6524
- * let lightPos = [(mouseX - width / 2) / width,
6525
- * (mouseY - height / 2) / height, 1.0];
6526
- * fillShader.setUniform('uLightPos', lightPos);
6527
- * let fillColor = [map(mouseX, 0, width, 0, 1),
6528
- * map(mouseY, 0, height, 0, 1), 0.5];
6529
- * fillShader.setUniform('uFillColor', fillColor);
6530
- * plane(width, height);
6531
- * }`<div>
6532
- * <p>If you want to apply shaders to strokes or images, use the following methods:
6533
- *
6534
- * - <a href="#/p5/strokeShader">strokeShader()</a> : Applies a shader to the stroke (outline) of shapes, allowing independent control over the stroke rendering using shaders.
6535
- *
6536
- * - <a href="#/p5/imageShader">imageShader()</a> : Applies a shader to images or textures, controlling how the shader modifies their appearance during rendering.
6537
- *
6538
- * </p>
6539
- * </div>
6540
- * @param s <a href="#/p5.Shader">p5.Shader</a> object
6541
- * to apply.
6542
- */
6543
- shader(s: P5.Shader): void;
6544
-
6545
6413
  /**
6546
6414
  * Returns the current
6547
6415
  * <a href="https://developer.mozilla.org/en-US/docs/Learn/Common_questions/Web_mechanics/What_is_a_URL#parameters" target="_blank">URL parameters</a>
@@ -6773,25 +6641,177 @@ EXCLUDE: typeof P5.EXCLUDE;
6773
6641
  keyIsDown(code: number | string): boolean;
6774
6642
 
6775
6643
  /**
6776
- * Sets the element's content.
6644
+ * Sets the <a href="#/p5.Shader">p5.Shader</a> object to apply while drawing.
6777
6645
  *
6778
- * An element's content is the text between its tags. For example, the element
6779
- * `&lt;language&gt;JavaScript&lt;/language&gt;` has the content `JavaScript`.
6646
+ * Shaders are programs that run on the graphics processing unit (GPU). They
6647
+ * can process many pixels or vertices at the same time, making them fast for
6648
+ * many graphics tasks.
6780
6649
  *
6781
- * The parameter, `content`, is a string with the element's new content.
6782
- * @param content new content for the element.
6783
- */
6784
- setContent(content: string): void;
6785
-
6786
- /**
6787
- * Draws a <a href="#/p5.Geometry">p5.Geometry</a> object to the canvas.
6650
+ * You can make new shaders using p5.strands with the
6651
+ * <a href="#/p5/buildMaterialShader">`buildMaterialShader`</a>,
6652
+ * <a href="#/p5/buildColorShader">`buildColorShader`</a>, and
6653
+ * <a href="#/p5/buildNormalShader">`buildNormalShader`</a> functions. You can also use
6654
+ * <a href="#/p5/buildFilterShader">`buildFilterShader`</a> alongside
6655
+ * <a href="#/p5/filter">`filter`</a>, and
6656
+ * <a href="#/p5/buildStrokeShader">`buildStrokeShader`</a> alongside
6657
+ * <a href="#/p5/stroke">`stroke`</a>.
6788
6658
  *
6789
- * The parameter, `model`, is the
6790
- * <a href="#/p5.Geometry">p5.Geometry</a> object to draw.
6791
- * <a href="#/p5.Geometry">p5.Geometry</a> objects can be built with
6792
- * <a href="#/p5/buildGeometry">buildGeometry()</a>, or
6793
- * <a href="#/p5/beginGeometry">beginGeometry()</a> and
6794
- * <a href="#/p5/endGeometry">endGeometry()</a>. They can also be loaded from
6659
+ * The parameter, `s`, is the <a href="#/p5.Shader">p5.Shader</a> object to
6660
+ * apply. For example, calling `shader(myShader)` applies `myShader` to
6661
+ * process each pixel on the canvas. This only changes the fill (the inner part of shapes),
6662
+ * but does not affect the outlines (strokes) or any images drawn using the `image()` function.
6663
+ * The source code from a <a href="#/p5.Shader">p5.Shader</a> object's
6664
+ * fragment and vertex shaders will be compiled the first time it's passed to
6665
+ * `shader()`.
6666
+ *
6667
+ * Calling <a href="#/p5/resetShader">resetShader()</a> restores a sketch’s
6668
+ * default shaders.
6669
+ *
6670
+ * Note: Shaders can only be used in WebGL mode.
6671
+ *
6672
+ * `let myShader;
6673
+ *
6674
+ * function setup() {
6675
+ * createCanvas(200, 200, WEBGL);
6676
+ * myShader = buildMaterialShader(material);
6677
+ * noStroke();
6678
+ * describe('A square with dynamically changing colors on a beige background.');
6679
+ * }
6680
+ *
6681
+ * function material() {
6682
+ * let time = uniformFloat();
6683
+ * finalColor.begin();
6684
+ * let r = 0.2 + 0.5 * abs(sin(time + 0));
6685
+ * let g = 0.2 + 0.5 * abs(sin(time + 1));
6686
+ * let b = 0.2 + 0.5 * abs(sin(time + 2));
6687
+ * finalColor.set([r, g, b, 1]);
6688
+ * finalColor.end();
6689
+ * }
6690
+ *
6691
+ * function draw() {
6692
+ * background(245, 245, 220);
6693
+ * myShader.setUniform('time', millis() / 1000);
6694
+ * shader(myShader);
6695
+ *
6696
+ * rectMode(CENTER);
6697
+ * rect(0, 0, 50, 50);
6698
+ * }`For advanced usage, shaders can be written in a language called
6699
+ * <a href="https://developer.mozilla.org/en-US/docs/Games/Techniques/3D_on_the_web/GLSL_Shaders" target="_blank">GLSL</a>.
6700
+ * <a href="#/p5.Shader">p5.Shader</a> objects can be created in this way using the
6701
+ * <a href="#/p5/createShader">createShader()</a> and
6702
+ * <a href="#/p5/loadShader">loadShader()</a> functions.
6703
+ *
6704
+ * `let fillShader;
6705
+ *
6706
+ * let vertSrc = `
6707
+ * precision highp float;
6708
+ * attribute vec3 aPosition;
6709
+ * uniform mat4 uModelViewMatrix;
6710
+ * uniform mat4 uProjectionMatrix;
6711
+ * varying vec3 vPosition;
6712
+ *
6713
+ * void main() {
6714
+ * vPosition = aPosition;
6715
+ * gl_Position = uProjectionMatrix * uModelViewMatrix * vec4(aPosition, 1.0);
6716
+ * }
6717
+ * `;
6718
+ *
6719
+ * let fragSrc = `
6720
+ * precision highp float;
6721
+ * uniform vec3 uLightDir;
6722
+ * varying vec3 vPosition;
6723
+ *
6724
+ * void main() {
6725
+ * vec3 lightDir = normalize(uLightDir);
6726
+ * float brightness = dot(lightDir, normalize(vPosition));
6727
+ * brightness = clamp(brightness, 0.4, 1.0);
6728
+ * vec3 color = vec3(0.3, 0.5, 1.0);
6729
+ * color = color * brightness * 3.0;
6730
+ * gl_FragColor = vec4(color, 1.0);
6731
+ * }
6732
+ * `;
6733
+ *
6734
+ * function setup() {
6735
+ * createCanvas(200, 200, WEBGL);
6736
+ * fillShader = createShader(vertSrc, fragSrc);
6737
+ * noStroke();
6738
+ * describe('A rotating torus with simulated directional lighting.');
6739
+ * }
6740
+ *
6741
+ * function draw() {
6742
+ * background(20, 20, 40);
6743
+ * let lightDir = [0.5, 0.5, 1.0];
6744
+ * fillShader.setUniform('uLightDir', lightDir);
6745
+ * shader(fillShader);
6746
+ * rotateY(frameCount * 0.02);
6747
+ * rotateX(frameCount * 0.02);
6748
+ * torus(25, 10, 30, 30);
6749
+ * }``let fillShader;
6750
+ *
6751
+ * let vertSrc = `
6752
+ * precision highp float;
6753
+ * attribute vec3 aPosition;
6754
+ * uniform mat4 uProjectionMatrix;
6755
+ * uniform mat4 uModelViewMatrix;
6756
+ * varying vec3 vPosition;
6757
+ * void main() {
6758
+ * vPosition = aPosition;
6759
+ * gl_Position = uProjectionMatrix * uModelViewMatrix * vec4(aPosition, 1.0);
6760
+ * }
6761
+ * `;
6762
+ *
6763
+ * let fragSrc = `
6764
+ * precision highp float;
6765
+ * uniform vec3 uLightPos;
6766
+ * uniform vec3 uFillColor;
6767
+ * varying vec3 vPosition;
6768
+ * void main() {
6769
+ * float brightness = dot(normalize(uLightPos), normalize(vPosition));
6770
+ * brightness = clamp(brightness, 0.0, 1.0);
6771
+ * vec3 color = uFillColor * brightness;
6772
+ * gl_FragColor = vec4(color, 1.0);
6773
+ * }
6774
+ * `;
6775
+ *
6776
+ * function setup() {
6777
+ * createCanvas(200, 200, WEBGL);
6778
+ * fillShader = createShader(vertSrc, fragSrc);
6779
+ * shader(fillShader);
6780
+ * noStroke();
6781
+ * describe('A square affected by both fill color and lighting, with lights controlled by mouse.');
6782
+ * }
6783
+ *
6784
+ * function draw() {
6785
+ * let lightPos = [(mouseX - width / 2) / width,
6786
+ * (mouseY - height / 2) / height, 1.0];
6787
+ * fillShader.setUniform('uLightPos', lightPos);
6788
+ * let fillColor = [map(mouseX, 0, width, 0, 1),
6789
+ * map(mouseY, 0, height, 0, 1), 0.5];
6790
+ * fillShader.setUniform('uFillColor', fillColor);
6791
+ * plane(width, height);
6792
+ * }`<div>
6793
+ * <p>If you want to apply shaders to strokes or images, use the following methods:
6794
+ *
6795
+ * - <a href="#/p5/strokeShader">strokeShader()</a> : Applies a shader to the stroke (outline) of shapes, allowing independent control over the stroke rendering using shaders.
6796
+ *
6797
+ * - <a href="#/p5/imageShader">imageShader()</a> : Applies a shader to images or textures, controlling how the shader modifies their appearance during rendering.
6798
+ *
6799
+ * </p>
6800
+ * </div>
6801
+ * @param s <a href="#/p5.Shader">p5.Shader</a> object
6802
+ * to apply.
6803
+ */
6804
+ shader(s: P5.Shader): void;
6805
+
6806
+ /**
6807
+ * Draws a <a href="#/p5.Geometry">p5.Geometry</a> object to the canvas.
6808
+ *
6809
+ * The parameter, `model`, is the
6810
+ * <a href="#/p5.Geometry">p5.Geometry</a> object to draw.
6811
+ * <a href="#/p5.Geometry">p5.Geometry</a> objects can be built with
6812
+ * <a href="#/p5/buildGeometry">buildGeometry()</a>, or
6813
+ * <a href="#/p5/beginGeometry">beginGeometry()</a> and
6814
+ * <a href="#/p5/endGeometry">endGeometry()</a>. They can also be loaded from
6795
6815
  * a file with <a href="#/p5/loadGeometry">loadGeometry()</a>.
6796
6816
  *
6797
6817
  * Note: `model()` can only be used in WebGL mode.
@@ -6800,6 +6820,17 @@ EXCLUDE: typeof P5.EXCLUDE;
6800
6820
  */
6801
6821
  model(model: P5.Geometry, count?: number): void;
6802
6822
 
6823
+ /**
6824
+ * Sets the element's content.
6825
+ *
6826
+ * An element's content is the text between its tags. For example, the element
6827
+ * `&lt;language&gt;JavaScript&lt;/language&gt;` has the content `JavaScript`.
6828
+ *
6829
+ * The parameter, `content`, is a string with the element's new content.
6830
+ * @param content new content for the element.
6831
+ */
6832
+ setContent(content: string): void;
6833
+
6803
6834
  /**
6804
6835
  * Method for executing an HTTP request. If data type is not specified,
6805
6836
  * it will default to `'text'`.
@@ -7079,26 +7110,6 @@ EXCLUDE: typeof P5.EXCLUDE;
7079
7110
  */
7080
7111
  square(x: number, y: number, s: number, tl?: number, tr?: number, br?: number, bl?: number): void;
7081
7112
 
7082
- /**
7083
- * Sets the <a href="#/p5.Shader">p5.Shader</a> object to apply for strokes.
7084
- *
7085
- * This method applies the given shader to strokes, allowing customization of
7086
- * how lines and outlines are drawn in 3D space. The shader will be used for
7087
- * strokes until <a href="#/p5/resetShader">resetShader()</a> is called or another
7088
- * strokeShader is applied.
7089
- *
7090
- * The shader will be used for:
7091
- *
7092
- * - Strokes only, regardless of whether the uniform `uStrokeWeight` is present.
7093
- *
7094
- * To further customize its behavior, refer to the various hooks provided by
7095
- * the <a href="#/p5/baseStrokeShader">baseStrokeShader()</a> method, which allow
7096
- * control over stroke weight, vertex positions, colors, and more.
7097
- * @param s <a href="#/p5.Shader">p5.Shader</a> object
7098
- * to apply for strokes.
7099
- */
7100
- strokeShader(s: P5.Shader): void;
7101
-
7102
7113
  /**
7103
7114
  * Converts 2D screen coordinates to 3D world coordinates.
7104
7115
  *
@@ -7160,6 +7171,26 @@ EXCLUDE: typeof P5.EXCLUDE;
7160
7171
  */
7161
7172
  mousePressed(event?: MouseEvent): void;
7162
7173
 
7174
+ /**
7175
+ * Sets the <a href="#/p5.Shader">p5.Shader</a> object to apply for strokes.
7176
+ *
7177
+ * This method applies the given shader to strokes, allowing customization of
7178
+ * how lines and outlines are drawn in 3D space. The shader will be used for
7179
+ * strokes until <a href="#/p5/resetShader">resetShader()</a> is called or another
7180
+ * strokeShader is applied.
7181
+ *
7182
+ * The shader will be used for:
7183
+ *
7184
+ * - Strokes only, regardless of whether the uniform `uStrokeWeight` is present.
7185
+ *
7186
+ * To further customize its behavior, refer to the various hooks provided by
7187
+ * the <a href="#/p5/baseStrokeShader">baseStrokeShader()</a> method, which allow
7188
+ * control over stroke weight, vertex positions, colors, and more.
7189
+ * @param s <a href="#/p5.Shader">p5.Shader</a> object
7190
+ * to apply for strokes.
7191
+ */
7192
+ strokeShader(s: P5.Shader): void;
7193
+
7163
7194
  /**
7164
7195
  * Tints images using a color.
7165
7196
  *
@@ -7756,25 +7787,6 @@ EXCLUDE: typeof P5.EXCLUDE;
7756
7787
  */
7757
7788
  noFill(): void;
7758
7789
 
7759
- /**
7760
- * Sets the <a href="#/p5.Shader">p5.Shader</a> object to apply for images.
7761
- *
7762
- * This method allows the user to apply a custom shader to images, enabling
7763
- * advanced visual effects such as pixel manipulation, color adjustments,
7764
- * or dynamic behavior. The shader will be applied to the image drawn using
7765
- * the <a href="#/p5/image">image()</a> function.
7766
- *
7767
- * The shader will be used exclusively for:
7768
- *
7769
- * - `image()` calls, applying only when drawing 2D images.
7770
- *
7771
- * - This shader will NOT apply to images used in <a href="#/p5/texture">texture()</a> or other 3D contexts.
7772
- * Any attempts to use the imageShader in these cases will be ignored.
7773
- * @param s <a href="#/p5.Shader">p5.Shader</a> object
7774
- * to apply for images.
7775
- */
7776
- imageShader(s: P5.Shader): void;
7777
-
7778
7790
  /**
7779
7791
  * Removes all lights from the sketch.
7780
7792
  *
@@ -7883,6 +7895,25 @@ EXCLUDE: typeof P5.EXCLUDE;
7883
7895
  */
7884
7896
  mouseReleased(event?: MouseEvent): void;
7885
7897
 
7898
+ /**
7899
+ * Sets the <a href="#/p5.Shader">p5.Shader</a> object to apply for images.
7900
+ *
7901
+ * This method allows the user to apply a custom shader to images, enabling
7902
+ * advanced visual effects such as pixel manipulation, color adjustments,
7903
+ * or dynamic behavior. The shader will be applied to the image drawn using
7904
+ * the <a href="#/p5/image">image()</a> function.
7905
+ *
7906
+ * The shader will be used exclusively for:
7907
+ *
7908
+ * - `image()` calls, applying only when drawing 2D images.
7909
+ *
7910
+ * - This shader will NOT apply to images used in <a href="#/p5/texture">texture()</a> or other 3D contexts.
7911
+ * Any attempts to use the imageShader in these cases will be ignored.
7912
+ * @param s <a href="#/p5.Shader">p5.Shader</a> object
7913
+ * to apply for images.
7914
+ */
7915
+ imageShader(s: P5.Shader): void;
7916
+
7886
7917
  /**
7887
7918
  * Disables drawing points, lines, and the outlines of shapes.
7888
7919
  *
@@ -8000,11 +8031,11 @@ EXCLUDE: typeof P5.EXCLUDE;
8000
8031
  * values. 0 is equal to the first color, 0.1 is very near the first color,
8001
8032
  * 0.5 is halfway between the two colors, and so on. Negative numbers are set
8002
8033
  * to 0. Numbers greater than 1 are set to 1. This differs from the behavior of
8003
- * <a href="#/lerp">lerp</a>. It's necessary because numbers outside of the
8034
+ * <a href="#/p5/lerp">lerp</a>. It's necessary because numbers outside of the
8004
8035
  * interval [0, 1] will produce strange and unexpected colors.
8005
8036
  *
8006
8037
  * The way that colors are interpolated depends on the current
8007
- * <a href="#/colorMode">colorMode()</a>.
8038
+ * <a href="#/p5/colorMode">colorMode()</a>.
8008
8039
  * @param c1 interpolate from this color.
8009
8040
  * @param c2 interpolate to this color.
8010
8041
  * @param amt number between 0 and 1.
@@ -8300,10 +8331,11 @@ EXCLUDE: typeof P5.EXCLUDE;
8300
8331
  * Read the <a href="#/p5.Shader/modify">reference entry for `modify()`</a>
8301
8332
  * for more info.
8302
8333
  * @param callback A function building a p5.strands shader.
8334
+ * @param scope An optional scope object passed to .modify().
8303
8335
  * @returns The material shader.
8304
8336
  */
8305
- buildMaterialShader(callback: Function): P5.Shader;
8306
- buildMaterialShader(hooks: object): P5.Shader;
8337
+ buildMaterialShader(callback: Function, scope?: object): P5.Shader;
8338
+ buildMaterialShader(hooks: object, scope?: object): P5.Shader;
8307
8339
 
8308
8340
  /**
8309
8341
  * Creates a `&lt;video&gt;` element that "captures" the audio/video stream from
@@ -8347,59 +8379,12 @@ EXCLUDE: typeof P5.EXCLUDE;
8347
8379
  createCapture(type?: typeof P5.AUDIO | typeof P5.VIDEO | object, flipped?: object, callback?: Function): P5.MediaElement;
8348
8380
 
8349
8381
  /**
8350
- * Loads a new shader from a file that can change how fills are drawn. Pass the resulting
8351
- * shader into the <a href="#/p5/shader">`shader()`</a> function to apply it
8352
- * to any fills you draw.
8382
+ * Sets the color used to draw points, lines, and the outlines of shapes.
8353
8383
  *
8354
- * Since this function loads data from another file, it returns a `Promise`.
8355
- * Use it in an `async function setup`, and `await` its result.
8356
- *
8357
- * `let myShader;
8358
- * async function setup() {
8359
- * createCanvas(200, 200, WEBGL);
8360
- * myShader = await loadMaterialShader('myMaterial.js');
8361
- * }
8362
- *
8363
- * function draw() {
8364
- * background(255);
8365
- * shader(myShader);
8366
- * myShader.setUniform('time', millis());
8367
- * lights();
8368
- * noStroke();
8369
- * fill('red');
8370
- * sphere(50);
8371
- * }`Inside your shader file, you can call p5.strands hooks to change parts of the shader. For
8372
- * example, you might use the `worldInputs` hook to change each vertex, or you
8373
- * might use the `pixelInputs` hook to change each pixel on the surface of a shape.
8374
- *
8375
- * `// myMaterial.js
8376
- * let time = uniformFloat();
8377
- * worldInputs.begin();
8378
- * worldInputs.position.y +=
8379
- * 20 * sin(time * 0.001 + worldInputs.position.x * 0.05);
8380
- * worldInputs.end();`Read the reference for <a href="#/p5/buildMaterialShader">`buildMaterialShader`</a>,
8381
- * the version of `loadMaterialShader` that takes in a function instead of a separate file,
8382
- * for a full list of hooks you can use and examples for each.
8383
- *
8384
- * The second parameter, `successCallback`, is optional. If a function is passed, as in
8385
- * `loadMaterialShader('myShader.js', onLoaded)`, then the `onLoaded()` function will be called
8386
- * once the shader loads. The shader will be passed to `onLoaded()` as its only argument.
8387
- * The return value of `handleData()`, if present, will be used as the final return value of
8388
- * `loadMaterialShader('myShader.js', onLoaded)`.
8389
- * @param url The URL of your p5.strands JavaScript file.
8390
- * @param onSuccess A callback function to run when loading completes.
8391
- * @param onFailure A callback function to run when loading fails.
8392
- * @returns The material shader.
8393
- */
8394
- loadMaterialShader(url: string, onSuccess?: Function, onFailure?: Function): Promise<P5.Shader>;
8395
-
8396
- /**
8397
- * Sets the color used to draw points, lines, and the outlines of shapes.
8398
- *
8399
- * Calling `stroke(255, 165, 0)` or `stroke('orange')` means all shapes drawn
8400
- * after calling `stroke()` will be outlined with the color orange. The way
8401
- * these parameters are interpreted may be changed with the
8402
- * <a href="#/p5/colorMode">colorMode()</a> function.
8384
+ * Calling `stroke(255, 165, 0)` or `stroke('orange')` means all shapes drawn
8385
+ * after calling `stroke()` will be outlined with the color orange. The way
8386
+ * these parameters are interpreted may be changed with the
8387
+ * <a href="#/p5/colorMode">colorMode()</a> function.
8403
8388
  *
8404
8389
  * The version of `stroke()` with one parameter interprets the value one of
8405
8390
  * three ways. If the parameter is a `Number`, it's interpreted as a grayscale
@@ -8482,30 +8467,51 @@ EXCLUDE: typeof P5.EXCLUDE;
8482
8467
  save(objectOrFilename?: object | string, filename?: string, options?: boolean | string): void;
8483
8468
 
8484
8469
  /**
8485
- * Returns the default shader used for fills when lights or textures are used.
8470
+ * Loads a new shader from a file that can change how fills are drawn. Pass the resulting
8471
+ * shader into the <a href="#/p5/shader">`shader()`</a> function to apply it
8472
+ * to any fills you draw.
8486
8473
  *
8487
- * Calling <a href="#/p5/buildMaterialShader">`buildMaterialShader(shaderFunction)`</a>
8488
- * is equivalent to calling `baseMaterialShader().modify(shaderFunction)`.
8474
+ * Since this function loads data from another file, it returns a `Promise`.
8475
+ * Use it in an `async function setup`, and `await` its result.
8489
8476
  *
8490
- * Read <a href="#/p5/buildMaterialShader">the `buildMaterialShader` reference</a> or
8491
- * call `baseMaterialShader().inspectHooks()` for more information on what you can do with
8492
- * the base material shader.
8493
- * @returns The base material shader.
8494
- */
8495
- baseMaterialShader(): P5.Shader;
8496
-
8497
- /**
8498
- * Returns the base shader used for filters.
8477
+ * `let myShader;
8478
+ * async function setup() {
8479
+ * createCanvas(200, 200, WEBGL);
8480
+ * myShader = await loadMaterialShader('myMaterial.js');
8481
+ * }
8499
8482
  *
8500
- * Calling <a href="#/p5/buildMaterialShader">`buildFilterShader(shaderFunction)`</a>
8501
- * is equivalent to calling `baseFilterShader().modify(shaderFunction)`.
8483
+ * function draw() {
8484
+ * background(255);
8485
+ * shader(myShader);
8486
+ * myShader.setUniform('time', millis());
8487
+ * lights();
8488
+ * noStroke();
8489
+ * fill('red');
8490
+ * sphere(50);
8491
+ * }`Inside your shader file, you can call p5.strands hooks to change parts of the shader. For
8492
+ * example, you might use the `worldInputs` hook to change each vertex, or you
8493
+ * might use the `pixelInputs` hook to change each pixel on the surface of a shape.
8502
8494
  *
8503
- * Read <a href="#/p5/buildFilterShader">the `buildFilterShader` reference</a> or
8504
- * call `baseFilterShader().inspectHooks()` for more information on what you can do with
8505
- * the base filter shader.
8506
- * @returns The base filter shader.
8495
+ * `// myMaterial.js
8496
+ * let time = uniformFloat();
8497
+ * worldInputs.begin();
8498
+ * worldInputs.position.y +=
8499
+ * 20 * sin(time * 0.001 + worldInputs.position.x * 0.05);
8500
+ * worldInputs.end();`Read the reference for <a href="#/p5/buildMaterialShader">`buildMaterialShader`</a>,
8501
+ * the version of `loadMaterialShader` that takes in a function instead of a separate file,
8502
+ * for a full list of hooks you can use and examples for each.
8503
+ *
8504
+ * The second parameter, `successCallback`, is optional. If a function is passed, as in
8505
+ * `loadMaterialShader('myShader.js', onLoaded)`, then the `onLoaded()` function will be called
8506
+ * once the shader loads. The shader will be passed to `onLoaded()` as its only argument.
8507
+ * The return value of `handleData()`, if present, will be used as the final return value of
8508
+ * `loadMaterialShader('myShader.js', onLoaded)`.
8509
+ * @param url The URL of your p5.strands JavaScript file.
8510
+ * @param onSuccess A callback function to run when loading completes.
8511
+ * @param onFailure A callback function to run when loading fails.
8512
+ * @returns The material shader.
8507
8513
  */
8508
- baseFilterShader(): P5.Shader;
8514
+ loadMaterialShader(url: string, onSuccess?: Function, onFailure?: Function): Promise<P5.Shader>;
8509
8515
 
8510
8516
  /**
8511
8517
  * Influences the shape of the Bézier curve segment in a custom shape.
@@ -8576,6 +8582,19 @@ EXCLUDE: typeof P5.EXCLUDE;
8576
8582
  */
8577
8583
  doubleClicked(event?: MouseEvent): void;
8578
8584
 
8585
+ /**
8586
+ * Returns the default shader used for fills when lights or textures are used.
8587
+ *
8588
+ * Calling <a href="#/p5/buildMaterialShader">`buildMaterialShader(shaderFunction)`</a>
8589
+ * is equivalent to calling `baseMaterialShader().modify(shaderFunction)`.
8590
+ *
8591
+ * Read <a href="#/p5/buildMaterialShader">the `buildMaterialShader` reference</a> or
8592
+ * call `baseMaterialShader().inspectHooks()` for more information on what you can do with
8593
+ * the base material shader.
8594
+ * @returns The base material shader.
8595
+ */
8596
+ baseMaterialShader(): P5.Shader;
8597
+
8579
8598
  /**
8580
8599
  * Starts using shapes to erase parts of the canvas.
8581
8600
  *
@@ -8610,6 +8629,19 @@ EXCLUDE: typeof P5.EXCLUDE;
8610
8629
  */
8611
8630
  erase(strengthFill?: number, strengthStroke?: number): void;
8612
8631
 
8632
+ /**
8633
+ * Returns the base shader used for filters.
8634
+ *
8635
+ * Calling <a href="#/p5/buildFilterShader">`buildFilterShader(shaderFunction)`</a>
8636
+ * is equivalent to calling `baseFilterShader().modify(shaderFunction)`.
8637
+ *
8638
+ * Read <a href="#/p5/buildFilterShader">the `buildFilterShader` reference</a> or
8639
+ * call `baseFilterShader().inspectHooks()` for more information on what you can do with
8640
+ * the base filter shader.
8641
+ * @returns The base filter shader.
8642
+ */
8643
+ baseFilterShader(): P5.Shader;
8644
+
8613
8645
  /**
8614
8646
  * Ends erasing that was started with <a href="#/p5/erase">erase()</a>.
8615
8647
  *
@@ -8638,6 +8670,37 @@ EXCLUDE: typeof P5.EXCLUDE;
8638
8670
  createInput(value?: string, type?: string): P5.Element;
8639
8671
  createInput(value?: string): P5.Element;
8640
8672
 
8673
+ /**
8674
+ * Saves an `Object` or `Array` to a JSON file.
8675
+ *
8676
+ * JavaScript Object Notation
8677
+ * (<a href="https://developer.mozilla.org/en-US/docs/Glossary/JSON" target="_blank">JSON</a>)
8678
+ * is a standard format for sending data between applications. The format is
8679
+ * based on JavaScript objects which have keys and values. JSON files store
8680
+ * data in an object with strings as keys. Values can be strings, numbers,
8681
+ * Booleans, arrays, `null`, or other objects.
8682
+ *
8683
+ * The first parameter, `json`, is the data to save. The data can be an array,
8684
+ * as in `[1, 2, 3]`, or an object, as in
8685
+ * `{ x: 50, y: 50, color: 'deeppink' }`.
8686
+ *
8687
+ * The second parameter, `filename`, is a string that sets the file's name.
8688
+ * For example, calling `saveJSON([1, 2, 3], 'data.json')` saves the array
8689
+ * `[1, 2, 3]` to a file called `data.json` on the user's computer.
8690
+ *
8691
+ * The third parameter, `optimize`, is optional. If `true` is passed, as in
8692
+ * `saveJSON([1, 2, 3], 'data.json', true)`, then all unneeded whitespace will
8693
+ * be removed to reduce the file size.
8694
+ *
8695
+ * Note: The browser will either save the file immediately or prompt the user
8696
+ * with a dialogue window.
8697
+ * @param json data to save.
8698
+ * @param filename name of the file to be saved.
8699
+ * @param optimize whether to trim unneeded whitespace. Defaults
8700
+ * to `true`.
8701
+ */
8702
+ saveJSON(json: any[] | object, filename: string, optimize?: boolean): void;
8703
+
8641
8704
  /**
8642
8705
  * Create a new shader that can change how fills are drawn, based on the material used
8643
8706
  * when <a href="#/p5/normalMaterial">`normalMaterial()`</a> is active. Pass the resulting
@@ -8723,41 +8786,11 @@ EXCLUDE: typeof P5.EXCLUDE;
8723
8786
  * Read the <a href="#/p5.Shader/modify">reference entry for `modify()`</a>
8724
8787
  * for more info.
8725
8788
  * @param callback A function building a p5.strands shader.
8789
+ * @param scope An optional scope object passed to .modify().
8726
8790
  * @returns The normal shader.
8727
8791
  */
8728
- buildNormalShader(callback: Function): P5.Shader;
8729
- buildNormalShader(hooks: object): P5.Shader;
8730
-
8731
- /**
8732
- * Saves an `Object` or `Array` to a JSON file.
8733
- *
8734
- * JavaScript Object Notation
8735
- * (<a href="https://developer.mozilla.org/en-US/docs/Glossary/JSON" target="_blank">JSON</a>)
8736
- * is a standard format for sending data between applications. The format is
8737
- * based on JavaScript objects which have keys and values. JSON files store
8738
- * data in an object with strings as keys. Values can be strings, numbers,
8739
- * Booleans, arrays, `null`, or other objects.
8740
- *
8741
- * The first parameter, `json`, is the data to save. The data can be an array,
8742
- * as in `[1, 2, 3]`, or an object, as in
8743
- * `{ x: 50, y: 50, color: 'deeppink' }`.
8744
- *
8745
- * The second parameter, `filename`, is a string that sets the file's name.
8746
- * For example, calling `saveJSON([1, 2, 3], 'data.json')` saves the array
8747
- * `[1, 2, 3]` to a file called `data.json` on the user's computer.
8748
- *
8749
- * The third parameter, `optimize`, is optional. If `true` is passed, as in
8750
- * `saveJSON([1, 2, 3], 'data.json', true)`, then all unneeded whitespace will
8751
- * be removed to reduce the file size.
8752
- *
8753
- * Note: The browser will either save the file immediately or prompt the user
8754
- * with a dialogue window.
8755
- * @param json data to save.
8756
- * @param filename name of the file to be saved.
8757
- * @param optimize whether to trim unneeded whitespace. Defaults
8758
- * to `true`.
8759
- */
8760
- saveJSON(json: any[] | object, filename: string, optimize?: boolean): void;
8792
+ buildNormalShader(callback: Function, scope?: object): P5.Shader;
8793
+ buildNormalShader(hooks: object, scope?: object): P5.Shader;
8761
8794
 
8762
8795
  /**
8763
8796
  * A function that's called once when the mouse wheel moves.
@@ -8803,54 +8836,6 @@ EXCLUDE: typeof P5.EXCLUDE;
8803
8836
  */
8804
8837
  mouseWheel(event?: WheelEvent): void;
8805
8838
 
8806
- /**
8807
- * Loads a new shader from a file that can change how fills are drawn, based on the material used
8808
- * when <a href="#/p5/normalMaterial">`normalMaterial()`</a> is active. Pass the resulting
8809
- * shader into the <a href="#/p5/shader">`shader()`</a> function to apply it
8810
- * to any fills you draw.
8811
- *
8812
- * Since this function loads data from another file, it returns a `Promise`.
8813
- * Use it in an `async function setup`, and `await` its result.
8814
- *
8815
- * `let myShader;
8816
- * async function setup() {
8817
- * createCanvas(200, 200, WEBGL);
8818
- * myShader = await loadNormalShader('myMaterial.js');
8819
- * }
8820
- *
8821
- * function draw() {
8822
- * background(255);
8823
- * shader(myShader);
8824
- * myShader.setUniform('time', millis());
8825
- * lights();
8826
- * noStroke();
8827
- * fill('red');
8828
- * sphere(50);
8829
- * }`Inside your shader file, you can call p5.strands hooks to change parts of the shader. For
8830
- * example, you might use the `worldInputs` hook to change each vertex, or you
8831
- * might use the `finalColor` hook to change the color of each pixel on the surface of a shape.
8832
- *
8833
- * `// myMaterial.js
8834
- * let time = uniformFloat();
8835
- * worldInputs.begin();
8836
- * worldInputs.position.y +=
8837
- * 20 * sin(time * 0.001 + worldInputs.position.x * 0.05);
8838
- * worldInputs.end();`Read the reference for <a href="#/p5/buildNormalShader">`buildNormalShader`</a>,
8839
- * the version of `loadNormalShader` that takes in a function instead of a separate file,
8840
- * for a full list of hooks you can use and examples for each.
8841
- *
8842
- * The second parameter, `successCallback`, is optional. If a function is passed, as in
8843
- * `loadNormalShader('myShader.js', onLoaded)`, then the `onLoaded()` function will be called
8844
- * once the shader loads. The shader will be passed to `onLoaded()` as its only argument.
8845
- * The return value of `handleData()`, if present, will be used as the final return value of
8846
- * `loadNormalShader('myShader.js', onLoaded)`.
8847
- * @param url The URL of your p5.strands JavaScript file.
8848
- * @param onSuccess A callback function to run when loading completes.
8849
- * @param onFailure A callback function to run when loading fails.
8850
- * @returns The normal shader.
8851
- */
8852
- loadNormalShader(url: string, onSuccess?: Function, onFailure?: Function): Promise<P5.Shader>;
8853
-
8854
8839
  /**
8855
8840
  * Ends a drawing group that contains its own styles and transformations.
8856
8841
  *
@@ -9034,20 +9019,6 @@ EXCLUDE: typeof P5.EXCLUDE;
9034
9019
  */
9035
9020
  createFileInput(callback: (input: P5.File) => any, multiple?: boolean): P5.Element;
9036
9021
 
9037
- /**
9038
- * Returns the default shader used for fills when
9039
- * <a href="#/p5/normalMaterial">`normalMaterial()`</a> is activated.
9040
- *
9041
- * Calling <a href="#/p5/buildNormalShader">`buildNormalShader(shaderFunction)`</a>
9042
- * is equivalent to calling `baseNormalShader().modify(shaderFunction)`.
9043
- *
9044
- * Read <a href="#/p5/buildNormalShader">the `buildNormalShader` reference</a> or
9045
- * call `baseNormalShader().inspectHooks()` for more information on what you can do with
9046
- * the base normal shader.
9047
- * @returns The base material shader.
9048
- */
9049
- baseNormalShader(): P5.Shader;
9050
-
9051
9022
  /**
9052
9023
  * Locks the mouse pointer to its current position and makes it invisible.
9053
9024
  *
@@ -9068,61 +9039,66 @@ EXCLUDE: typeof P5.EXCLUDE;
9068
9039
  requestPointerLock(): void;
9069
9040
 
9070
9041
  /**
9071
- * Create a new shader that can change how fills are drawn, based on the default shader
9072
- * used when no lights or textures are applied. Pass the resulting
9042
+ * Loads a new shader from a file that can change how fills are drawn, based on the material used
9043
+ * when <a href="#/p5/normalMaterial">`normalMaterial()`</a> is active. Pass the resulting
9073
9044
  * shader into the <a href="#/p5/shader">`shader()`</a> function to apply it
9074
9045
  * to any fills you draw.
9075
9046
  *
9076
- * The main way to use `buildColorShader` is to pass a function in as a parameter.
9077
- * This will let you create a shader using p5.strands.
9078
- *
9079
- * In your function, you can call hooks to change part of the shader. In a material
9080
- * shader, these are the hooks available:
9081
- *
9082
- * - <a href="#/p5/objectInputs">`objectInputs`</a>: Update vertices before any positioning has been applied. Your function gets run on every vertex.
9083
- *
9084
- * - <a href="#/p5/worldInputs">`worldInputs`</a>: Update vertices after transformations have been applied. Your function gets run on every vertex.
9085
- *
9086
- * - <a href="#/p5/cameraInputs">`cameraInputs`</a>: Update vertices after transformations have been applied, relative to the camera. Your function gets run on every vertex.
9087
- *
9088
- * - <a href="#/p5/finalColor">`finalColor`</a>: Update or replace the pixel color on the surface of a shape. Your function gets run on every pixel.
9089
- *
9090
- * Read the linked reference page for each hook for more information about how to use them.
9091
- *
9092
- * One thing you might want to do is modify the position of every vertex over time:
9047
+ * Since this function loads data from another file, it returns a `Promise`.
9048
+ * Use it in an `async function setup`, and `await` its result.
9093
9049
  *
9094
9050
  * `let myShader;
9095
- *
9096
- * function setup() {
9051
+ * async function setup() {
9097
9052
  * createCanvas(200, 200, WEBGL);
9098
- * myShader = buildColorShader(material);
9099
- * }
9100
- *
9101
- * function material() {
9102
- * let time = uniformFloat();
9103
- * worldInputs.begin();
9104
- * worldInputs.position.y +=
9105
- * 20 * sin(time * 0.001 + worldInputs.position.x * 0.05);
9106
- * worldInputs.end();
9053
+ * myShader = await loadNormalShader('myMaterial.js');
9107
9054
  * }
9108
9055
  *
9109
9056
  * function draw() {
9110
9057
  * background(255);
9111
9058
  * shader(myShader);
9112
9059
  * myShader.setUniform('time', millis());
9060
+ * lights();
9113
9061
  * noStroke();
9114
9062
  * fill('red');
9115
- * circle(0, 0, 50);
9116
- * }`Like the `modify()` method on shaders,
9117
- * advanced users can also fill in hooks using <a href="https://developer.mozilla.org/en-US/docs/Games/Techniques/3D_on_the_web/GLSL_Shaders" target="_blank">GLSL</a>
9118
- * instead of JavaScript.
9119
- * Read the <a href="#/p5.Shader/modify">reference entry for `modify()`</a>
9120
- * for more info.
9121
- * @param callback A function building a p5.strands shader.
9122
- * @returns The color shader.
9063
+ * sphere(50);
9064
+ * }`Inside your shader file, you can call p5.strands hooks to change parts of the shader. For
9065
+ * example, you might use the `worldInputs` hook to change each vertex, or you
9066
+ * might use the `finalColor` hook to change the color of each pixel on the surface of a shape.
9067
+ *
9068
+ * `// myMaterial.js
9069
+ * let time = uniformFloat();
9070
+ * worldInputs.begin();
9071
+ * worldInputs.position.y +=
9072
+ * 20 * sin(time * 0.001 + worldInputs.position.x * 0.05);
9073
+ * worldInputs.end();`Read the reference for <a href="#/p5/buildNormalShader">`buildNormalShader`</a>,
9074
+ * the version of `loadNormalShader` that takes in a function instead of a separate file,
9075
+ * for a full list of hooks you can use and examples for each.
9076
+ *
9077
+ * The second parameter, `successCallback`, is optional. If a function is passed, as in
9078
+ * `loadNormalShader('myShader.js', onLoaded)`, then the `onLoaded()` function will be called
9079
+ * once the shader loads. The shader will be passed to `onLoaded()` as its only argument.
9080
+ * The return value of `handleData()`, if present, will be used as the final return value of
9081
+ * `loadNormalShader('myShader.js', onLoaded)`.
9082
+ * @param url The URL of your p5.strands JavaScript file.
9083
+ * @param onSuccess A callback function to run when loading completes.
9084
+ * @param onFailure A callback function to run when loading fails.
9085
+ * @returns The normal shader.
9086
+ */
9087
+ loadNormalShader(url: string, onSuccess?: Function, onFailure?: Function): Promise<P5.Shader>;
9088
+
9089
+ /**
9090
+ * Returns the default shader used for fills when
9091
+ * <a href="#/p5/normalMaterial">`normalMaterial()`</a> is activated.
9092
+ *
9093
+ * Calling <a href="#/p5/buildNormalShader">`buildNormalShader(shaderFunction)`</a>
9094
+ * is equivalent to calling `baseNormalShader().modify(shaderFunction)`.
9095
+ *
9096
+ * Read <a href="#/p5/buildNormalShader">the `buildNormalShader` reference</a> or
9097
+ * call `baseNormalShader().inspectHooks()` for more information on what you can do with
9098
+ * the base normal shader.
9099
+ * @returns The base material shader.
9123
9100
  */
9124
- buildColorShader(callback: Function): P5.Shader;
9125
- buildColorShader(hooks: object): P5.Shader;
9101
+ baseNormalShader(): P5.Shader;
9126
9102
 
9127
9103
  /**
9128
9104
  * Exits a pointer lock started with
@@ -9170,6 +9146,64 @@ EXCLUDE: typeof P5.EXCLUDE;
9170
9146
  */
9171
9147
  saveStrings(list: string[], filename: string, extension?: string, isCRLF?: boolean): void;
9172
9148
 
9149
+ /**
9150
+ * Create a new shader that can change how fills are drawn, based on the default shader
9151
+ * used when no lights or textures are applied. Pass the resulting
9152
+ * shader into the <a href="#/p5/shader">`shader()`</a> function to apply it
9153
+ * to any fills you draw.
9154
+ *
9155
+ * The main way to use `buildColorShader` is to pass a function in as a parameter.
9156
+ * This will let you create a shader using p5.strands.
9157
+ *
9158
+ * In your function, you can call hooks to change part of the shader. In a material
9159
+ * shader, these are the hooks available:
9160
+ *
9161
+ * - <a href="#/p5/objectInputs">`objectInputs`</a>: Update vertices before any positioning has been applied. Your function gets run on every vertex.
9162
+ *
9163
+ * - <a href="#/p5/worldInputs">`worldInputs`</a>: Update vertices after transformations have been applied. Your function gets run on every vertex.
9164
+ *
9165
+ * - <a href="#/p5/cameraInputs">`cameraInputs`</a>: Update vertices after transformations have been applied, relative to the camera. Your function gets run on every vertex.
9166
+ *
9167
+ * - <a href="#/p5/finalColor">`finalColor`</a>: Update or replace the pixel color on the surface of a shape. Your function gets run on every pixel.
9168
+ *
9169
+ * Read the linked reference page for each hook for more information about how to use them.
9170
+ *
9171
+ * One thing you might want to do is modify the position of every vertex over time:
9172
+ *
9173
+ * `let myShader;
9174
+ *
9175
+ * function setup() {
9176
+ * createCanvas(200, 200, WEBGL);
9177
+ * myShader = buildColorShader(material);
9178
+ * }
9179
+ *
9180
+ * function material() {
9181
+ * let time = uniformFloat();
9182
+ * worldInputs.begin();
9183
+ * worldInputs.position.y +=
9184
+ * 20 * sin(time * 0.001 + worldInputs.position.x * 0.05);
9185
+ * worldInputs.end();
9186
+ * }
9187
+ *
9188
+ * function draw() {
9189
+ * background(255);
9190
+ * shader(myShader);
9191
+ * myShader.setUniform('time', millis());
9192
+ * noStroke();
9193
+ * fill('red');
9194
+ * circle(0, 0, 50);
9195
+ * }`Like the `modify()` method on shaders,
9196
+ * advanced users can also fill in hooks using <a href="https://developer.mozilla.org/en-US/docs/Games/Techniques/3D_on_the_web/GLSL_Shaders" target="_blank">GLSL</a>
9197
+ * instead of JavaScript.
9198
+ * Read the <a href="#/p5.Shader/modify">reference entry for `modify()`</a>
9199
+ * for more info.
9200
+ * @param callback A function building a p5.strands shader.
9201
+ * @param scope An optional scope object passed to .modify().
9202
+ * @returns The color shader.
9203
+ */
9204
+ buildColorShader(callback: Function, scope?: object): P5.Shader;
9205
+ buildColorShader(hooks: object, scope?: object): P5.Shader;
9206
+
9173
9207
  /**
9174
9208
  * Connects points with a smooth curve (a spline).
9175
9209
  *
@@ -9238,6 +9272,18 @@ EXCLUDE: typeof P5.EXCLUDE;
9238
9272
  splineVertex(x: number, y: number, u?: number, v?: number): void;
9239
9273
  splineVertex(x: number, y: number, z: number, u?: number, v?: number): void;
9240
9274
 
9275
+ /**
9276
+ * Writes the contents of a <a href="#/p5.Table">Table</a> object to a file. Defaults to a
9277
+ * text file with comma-separated-values ('csv') but can also
9278
+ * use tab separation ('tsv'), or generate an HTML table ('html').
9279
+ * The file saving process and location of the saved file will
9280
+ * vary between web browsers.
9281
+ * @param Table the <a href="#/p5.Table">Table</a> object to save to a file
9282
+ * @param filename the filename to which the Table should be saved
9283
+ * @param options can be one of "tsv", "csv", or "html"
9284
+ */
9285
+ saveTable(Table: P5.Table, filename: string, options?: string): void;
9286
+
9241
9287
  /**
9242
9288
  * Loads a new shader from a file that can change how fills are drawn, based on the material used
9243
9289
  * when no lights or textures are active. Pass the resulting
@@ -9286,18 +9332,6 @@ EXCLUDE: typeof P5.EXCLUDE;
9286
9332
  */
9287
9333
  loadColorShader(url: string, onSuccess?: Function, onFailure?: Function): Promise<P5.Shader>;
9288
9334
 
9289
- /**
9290
- * Writes the contents of a <a href="#/p5.Table">Table</a> object to a file. Defaults to a
9291
- * text file with comma-separated-values ('csv') but can also
9292
- * use tab separation ('tsv'), or generate an HTML table ('html').
9293
- * The file saving process and location of the saved file will
9294
- * vary between web browsers.
9295
- * @param Table the <a href="#/p5.Table">Table</a> object to save to a file
9296
- * @param filename the filename to which the Table should be saved
9297
- * @param options can be one of "tsv", "csv", or "html"
9298
- */
9299
- saveTable(Table: P5.Table, filename: string, options?: string): void;
9300
-
9301
9335
  /**
9302
9336
  * Returns the default shader used for fills when no lights or textures are activate.
9303
9337
  *
@@ -9595,62 +9629,11 @@ EXCLUDE: typeof P5.EXCLUDE;
9595
9629
  * Read the <a href="#/p5.Shader/modify">reference entry for `modify()`</a>
9596
9630
  * for more info.
9597
9631
  * @param callback A function building a p5.strands shader.
9632
+ * @param scope An optional scope object passed to .modify().
9598
9633
  * @returns The stroke shader.
9599
9634
  */
9600
- buildStrokeShader(callback: Function): P5.Shader;
9601
- buildStrokeShader(hooks: object): P5.Shader;
9602
-
9603
- /**
9604
- * Loads a new shader from a file that can change how strokes are drawn. Pass the resulting
9605
- * shader into the <a href="#/p5/strokeShader">`strokeShader()`</a> function to apply it
9606
- * to any strokes you draw.
9607
- *
9608
- * Since this function loads data from another file, it returns a `Promise`.
9609
- * Use it in an `async function setup`, and `await` its result.
9610
- *
9611
- * `let myShader;
9612
- * async function setup() {
9613
- * createCanvas(200, 200, WEBGL);
9614
- * myShader = await loadStrokeShader('myMaterial.js');
9615
- * }
9616
- *
9617
- * function draw() {
9618
- * background(255);
9619
- * strokeShader(myShader);
9620
- * strokeWeight(30);
9621
- * line(
9622
- * -width/3,
9623
- * sin(millis()*0.001) * height/4,
9624
- * width/3,
9625
- * sin(millis()*0.001 + 1) * height/4
9626
- * );
9627
- * }`Inside your shader file, you can call p5.strands hooks to change parts of the shader. For
9628
- * example, you might use the `worldInputs` hook to change each vertex, or you
9629
- * might use the `pixelInputs` hook to change each pixel on the surface of a stroke.
9630
- *
9631
- * `// myMaterial.js
9632
- * pixelInputs.begin();
9633
- * let opacity = 1 - smoothstep(
9634
- * 0,
9635
- * 15,
9636
- * length(pixelInputs.position - pixelInputs.center)
9637
- * );
9638
- * pixelInputs.color.a *= opacity;
9639
- * pixelInputs.end();`Read the reference for <a href="#/p5/buildStrokeShader">`buildStrokeShader`</a>,
9640
- * the version of `loadStrokeShader` that takes in a function instead of a separate file,
9641
- * for a full list of hooks you can use and examples for each.
9642
- *
9643
- * The second parameter, `successCallback`, is optional. If a function is passed, as in
9644
- * `loadStrokeShader('myShader.js', onLoaded)`, then the `onLoaded()` function will be called
9645
- * once the shader loads. The shader will be passed to `onLoaded()` as its only argument.
9646
- * The return value of `handleData()`, if present, will be used as the final return value of
9647
- * `loadStrokeShader('myShader.js', onLoaded)`.
9648
- * @param url The URL of your p5.strands JavaScript file.
9649
- * @param onSuccess A callback function to run when loading completes.
9650
- * @param onFailure A callback function to run when loading fails.
9651
- * @returns The stroke shader.
9652
- */
9653
- loadStrokeShader(url: string, onSuccess?: Function, onFailure?: Function): Promise<P5.Shader>;
9635
+ buildStrokeShader(callback: Function, scope?: object): P5.Shader;
9636
+ buildStrokeShader(hooks: object, scope?: object): P5.Shader;
9654
9637
 
9655
9638
  /**
9656
9639
  * Gets or sets a given spline property.
@@ -9776,31 +9759,72 @@ EXCLUDE: typeof P5.EXCLUDE;
9776
9759
  perspective(fovy?: number, aspect?: number, near?: number, far?: number): void;
9777
9760
 
9778
9761
  /**
9779
- * Returns the default shader used for strokes.
9762
+ * Loads a new shader from a file that can change how strokes are drawn. Pass the resulting
9763
+ * shader into the <a href="#/p5/strokeShader">`strokeShader()`</a> function to apply it
9764
+ * to any strokes you draw.
9780
9765
  *
9781
- * Calling <a href="#/p5/buildStrokeShader">`buildStrokeShader(shaderFunction)`</a>
9782
- * is equivalent to calling `baseStrokeShader().modify(shaderFunction)`.
9766
+ * Since this function loads data from another file, it returns a `Promise`.
9767
+ * Use it in an `async function setup`, and `await` its result.
9783
9768
  *
9784
- * Read <a href="#/p5/buildStrokeShader">the `buildStrokeShader` reference</a> or
9785
- * call `baseStrokeShader().inspectHooks()` for more information on what you can do with
9786
- * the base material shader.
9787
- * @returns The base material shader.
9788
- */
9789
- baseStrokeShader(): P5.Shader;
9790
-
9791
- /**
9792
- * Restores the default shaders.
9769
+ * `let myShader;
9770
+ * async function setup() {
9771
+ * createCanvas(200, 200, WEBGL);
9772
+ * myShader = await loadStrokeShader('myMaterial.js');
9773
+ * }
9793
9774
  *
9794
- * `resetShader()` deactivates any shaders previously applied by
9795
- * <a href="#/p5/shader">shader()</a>, <a href="#/p5/strokeShader">strokeShader()</a>,
9796
- * or <a href="#/p5/imageShader">imageShader()</a>.
9775
+ * function draw() {
9776
+ * background(255);
9777
+ * strokeShader(myShader);
9778
+ * strokeWeight(30);
9779
+ * line(
9780
+ * -width/3,
9781
+ * sin(millis()*0.001) * height/4,
9782
+ * width/3,
9783
+ * sin(millis()*0.001 + 1) * height/4
9784
+ * );
9785
+ * }`Inside your shader file, you can call p5.strands hooks to change parts of the shader. For
9786
+ * example, you might use the `worldInputs` hook to change each vertex, or you
9787
+ * might use the `pixelInputs` hook to change each pixel on the surface of a stroke.
9797
9788
  *
9798
- * Note: Shaders can only be used in WebGL mode.
9799
- */
9800
- resetShader(): void;
9801
-
9802
- /**
9803
- * Sets multiple properties for spline curves at once.
9789
+ * `// myMaterial.js
9790
+ * pixelInputs.begin();
9791
+ * let opacity = 1 - smoothstep(
9792
+ * 0,
9793
+ * 15,
9794
+ * length(pixelInputs.position - pixelInputs.center)
9795
+ * );
9796
+ * pixelInputs.color.a *= opacity;
9797
+ * pixelInputs.end();`Read the reference for <a href="#/p5/buildStrokeShader">`buildStrokeShader`</a>,
9798
+ * the version of `loadStrokeShader` that takes in a function instead of a separate file,
9799
+ * for a full list of hooks you can use and examples for each.
9800
+ *
9801
+ * The second parameter, `successCallback`, is optional. If a function is passed, as in
9802
+ * `loadStrokeShader('myShader.js', onLoaded)`, then the `onLoaded()` function will be called
9803
+ * once the shader loads. The shader will be passed to `onLoaded()` as its only argument.
9804
+ * The return value of `handleData()`, if present, will be used as the final return value of
9805
+ * `loadStrokeShader('myShader.js', onLoaded)`.
9806
+ * @param url The URL of your p5.strands JavaScript file.
9807
+ * @param onSuccess A callback function to run when loading completes.
9808
+ * @param onFailure A callback function to run when loading fails.
9809
+ * @returns The stroke shader.
9810
+ */
9811
+ loadStrokeShader(url: string, onSuccess?: Function, onFailure?: Function): Promise<P5.Shader>;
9812
+
9813
+ /**
9814
+ * Returns the default shader used for strokes.
9815
+ *
9816
+ * Calling <a href="#/p5/buildStrokeShader">`buildStrokeShader(shaderFunction)`</a>
9817
+ * is equivalent to calling `baseStrokeShader().modify(shaderFunction)`.
9818
+ *
9819
+ * Read <a href="#/p5/buildStrokeShader">the `buildStrokeShader` reference</a> or
9820
+ * call `baseStrokeShader().inspectHooks()` for more information on what you can do with
9821
+ * the base material shader.
9822
+ * @returns The base material shader.
9823
+ */
9824
+ baseStrokeShader(): P5.Shader;
9825
+
9826
+ /**
9827
+ * Sets multiple properties for spline curves at once.
9804
9828
  *
9805
9829
  * `splineProperties()` accepts an object with key-value pairs to configure
9806
9830
  * how spline curves are drawn. This is a convenient way to set multiple
@@ -9867,6 +9891,17 @@ EXCLUDE: typeof P5.EXCLUDE;
9867
9891
  linePerspective(enable: boolean): boolean;
9868
9892
  linePerspective(): boolean;
9869
9893
 
9894
+ /**
9895
+ * Restores the default shaders.
9896
+ *
9897
+ * `resetShader()` deactivates any shaders previously applied by
9898
+ * <a href="#/p5/shader">shader()</a>, <a href="#/p5/strokeShader">strokeShader()</a>,
9899
+ * or <a href="#/p5/imageShader">imageShader()</a>.
9900
+ *
9901
+ * Note: Shaders can only be used in WebGL mode.
9902
+ */
9903
+ resetShader(): void;
9904
+
9870
9905
  /**
9871
9906
  * Sets an orthographic projection for the current camera in a 3D sketch.
9872
9907
  *
@@ -16589,6 +16624,112 @@ function get(x: number, y: number): number[];
16589
16624
  function min(n0: number, n1: number): number;
16590
16625
  function min(nums: number[]): number;
16591
16626
 
16627
+ /**
16628
+ * A function that's called when the browser window is resized.
16629
+ *
16630
+ * Code placed in the body of `windowResized()` will run when the
16631
+ * browser window's size changes. It's a good place to call
16632
+ * <a href="#/p5/resizeCanvas">resizeCanvas()</a> or make other
16633
+ * adjustments to accommodate the new window size.
16634
+ *
16635
+ * The `event` parameter is optional. If added to the function declaration, it
16636
+ * can be used for debugging or other purposes.
16637
+ * @param event optional resize Event.
16638
+ */
16639
+ function windowResized(event?: Event): void;
16640
+
16641
+ /**
16642
+ * Shuffles the elements of an array.
16643
+ *
16644
+ * The first parameter, `array`, is the array to be shuffled. For example,
16645
+ * calling `shuffle(myArray)` will shuffle the elements of `myArray`. By
16646
+ * default, the original array won’t be modified. Instead, a copy will be
16647
+ * created, shuffled, and returned.
16648
+ *
16649
+ * The second parameter, `modify`, is optional. If `true` is passed, as in
16650
+ * `shuffle(myArray, true)`, then the array will be shuffled in place without
16651
+ * making a copy.
16652
+ * @param array array to shuffle.
16653
+ * @param modify if `true`, shuffle the original array in place. Defaults to `false`.
16654
+ * @returns shuffled array.
16655
+ */
16656
+ function shuffle<T>(array: T[], modify?: boolean): T[];
16657
+
16658
+ /**
16659
+ * This method is suitable for fetching files up to size of 64MB.
16660
+ * @param file name of the file or URL to load
16661
+ * @param callback function to be executed after <a href="#/p5/loadBytes">loadBytes()</a>
16662
+ * completes
16663
+ * @param errorCallback function to be executed if there
16664
+ * is an error
16665
+ * @returns a Uint8Array containing the loaded buffer
16666
+ */
16667
+ function loadBytes(file: string | Request, callback?: Function, errorCallback?: Function): Promise<Uint8Array>;
16668
+
16669
+ /**
16670
+ * Turns off <a href="#/p5/debugMode">debugMode()</a> in a 3D sketch.
16671
+ */
16672
+ function noDebugMode(): void;
16673
+
16674
+ /**
16675
+ * Gets the blue value of a color.
16676
+ *
16677
+ * `blue()` extracts the blue value from a
16678
+ * <a href="/reference/p5/p5.Color/">p5.Color</a> object, an array of color components, or
16679
+ * a CSS color string.
16680
+ *
16681
+ * By default, `blue()` returns a color's blue value in the range 0
16682
+ * to 255. If the <a href="/reference/p5/colorMode/">colorMode()</a> is set to RGB, it
16683
+ * returns the blue value in the given range.
16684
+ * @param color <a href="/reference/p5/p5.Color/">p5.Color</a> object, array of
16685
+ * color components, or CSS color string.
16686
+ * @returns the blue value.
16687
+ */
16688
+ function blue(color: P5.Color | number[] | string): number;
16689
+
16690
+ /**
16691
+ * Converts a single-character `String` to a `Number`.
16692
+ *
16693
+ * `unchar()` converts single-character strings to their corresponding
16694
+ * integer (whole number).
16695
+ *
16696
+ * The parameter, `n`, is the character to convert. For example,
16697
+ * `unchar('A')`, returns the number 65. If an array is passed, as in
16698
+ * `unchar(['A', 'B', 'C'])`, an array of integers is returned.
16699
+ * @param n value to convert.
16700
+ * @returns converted number.
16701
+ */
16702
+ function unchar(n: string): number;
16703
+ function unchar(ns: string[]): number[];
16704
+
16705
+ /**
16706
+ * Changes the unit system used to measure angles.
16707
+ *
16708
+ * Degrees and radians are both units for measuring angles. There are 360˚ in
16709
+ * one full rotation. A full rotation is 2 × π (about 6.28) radians.
16710
+ *
16711
+ * Functions such as <a href="#/p5/rotate">rotate()</a> and
16712
+ * <a href="#/p5/sin">sin()</a> expect angles measured radians by default.
16713
+ * Calling `angleMode(DEGREES)` switches to degrees. Calling
16714
+ * `angleMode(RADIANS)` switches back to radians.
16715
+ *
16716
+ * Calling `angleMode()` with no arguments returns current angle mode, which
16717
+ * is either `RADIANS` or `DEGREES`.
16718
+ * @param mode either RADIANS or DEGREES.
16719
+ * @returns mode either RADIANS or DEGREES
16720
+ */
16721
+ function angleMode(mode: typeof P5.RADIANS | typeof P5.DEGREES): typeof P5.RADIANS | typeof P5.DEGREES;
16722
+ function angleMode(): typeof P5.RADIANS | typeof P5.DEGREES;
16723
+
16724
+ /**
16725
+ * Loads the current value of each pixel on the canvas into the
16726
+ * <a href="#/p5/pixels">pixels</a> array.
16727
+ *
16728
+ * `loadPixels()` must be called before reading from or writing to
16729
+ * <a href="#/p5/pixels">pixels</a>.
16730
+ */
16731
+ function loadPixels(): void;
16732
+
16592
16733
  /**
16593
16734
  * Creates a <a href="#/p5.Shader">p5.Shader</a> object to be used with the
16594
16735
  * <a href="#/p5/filter">filter()</a> function.
@@ -16708,6 +16849,36 @@ function min(nums: number[]): number;
16708
16849
  * function draw() {
16709
16850
  * myFilter.setUniform('time', millis());
16710
16851
  * filter(myFilter);
16852
+ * }`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 passing in an announced uniform variable `time` with `setUniform()`, each frame.
16853
+ *
16854
+ * `let myFilter;
16855
+ *
16856
+ * function setup() {
16857
+ * createCanvas(100, 100, WEBGL);
16858
+ * myFilter = buildFilterShader(noiseShaderCallback);
16859
+ * describe('Evolving animated cloud-like noise in cyan and magenta');
16860
+ * }
16861
+ *
16862
+ * function noiseShaderCallback() {
16863
+ * let time = uniformFloat();
16864
+ * filterColor.begin();
16865
+ * let coord = filterColor.texCoord;
16866
+ *
16867
+ * //generate a value roughly between 0 and 1
16868
+ * let noiseVal = noise(coord.x, coord.y, time / 2000);
16869
+ *
16870
+ * let result = mix(
16871
+ * [1, 0, 1, 1], // Magenta
16872
+ * [0, 1, 1, 1], // Cyan
16873
+ * noiseVal
16874
+ * );
16875
+ * filterColor.set(result);
16876
+ * filterColor.end();
16877
+ * }
16878
+ *
16879
+ * function draw() {
16880
+ * myFilter.setUniform("time", millis());
16881
+ * filter(myFilter);
16711
16882
  * }`Like the `modify()` method on shaders,
16712
16883
  * 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>
16713
16884
  * instead of JavaScript.
@@ -16718,157 +16889,52 @@ function min(nums: number[]): number;
16718
16889
  * For more info about filters and shaders, see Adam Ferriss' <a href="https://github.com/aferriss/p5jsShaderExamples">repo of shader examples</a>
16719
16890
  * or the <a href="https://p5js.org/learn/getting-started-in-webgl-shaders.html">Introduction to Shaders</a> tutorial.
16720
16891
  * @param callback A function building a p5.strands shader.
16892
+ * @param scope An optional scope object passed to .modify().
16721
16893
  * @returns The material shader
16722
16894
  */
16723
- function buildFilterShader(callback: Function): P5.Shader;
16724
- function buildFilterShader(hooks: object): P5.Shader;
16895
+ function buildFilterShader(callback: Function, scope?: object): P5.Shader;
16896
+ function buildFilterShader(hooks: object, scope?: object): P5.Shader;
16725
16897
 
16726
16898
  /**
16727
- * A function that's called when the browser window is resized.
16899
+ * Creates a slider `&lt;input&gt;&lt;/input&gt;` element.
16728
16900
  *
16729
- * Code placed in the body of `windowResized()` will run when the
16730
- * browser window's size changes. It's a good place to call
16731
- * <a href="#/p5/resizeCanvas">resizeCanvas()</a> or make other
16732
- * adjustments to accommodate the new window size.
16901
+ * Range sliders are useful for quickly selecting numbers from a given range.
16733
16902
  *
16734
- * The `event` parameter is optional. If added to the function declaration, it
16735
- * can be used for debugging or other purposes.
16736
- * @param event optional resize Event.
16737
- */
16738
- function windowResized(event?: Event): void;
16739
-
16740
- /**
16741
- * Shuffles the elements of an array.
16903
+ * The first two parameters, `min` and `max`, are numbers that set the
16904
+ * slider's minimum and maximum.
16742
16905
  *
16743
- * The first parameter, `array`, is the array to be shuffled. For example,
16744
- * calling `shuffle(myArray)` will shuffle the elements of `myArray`. By
16745
- * default, the original array won’t be modified. Instead, a copy will be
16746
- * created, shuffled, and returned.
16906
+ * The third parameter, `value`, is optional. It's a number that sets the
16907
+ * slider's default value.
16747
16908
  *
16748
- * The second parameter, `modify`, is optional. If `true` is passed, as in
16749
- * `shuffle(myArray, true)`, then the array will be shuffled in place without
16750
- * making a copy.
16751
- * @param array array to shuffle.
16752
- * @param modify if `true`, shuffle the original array in place. Defaults to `false`.
16753
- * @returns shuffled array.
16754
- */
16755
- function shuffle<T>(array: T[], modify?: boolean): T[];
16756
-
16757
- /**
16758
- * This method is suitable for fetching files up to size of 64MB.
16759
- * @param file name of the file or URL to load
16760
- * @param callback function to be executed after <a href="#/p5/loadBytes">loadBytes()</a>
16761
- * completes
16762
- * @param errorCallback function to be executed if there
16763
- * is an error
16764
- * @returns a Uint8Array containing the loaded buffer
16765
- */
16766
- function loadBytes(file: string | Request, callback?: Function, errorCallback?: Function): Promise<Uint8Array>;
16767
-
16768
- /**
16769
- * Turns off <a href="#/p5/debugMode">debugMode()</a> in a 3D sketch.
16909
+ * The fourth parameter, `step`, is also optional. It's a number that sets the
16910
+ * spacing between each value in the slider's range. Setting `step` to 0
16911
+ * allows the slider to move smoothly from `min` to `max`.
16912
+ * @param min minimum value of the slider.
16913
+ * @param max maximum value of the slider.
16914
+ * @param value default value of the slider.
16915
+ * @param step size for each step in the slider's range.
16916
+ * @returns new <a href="#/p5.Element">p5.Element</a> object.
16770
16917
  */
16771
- function noDebugMode(): void;
16918
+ function createSlider(min: number, max: number, value?: number, step?: number): P5.Element;
16772
16919
 
16773
16920
  /**
16774
- * Gets the blue value of a color.
16921
+ * Maps a number from one range to a value between 0 and 1.
16775
16922
  *
16776
- * `blue()` extracts the blue value from a
16777
- * <a href="/reference/p5/p5.Color/">p5.Color</a> object, an array of color components, or
16778
- * a CSS color string.
16923
+ * For example, `norm(2, 0, 10)` returns 0.2. 2's position in the original
16924
+ * range [0, 10] is proportional to 0.2's position in the range [0, 1]. This
16925
+ * is the same as calling `map(2, 0, 10, 0, 1)`.
16779
16926
  *
16780
- * By default, `blue()` returns a color's blue value in the range 0
16781
- * to 255. If the <a href="/reference/p5/colorMode/">colorMode()</a> is set to RGB, it
16782
- * returns the blue value in the given range.
16783
- * @param color <a href="/reference/p5/p5.Color/">p5.Color</a> object, array of
16784
- * color components, or CSS color string.
16785
- * @returns the blue value.
16927
+ * Numbers outside of the original range are not constrained between 0 and 1.
16928
+ * Out-of-range values are often intentional and useful.
16929
+ * @param value incoming value to be normalized.
16930
+ * @param start lower bound of the value's current range.
16931
+ * @param stop upper bound of the value's current range.
16932
+ * @returns normalized number.
16786
16933
  */
16787
- function blue(color: P5.Color | number[] | string): number;
16934
+ function norm(value: number, start: number, stop: number): number;
16788
16935
 
16789
16936
  /**
16790
- * Converts a single-character `String` to a `Number`.
16791
- *
16792
- * `unchar()` converts single-character strings to their corresponding
16793
- * integer (whole number).
16794
- *
16795
- * The parameter, `n`, is the character to convert. For example,
16796
- * `unchar('A')`, returns the number 65. If an array is passed, as in
16797
- * `unchar(['A', 'B', 'C'])`, an array of integers is returned.
16798
- * @param n value to convert.
16799
- * @returns converted number.
16800
- */
16801
- function unchar(n: string): number;
16802
- function unchar(ns: string[]): number[];
16803
-
16804
- /**
16805
- * Changes the unit system used to measure angles.
16806
- *
16807
- * Degrees and radians are both units for measuring angles. There are 360˚ in
16808
- * one full rotation. A full rotation is 2 × π (about 6.28) radians.
16809
- *
16810
- * Functions such as <a href="#/p5/rotate">rotate()</a> and
16811
- * <a href="#/p5/sin">sin()</a> expect angles measured radians by default.
16812
- * Calling `angleMode(DEGREES)` switches to degrees. Calling
16813
- * `angleMode(RADIANS)` switches back to radians.
16814
- *
16815
- * Calling `angleMode()` with no arguments returns current angle mode, which
16816
- * is either `RADIANS` or `DEGREES`.
16817
- * @param mode either RADIANS or DEGREES.
16818
- * @returns mode either RADIANS or DEGREES
16819
- */
16820
- function angleMode(mode: typeof P5.RADIANS | typeof P5.DEGREES): typeof P5.RADIANS | typeof P5.DEGREES;
16821
- function angleMode(): typeof P5.RADIANS | typeof P5.DEGREES;
16822
-
16823
- /**
16824
- * Loads the current value of each pixel on the canvas into the
16825
- * <a href="#/p5/pixels">pixels</a> array.
16826
- *
16827
- * `loadPixels()` must be called before reading from or writing to
16828
- * <a href="#/p5/pixels">pixels</a>.
16829
- */
16830
- function loadPixels(): void;
16831
-
16832
- /**
16833
- * Creates a slider `&lt;input&gt;&lt;/input&gt;` element.
16834
- *
16835
- * Range sliders are useful for quickly selecting numbers from a given range.
16836
- *
16837
- * The first two parameters, `min` and `max`, are numbers that set the
16838
- * slider's minimum and maximum.
16839
- *
16840
- * The third parameter, `value`, is optional. It's a number that sets the
16841
- * slider's default value.
16842
- *
16843
- * The fourth parameter, `step`, is also optional. It's a number that sets the
16844
- * spacing between each value in the slider's range. Setting `step` to 0
16845
- * allows the slider to move smoothly from `min` to `max`.
16846
- * @param min minimum value of the slider.
16847
- * @param max maximum value of the slider.
16848
- * @param value default value of the slider.
16849
- * @param step size for each step in the slider's range.
16850
- * @returns new <a href="#/p5.Element">p5.Element</a> object.
16851
- */
16852
- function createSlider(min: number, max: number, value?: number, step?: number): P5.Element;
16853
-
16854
- /**
16855
- * Maps a number from one range to a value between 0 and 1.
16856
- *
16857
- * For example, `norm(2, 0, 10)` returns 0.2. 2's position in the original
16858
- * range [0, 10] is proportional to 0.2's position in the range [0, 1]. This
16859
- * is the same as calling `map(2, 0, 10, 0, 1)`.
16860
- *
16861
- * Numbers outside of the original range are not constrained between 0 and 1.
16862
- * Out-of-range values are often intentional and useful.
16863
- * @param value incoming value to be normalized.
16864
- * @param start lower bound of the value's current range.
16865
- * @param stop upper bound of the value's current range.
16866
- * @returns normalized number.
16867
- */
16868
- function norm(value: number, start: number, stop: number): number;
16869
-
16870
- /**
16871
- * Draws a sphere.
16937
+ * Draws a sphere.
16872
16938
  *
16873
16939
  * A sphere is a 3D shape with triangular faces that connect to form a round
16874
16940
  * surface. Spheres with few faces look like crystals. Spheres with many faces
@@ -16992,45 +17058,6 @@ function pow(n: number, e: number): number;
16992
17058
  */
16993
17059
  function fullscreen(val?: boolean): boolean;
16994
17060
 
16995
- /**
16996
- * Creates a <a href="#/p5.Shader">p5.Shader</a> object to be used with the
16997
- * <a href="#/p5/filter">filter()</a> function using GLSL.
16998
- *
16999
- * Since this method requires you to write your shaders in GLSL, it is most suitable
17000
- * for advanced use cases. Consider using <a href="#/p5/buildFilterShader">`buildFilterShader`</a>
17001
- * first, as a way to create filters in JavaScript using p5.strands.
17002
- *
17003
- * `createFilterShader()` works like
17004
- * <a href="#/p5/createShader">createShader()</a> but has a default vertex
17005
- * shader included. `createFilterShader()` is intended to be used along with
17006
- * <a href="#/p5/filter">filter()</a> for filtering the contents of a canvas.
17007
- * A filter shader will be applied to the whole canvas instead of just
17008
- * <a href="#/p5.Geometry">p5.Geometry</a> objects.
17009
- *
17010
- * The parameter, `fragSrc`, sets the fragment shader. It’s a string that
17011
- * contains the fragment shader program written in
17012
- * <a href="https://developer.mozilla.org/en-US/docs/Games/Techniques/3D_on_the_web/GLSL_Shaders" target="_blank">GLSL</a>.
17013
- *
17014
- * The <a href="#/p5.Shader">p5.Shader</a> object that's created has some
17015
- * uniforms that can be set:
17016
- *
17017
- * - `sampler2D tex0`, which contains the canvas contents as a texture.
17018
- *
17019
- * - `vec2 canvasSize`, which is the width and height of the canvas, not including pixel density.
17020
- *
17021
- * - `vec2 texelSize`, which is the size of a physical pixel including pixel density. This is calculated as `1.0 / (width * density)` for the pixel width and `1.0 / (height * density)` for the pixel height.
17022
- *
17023
- * The <a href="#/p5.Shader">p5.Shader</a> that's created also provides
17024
- * `varying vec2 vTexCoord`, a coordinate with values between 0 and 1.
17025
- * `vTexCoord` describes where on the canvas the pixel will be drawn.
17026
- *
17027
- * For more info about filters and shaders, see Adam Ferriss' <a href="https://github.com/aferriss/p5jsShaderExamples">repo of shader examples</a>
17028
- * or the <a href="https://p5js.org/learn/getting-started-in-webgl-shaders.html">Introduction to Shaders</a> tutorial.
17029
- * @param fragSrc source code for the fragment shader.
17030
- * @returns new shader object created from the fragment shader.
17031
- */
17032
- function createFilterShader(fragSrc: string): P5.Shader;
17033
-
17034
17061
  /**
17035
17062
  * Creates a light that shines from a point in all directions.
17036
17063
  *
@@ -17138,6 +17165,45 @@ function alpha(color: P5.Color | number[] | string): number;
17138
17165
  */
17139
17166
  function createButton(label: string, value?: string): P5.Element;
17140
17167
 
17168
+ /**
17169
+ * Creates a <a href="#/p5.Shader">p5.Shader</a> object to be used with the
17170
+ * <a href="#/p5/filter">filter()</a> function using GLSL.
17171
+ *
17172
+ * Since this method requires you to write your shaders in GLSL, it is most suitable
17173
+ * for advanced use cases. Consider using <a href="#/p5/buildFilterShader">`buildFilterShader`</a>
17174
+ * first, as a way to create filters in JavaScript using p5.strands.
17175
+ *
17176
+ * `createFilterShader()` works like
17177
+ * <a href="#/p5/createShader">createShader()</a> but has a default vertex
17178
+ * shader included. `createFilterShader()` is intended to be used along with
17179
+ * <a href="#/p5/filter">filter()</a> for filtering the contents of a canvas.
17180
+ * A filter shader will be applied to the whole canvas instead of just
17181
+ * <a href="#/p5.Geometry">p5.Geometry</a> objects.
17182
+ *
17183
+ * The parameter, `fragSrc`, sets the fragment shader. It’s a string that
17184
+ * contains the fragment shader program written in
17185
+ * <a href="https://developer.mozilla.org/en-US/docs/Games/Techniques/3D_on_the_web/GLSL_Shaders" target="_blank">GLSL</a>.
17186
+ *
17187
+ * The <a href="#/p5.Shader">p5.Shader</a> object that's created has some
17188
+ * uniforms that can be set:
17189
+ *
17190
+ * - `sampler2D tex0`, which contains the canvas contents as a texture.
17191
+ *
17192
+ * - `vec2 canvasSize`, which is the width and height of the canvas, not including pixel density.
17193
+ *
17194
+ * - `vec2 texelSize`, which is the size of a physical pixel including pixel density. This is calculated as `1.0 / (width * density)` for the pixel width and `1.0 / (height * density)` for the pixel height.
17195
+ *
17196
+ * The <a href="#/p5.Shader">p5.Shader</a> that's created also provides
17197
+ * `varying vec2 vTexCoord`, a coordinate with values between 0 and 1.
17198
+ * `vTexCoord` describes where on the canvas the pixel will be drawn.
17199
+ *
17200
+ * For more info about filters and shaders, see Adam Ferriss' <a href="https://github.com/aferriss/p5jsShaderExamples">repo of shader examples</a>
17201
+ * or the <a href="https://p5js.org/learn/getting-started-in-webgl-shaders.html">Introduction to Shaders</a> tutorial.
17202
+ * @param fragSrc source code for the fragment shader.
17203
+ * @returns new shader object created from the fragment shader.
17204
+ */
17205
+ function createFilterShader(fragSrc: string): P5.Shader;
17206
+
17141
17207
  /**
17142
17208
  * Concludes the vertices of a custom shape.
17143
17209
  *
@@ -17815,169 +17881,6 @@ function normal(x: number, y: number, z: number): void;
17815
17881
  function 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;
17816
17882
  function 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;
17817
17883
 
17818
- /**
17819
- * Sets the <a href="#/p5.Shader">p5.Shader</a> object to apply while drawing.
17820
- *
17821
- * Shaders are programs that run on the graphics processing unit (GPU). They
17822
- * can process many pixels or vertices at the same time, making them fast for
17823
- * many graphics tasks.
17824
- *
17825
- * You can make new shaders using p5.strands with the
17826
- * <a href="#/p5/buildMaterialShader">`buildMaterialShader`</a>,
17827
- * <a href="#/p5/buildColorShader">`buildColorShader`</a>, and
17828
- * <a href="#/p5/buildNormalShader">`buildNormalShader`</a> functions. You can also use
17829
- * <a href="#/p5/buildFilterShader">`buildFilterShader`</a> alongside
17830
- * <a href="#/p5/filter">`filter`</a>, and
17831
- * <a href="#/p5/buildStrokeShader">`buildStrokeShader`</a> alongside
17832
- * <a href="#/p5/stroke">`stroke`</a>.
17833
- *
17834
- * The parameter, `s`, is the <a href="#/p5.Shader">p5.Shader</a> object to
17835
- * apply. For example, calling `shader(myShader)` applies `myShader` to
17836
- * process each pixel on the canvas. This only changes the fill (the inner part of shapes),
17837
- * but does not affect the outlines (strokes) or any images drawn using the `image()` function.
17838
- * The source code from a <a href="#/p5.Shader">p5.Shader</a> object's
17839
- * fragment and vertex shaders will be compiled the first time it's passed to
17840
- * `shader()`.
17841
- *
17842
- * Calling <a href="#/p5/resetShader">resetShader()</a> restores a sketch’s
17843
- * default shaders.
17844
- *
17845
- * Note: Shaders can only be used in WebGL mode.
17846
- *
17847
- * `let myShader;
17848
- *
17849
- * function setup() {
17850
- * createCanvas(200, 200, WEBGL);
17851
- * myShader = buildMaterialShader(material);
17852
- * noStroke();
17853
- * describe('A square with dynamically changing colors on a beige background.');
17854
- * }
17855
- *
17856
- * function material() {
17857
- * let time = uniformFloat();
17858
- * finalColor.begin();
17859
- * let r = 0.2 + 0.5 * abs(sin(time + 0));
17860
- * let g = 0.2 + 0.5 * abs(sin(time + 1));
17861
- * let b = 0.2 + 0.5 * abs(sin(time + 2));
17862
- * finalColor.set([r, g, b, 1]);
17863
- * finalColor.end();
17864
- * }
17865
- *
17866
- * function draw() {
17867
- * background(245, 245, 220);
17868
- * myShader.setUniform('time', millis() / 1000);
17869
- * shader(myShader);
17870
- *
17871
- * rectMode(CENTER);
17872
- * rect(0, 0, 50, 50);
17873
- * }`For advanced usage, shaders can be written in a language called
17874
- * <a href="https://developer.mozilla.org/en-US/docs/Games/Techniques/3D_on_the_web/GLSL_Shaders" target="_blank">GLSL</a>.
17875
- * <a href="#/p5.Shader">p5.Shader</a> objects can be created in this way using the
17876
- * <a href="#/p5/createShader">createShader()</a> and
17877
- * <a href="#/p5/loadShader">loadShader()</a> functions.
17878
- *
17879
- * `let fillShader;
17880
- *
17881
- * let vertSrc = `
17882
- * precision highp float;
17883
- * attribute vec3 aPosition;
17884
- * uniform mat4 uModelViewMatrix;
17885
- * uniform mat4 uProjectionMatrix;
17886
- * varying vec3 vPosition;
17887
- *
17888
- * void main() {
17889
- * vPosition = aPosition;
17890
- * gl_Position = uProjectionMatrix * uModelViewMatrix * vec4(aPosition, 1.0);
17891
- * }
17892
- * `;
17893
- *
17894
- * let fragSrc = `
17895
- * precision highp float;
17896
- * uniform vec3 uLightDir;
17897
- * varying vec3 vPosition;
17898
- *
17899
- * void main() {
17900
- * vec3 lightDir = normalize(uLightDir);
17901
- * float brightness = dot(lightDir, normalize(vPosition));
17902
- * brightness = clamp(brightness, 0.4, 1.0);
17903
- * vec3 color = vec3(0.3, 0.5, 1.0);
17904
- * color = color * brightness * 3.0;
17905
- * gl_FragColor = vec4(color, 1.0);
17906
- * }
17907
- * `;
17908
- *
17909
- * function setup() {
17910
- * createCanvas(200, 200, WEBGL);
17911
- * fillShader = createShader(vertSrc, fragSrc);
17912
- * noStroke();
17913
- * describe('A rotating torus with simulated directional lighting.');
17914
- * }
17915
- *
17916
- * function draw() {
17917
- * background(20, 20, 40);
17918
- * let lightDir = [0.5, 0.5, 1.0];
17919
- * fillShader.setUniform('uLightDir', lightDir);
17920
- * shader(fillShader);
17921
- * rotateY(frameCount * 0.02);
17922
- * rotateX(frameCount * 0.02);
17923
- * torus(25, 10, 30, 30);
17924
- * }``let fillShader;
17925
- *
17926
- * let vertSrc = `
17927
- * precision highp float;
17928
- * attribute vec3 aPosition;
17929
- * uniform mat4 uProjectionMatrix;
17930
- * uniform mat4 uModelViewMatrix;
17931
- * varying vec3 vPosition;
17932
- * void main() {
17933
- * vPosition = aPosition;
17934
- * gl_Position = uProjectionMatrix * uModelViewMatrix * vec4(aPosition, 1.0);
17935
- * }
17936
- * `;
17937
- *
17938
- * let fragSrc = `
17939
- * precision highp float;
17940
- * uniform vec3 uLightPos;
17941
- * uniform vec3 uFillColor;
17942
- * varying vec3 vPosition;
17943
- * void main() {
17944
- * float brightness = dot(normalize(uLightPos), normalize(vPosition));
17945
- * brightness = clamp(brightness, 0.0, 1.0);
17946
- * vec3 color = uFillColor * brightness;
17947
- * gl_FragColor = vec4(color, 1.0);
17948
- * }
17949
- * `;
17950
- *
17951
- * function setup() {
17952
- * createCanvas(200, 200, WEBGL);
17953
- * fillShader = createShader(vertSrc, fragSrc);
17954
- * shader(fillShader);
17955
- * noStroke();
17956
- * describe('A square affected by both fill color and lighting, with lights controlled by mouse.');
17957
- * }
17958
- *
17959
- * function draw() {
17960
- * let lightPos = [(mouseX - width / 2) / width,
17961
- * (mouseY - height / 2) / height, 1.0];
17962
- * fillShader.setUniform('uLightPos', lightPos);
17963
- * let fillColor = [map(mouseX, 0, width, 0, 1),
17964
- * map(mouseY, 0, height, 0, 1), 0.5];
17965
- * fillShader.setUniform('uFillColor', fillColor);
17966
- * plane(width, height);
17967
- * }`<div>
17968
- * <p>If you want to apply shaders to strokes or images, use the following methods:
17969
- *
17970
- * - <a href="#/p5/strokeShader">strokeShader()</a> : Applies a shader to the stroke (outline) of shapes, allowing independent control over the stroke rendering using shaders.
17971
- *
17972
- * - <a href="#/p5/imageShader">imageShader()</a> : Applies a shader to images or textures, controlling how the shader modifies their appearance during rendering.
17973
- *
17974
- * </p>
17975
- * </div>
17976
- * @param s <a href="#/p5.Shader">p5.Shader</a> object
17977
- * to apply.
17978
- */
17979
- function shader(s: P5.Shader): void;
17980
-
17981
17884
  /**
17982
17885
  * Returns the current
17983
17886
  * <a href="https://developer.mozilla.org/en-US/docs/Learn/Common_questions/Web_mechanics/What_is_a_URL#parameters" target="_blank">URL parameters</a>
@@ -18163,61 +18066,213 @@ function mouseMoved(event?: MouseEvent): void;
18163
18066
  * // Code to run if the mouse is on the left.
18164
18067
  * }
18165
18068
  *
18166
- * if (mouseY > 50) {
18167
- * // Code to run if the mouse is near the bottom.
18069
+ * if (mouseY > 50) {
18070
+ * // Code to run if the mouse is near the bottom.
18071
+ * }
18072
+ * }`The parameter, `event`, is optional. `mouseDragged()` is always passed a
18073
+ * <a href="https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent" target="_blank">MouseEvent</a>
18074
+ * object with properties that describe the mouse drag event:
18075
+ *
18076
+ * `function mouseDragged(event) {
18077
+ * // Code to run that uses the event.
18078
+ * console.log(event);
18079
+ * }`On touchscreen devices, `mouseDragged()` will run when a user moves a touch
18080
+ * point.
18081
+ *
18082
+ * Browsers may have default behaviors attached to various mouse events. For
18083
+ * example, some browsers highlight text when the user moves the mouse while
18084
+ * pressing a mouse button. To prevent any default behavior for this event,
18085
+ * add `return false;` to the end of the function.
18086
+ * @param event optional `MouseEvent` argument.
18087
+ */
18088
+ function mouseDragged(event?: MouseEvent): void;
18089
+
18090
+ /**
18091
+ * Returns `true` if the key it’s checking is pressed and `false` if not.
18092
+ *
18093
+ * `keyIsDown()` is helpful when checking for multiple different key presses.
18094
+ * For example, `keyIsDown()` can be used to check if both `LEFT_ARROW` and
18095
+ * `UP_ARROW` are pressed:
18096
+ *
18097
+ * `if (keyIsDown(LEFT_ARROW) && keyIsDown(UP_ARROW)) {
18098
+ * // Move diagonally.
18099
+ * }``keyIsDown()` can check for key presses using strings based on
18100
+ * <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key" target="_blank">KeyboardEvent.key</a>
18101
+ * or <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code" target="_blank">KeyboardEvent.code</a> values,
18102
+ * such as `keyIsDown('x')` or `keyIsDown('ArrowLeft')`.
18103
+ *
18104
+ * Note: In p5.js 2.0 and newer, numeric keycodes (such as 88 for 'X') are no longer supported.
18105
+ * This is a breaking change from previous versions.
18106
+ *
18107
+ * You can still use the p5 constants like `LEFT_ARROW` which now map to string values
18108
+ * internally rather than numeric codes.
18109
+ * @param code key to check.
18110
+ * @returns whether the key is down or not.
18111
+ */
18112
+ function keyIsDown(code: number | string): boolean;
18113
+
18114
+ /**
18115
+ * Sets the <a href="#/p5.Shader">p5.Shader</a> object to apply while drawing.
18116
+ *
18117
+ * Shaders are programs that run on the graphics processing unit (GPU). They
18118
+ * can process many pixels or vertices at the same time, making them fast for
18119
+ * many graphics tasks.
18120
+ *
18121
+ * You can make new shaders using p5.strands with the
18122
+ * <a href="#/p5/buildMaterialShader">`buildMaterialShader`</a>,
18123
+ * <a href="#/p5/buildColorShader">`buildColorShader`</a>, and
18124
+ * <a href="#/p5/buildNormalShader">`buildNormalShader`</a> functions. You can also use
18125
+ * <a href="#/p5/buildFilterShader">`buildFilterShader`</a> alongside
18126
+ * <a href="#/p5/filter">`filter`</a>, and
18127
+ * <a href="#/p5/buildStrokeShader">`buildStrokeShader`</a> alongside
18128
+ * <a href="#/p5/stroke">`stroke`</a>.
18129
+ *
18130
+ * The parameter, `s`, is the <a href="#/p5.Shader">p5.Shader</a> object to
18131
+ * apply. For example, calling `shader(myShader)` applies `myShader` to
18132
+ * process each pixel on the canvas. This only changes the fill (the inner part of shapes),
18133
+ * but does not affect the outlines (strokes) or any images drawn using the `image()` function.
18134
+ * The source code from a <a href="#/p5.Shader">p5.Shader</a> object's
18135
+ * fragment and vertex shaders will be compiled the first time it's passed to
18136
+ * `shader()`.
18137
+ *
18138
+ * Calling <a href="#/p5/resetShader">resetShader()</a> restores a sketch’s
18139
+ * default shaders.
18140
+ *
18141
+ * Note: Shaders can only be used in WebGL mode.
18142
+ *
18143
+ * `let myShader;
18144
+ *
18145
+ * function setup() {
18146
+ * createCanvas(200, 200, WEBGL);
18147
+ * myShader = buildMaterialShader(material);
18148
+ * noStroke();
18149
+ * describe('A square with dynamically changing colors on a beige background.');
18150
+ * }
18151
+ *
18152
+ * function material() {
18153
+ * let time = uniformFloat();
18154
+ * finalColor.begin();
18155
+ * let r = 0.2 + 0.5 * abs(sin(time + 0));
18156
+ * let g = 0.2 + 0.5 * abs(sin(time + 1));
18157
+ * let b = 0.2 + 0.5 * abs(sin(time + 2));
18158
+ * finalColor.set([r, g, b, 1]);
18159
+ * finalColor.end();
18160
+ * }
18161
+ *
18162
+ * function draw() {
18163
+ * background(245, 245, 220);
18164
+ * myShader.setUniform('time', millis() / 1000);
18165
+ * shader(myShader);
18166
+ *
18167
+ * rectMode(CENTER);
18168
+ * rect(0, 0, 50, 50);
18169
+ * }`For advanced usage, shaders can be written in a language called
18170
+ * <a href="https://developer.mozilla.org/en-US/docs/Games/Techniques/3D_on_the_web/GLSL_Shaders" target="_blank">GLSL</a>.
18171
+ * <a href="#/p5.Shader">p5.Shader</a> objects can be created in this way using the
18172
+ * <a href="#/p5/createShader">createShader()</a> and
18173
+ * <a href="#/p5/loadShader">loadShader()</a> functions.
18174
+ *
18175
+ * `let fillShader;
18176
+ *
18177
+ * let vertSrc = `
18178
+ * precision highp float;
18179
+ * attribute vec3 aPosition;
18180
+ * uniform mat4 uModelViewMatrix;
18181
+ * uniform mat4 uProjectionMatrix;
18182
+ * varying vec3 vPosition;
18183
+ *
18184
+ * void main() {
18185
+ * vPosition = aPosition;
18186
+ * gl_Position = uProjectionMatrix * uModelViewMatrix * vec4(aPosition, 1.0);
18187
+ * }
18188
+ * `;
18189
+ *
18190
+ * let fragSrc = `
18191
+ * precision highp float;
18192
+ * uniform vec3 uLightDir;
18193
+ * varying vec3 vPosition;
18194
+ *
18195
+ * void main() {
18196
+ * vec3 lightDir = normalize(uLightDir);
18197
+ * float brightness = dot(lightDir, normalize(vPosition));
18198
+ * brightness = clamp(brightness, 0.4, 1.0);
18199
+ * vec3 color = vec3(0.3, 0.5, 1.0);
18200
+ * color = color * brightness * 3.0;
18201
+ * gl_FragColor = vec4(color, 1.0);
18202
+ * }
18203
+ * `;
18204
+ *
18205
+ * function setup() {
18206
+ * createCanvas(200, 200, WEBGL);
18207
+ * fillShader = createShader(vertSrc, fragSrc);
18208
+ * noStroke();
18209
+ * describe('A rotating torus with simulated directional lighting.');
18168
18210
  * }
18169
- * }`The parameter, `event`, is optional. `mouseDragged()` is always passed a
18170
- * <a href="https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent" target="_blank">MouseEvent</a>
18171
- * object with properties that describe the mouse drag event:
18172
18211
  *
18173
- * `function mouseDragged(event) {
18174
- * // Code to run that uses the event.
18175
- * console.log(event);
18176
- * }`On touchscreen devices, `mouseDragged()` will run when a user moves a touch
18177
- * point.
18212
+ * function draw() {
18213
+ * background(20, 20, 40);
18214
+ * let lightDir = [0.5, 0.5, 1.0];
18215
+ * fillShader.setUniform('uLightDir', lightDir);
18216
+ * shader(fillShader);
18217
+ * rotateY(frameCount * 0.02);
18218
+ * rotateX(frameCount * 0.02);
18219
+ * torus(25, 10, 30, 30);
18220
+ * }``let fillShader;
18178
18221
  *
18179
- * Browsers may have default behaviors attached to various mouse events. For
18180
- * example, some browsers highlight text when the user moves the mouse while
18181
- * pressing a mouse button. To prevent any default behavior for this event,
18182
- * add `return false;` to the end of the function.
18183
- * @param event optional `MouseEvent` argument.
18184
- */
18185
- function mouseDragged(event?: MouseEvent): void;
18186
-
18187
- /**
18188
- * Returns `true` if the key it’s checking is pressed and `false` if not.
18222
+ * let vertSrc = `
18223
+ * precision highp float;
18224
+ * attribute vec3 aPosition;
18225
+ * uniform mat4 uProjectionMatrix;
18226
+ * uniform mat4 uModelViewMatrix;
18227
+ * varying vec3 vPosition;
18228
+ * void main() {
18229
+ * vPosition = aPosition;
18230
+ * gl_Position = uProjectionMatrix * uModelViewMatrix * vec4(aPosition, 1.0);
18231
+ * }
18232
+ * `;
18189
18233
  *
18190
- * `keyIsDown()` is helpful when checking for multiple different key presses.
18191
- * For example, `keyIsDown()` can be used to check if both `LEFT_ARROW` and
18192
- * `UP_ARROW` are pressed:
18234
+ * let fragSrc = `
18235
+ * precision highp float;
18236
+ * uniform vec3 uLightPos;
18237
+ * uniform vec3 uFillColor;
18238
+ * varying vec3 vPosition;
18239
+ * void main() {
18240
+ * float brightness = dot(normalize(uLightPos), normalize(vPosition));
18241
+ * brightness = clamp(brightness, 0.0, 1.0);
18242
+ * vec3 color = uFillColor * brightness;
18243
+ * gl_FragColor = vec4(color, 1.0);
18244
+ * }
18245
+ * `;
18193
18246
  *
18194
- * `if (keyIsDown(LEFT_ARROW) && keyIsDown(UP_ARROW)) {
18195
- * // Move diagonally.
18196
- * }``keyIsDown()` can check for key presses using strings based on
18197
- * <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key" target="_blank">KeyboardEvent.key</a>
18198
- * or <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code" target="_blank">KeyboardEvent.code</a> values,
18199
- * such as `keyIsDown('x')` or `keyIsDown('ArrowLeft')`.
18247
+ * function setup() {
18248
+ * createCanvas(200, 200, WEBGL);
18249
+ * fillShader = createShader(vertSrc, fragSrc);
18250
+ * shader(fillShader);
18251
+ * noStroke();
18252
+ * describe('A square affected by both fill color and lighting, with lights controlled by mouse.');
18253
+ * }
18200
18254
  *
18201
- * Note: In p5.js 2.0 and newer, numeric keycodes (such as 88 for 'X') are no longer supported.
18202
- * This is a breaking change from previous versions.
18255
+ * function draw() {
18256
+ * let lightPos = [(mouseX - width / 2) / width,
18257
+ * (mouseY - height / 2) / height, 1.0];
18258
+ * fillShader.setUniform('uLightPos', lightPos);
18259
+ * let fillColor = [map(mouseX, 0, width, 0, 1),
18260
+ * map(mouseY, 0, height, 0, 1), 0.5];
18261
+ * fillShader.setUniform('uFillColor', fillColor);
18262
+ * plane(width, height);
18263
+ * }`<div>
18264
+ * <p>If you want to apply shaders to strokes or images, use the following methods:
18203
18265
  *
18204
- * You can still use the p5 constants like `LEFT_ARROW` which now map to string values
18205
- * internally rather than numeric codes.
18206
- * @param code key to check.
18207
- * @returns whether the key is down or not.
18208
- */
18209
- function keyIsDown(code: number | string): boolean;
18210
-
18211
- /**
18212
- * Sets the element's content.
18266
+ * - <a href="#/p5/strokeShader">strokeShader()</a> : Applies a shader to the stroke (outline) of shapes, allowing independent control over the stroke rendering using shaders.
18213
18267
  *
18214
- * An element's content is the text between its tags. For example, the element
18215
- * `&lt;language&gt;JavaScript&lt;/language&gt;` has the content `JavaScript`.
18268
+ * - <a href="#/p5/imageShader">imageShader()</a> : Applies a shader to images or textures, controlling how the shader modifies their appearance during rendering.
18216
18269
  *
18217
- * The parameter, `content`, is a string with the element's new content.
18218
- * @param content new content for the element.
18270
+ * </p>
18271
+ * </div>
18272
+ * @param s <a href="#/p5.Shader">p5.Shader</a> object
18273
+ * to apply.
18219
18274
  */
18220
- function setContent(content: string): void;
18275
+ function shader(s: P5.Shader): void;
18221
18276
 
18222
18277
  /**
18223
18278
  * Draws a <a href="#/p5.Geometry">p5.Geometry</a> object to the canvas.
@@ -18236,6 +18291,17 @@ function setContent(content: string): void;
18236
18291
  */
18237
18292
  function model(model: P5.Geometry, count?: number): void;
18238
18293
 
18294
+ /**
18295
+ * Sets the element's content.
18296
+ *
18297
+ * An element's content is the text between its tags. For example, the element
18298
+ * `&lt;language&gt;JavaScript&lt;/language&gt;` has the content `JavaScript`.
18299
+ *
18300
+ * The parameter, `content`, is a string with the element's new content.
18301
+ * @param content new content for the element.
18302
+ */
18303
+ function setContent(content: string): void;
18304
+
18239
18305
  /**
18240
18306
  * Method for executing an HTTP request. If data type is not specified,
18241
18307
  * it will default to `'text'`.
@@ -18515,26 +18581,6 @@ function vertexProperty(attributeName: string, data: number | number[]): void;
18515
18581
  */
18516
18582
  function square(x: number, y: number, s: number, tl?: number, tr?: number, br?: number, bl?: number): void;
18517
18583
 
18518
- /**
18519
- * Sets the <a href="#/p5.Shader">p5.Shader</a> object to apply for strokes.
18520
- *
18521
- * This method applies the given shader to strokes, allowing customization of
18522
- * how lines and outlines are drawn in 3D space. The shader will be used for
18523
- * strokes until <a href="#/p5/resetShader">resetShader()</a> is called or another
18524
- * strokeShader is applied.
18525
- *
18526
- * The shader will be used for:
18527
- *
18528
- * - Strokes only, regardless of whether the uniform `uStrokeWeight` is present.
18529
- *
18530
- * To further customize its behavior, refer to the various hooks provided by
18531
- * the <a href="#/p5/baseStrokeShader">baseStrokeShader()</a> method, which allow
18532
- * control over stroke weight, vertex positions, colors, and more.
18533
- * @param s <a href="#/p5.Shader">p5.Shader</a> object
18534
- * to apply for strokes.
18535
- */
18536
- function strokeShader(s: P5.Shader): void;
18537
-
18538
18584
  /**
18539
18585
  * Converts 2D screen coordinates to 3D world coordinates.
18540
18586
  *
@@ -18596,6 +18642,26 @@ function screenToWorld(x: number | P5.Vector, y: number, z?: number): P5.Vector;
18596
18642
  */
18597
18643
  function mousePressed(event?: MouseEvent): void;
18598
18644
 
18645
+ /**
18646
+ * Sets the <a href="#/p5.Shader">p5.Shader</a> object to apply for strokes.
18647
+ *
18648
+ * This method applies the given shader to strokes, allowing customization of
18649
+ * how lines and outlines are drawn in 3D space. The shader will be used for
18650
+ * strokes until <a href="#/p5/resetShader">resetShader()</a> is called or another
18651
+ * strokeShader is applied.
18652
+ *
18653
+ * The shader will be used for:
18654
+ *
18655
+ * - Strokes only, regardless of whether the uniform `uStrokeWeight` is present.
18656
+ *
18657
+ * To further customize its behavior, refer to the various hooks provided by
18658
+ * the <a href="#/p5/baseStrokeShader">baseStrokeShader()</a> method, which allow
18659
+ * control over stroke weight, vertex positions, colors, and more.
18660
+ * @param s <a href="#/p5.Shader">p5.Shader</a> object
18661
+ * to apply for strokes.
18662
+ */
18663
+ function strokeShader(s: P5.Shader): void;
18664
+
18599
18665
  /**
18600
18666
  * Tints images using a color.
18601
18667
  *
@@ -19192,25 +19258,6 @@ function ellipsoid(radiusX?: number, radiusY?: number, radiusZ?: number, detailX
19192
19258
  */
19193
19259
  function noFill(): void;
19194
19260
 
19195
- /**
19196
- * Sets the <a href="#/p5.Shader">p5.Shader</a> object to apply for images.
19197
- *
19198
- * This method allows the user to apply a custom shader to images, enabling
19199
- * advanced visual effects such as pixel manipulation, color adjustments,
19200
- * or dynamic behavior. The shader will be applied to the image drawn using
19201
- * the <a href="#/p5/image">image()</a> function.
19202
- *
19203
- * The shader will be used exclusively for:
19204
- *
19205
- * - `image()` calls, applying only when drawing 2D images.
19206
- *
19207
- * - This shader will NOT apply to images used in <a href="#/p5/texture">texture()</a> or other 3D contexts.
19208
- * Any attempts to use the imageShader in these cases will be ignored.
19209
- * @param s <a href="#/p5.Shader">p5.Shader</a> object
19210
- * to apply for images.
19211
- */
19212
- function imageShader(s: P5.Shader): void;
19213
-
19214
19261
  /**
19215
19262
  * Removes all lights from the sketch.
19216
19263
  *
@@ -19319,6 +19366,25 @@ function imageMode(mode: typeof P5.CORNER | typeof P5.CORNERS | typeof P5.CENTER
19319
19366
  */
19320
19367
  function mouseReleased(event?: MouseEvent): void;
19321
19368
 
19369
+ /**
19370
+ * Sets the <a href="#/p5.Shader">p5.Shader</a> object to apply for images.
19371
+ *
19372
+ * This method allows the user to apply a custom shader to images, enabling
19373
+ * advanced visual effects such as pixel manipulation, color adjustments,
19374
+ * or dynamic behavior. The shader will be applied to the image drawn using
19375
+ * the <a href="#/p5/image">image()</a> function.
19376
+ *
19377
+ * The shader will be used exclusively for:
19378
+ *
19379
+ * - `image()` calls, applying only when drawing 2D images.
19380
+ *
19381
+ * - This shader will NOT apply to images used in <a href="#/p5/texture">texture()</a> or other 3D contexts.
19382
+ * Any attempts to use the imageShader in these cases will be ignored.
19383
+ * @param s <a href="#/p5.Shader">p5.Shader</a> object
19384
+ * to apply for images.
19385
+ */
19386
+ function imageShader(s: P5.Shader): void;
19387
+
19322
19388
  /**
19323
19389
  * Disables drawing points, lines, and the outlines of shapes.
19324
19390
  *
@@ -19436,11 +19502,11 @@ function loadFont(path: string, successCallback?: (font: P5.Font) => any, failur
19436
19502
  * values. 0 is equal to the first color, 0.1 is very near the first color,
19437
19503
  * 0.5 is halfway between the two colors, and so on. Negative numbers are set
19438
19504
  * to 0. Numbers greater than 1 are set to 1. This differs from the behavior of
19439
- * <a href="#/lerp">lerp</a>. It's necessary because numbers outside of the
19505
+ * <a href="#/p5/lerp">lerp</a>. It's necessary because numbers outside of the
19440
19506
  * interval [0, 1] will produce strange and unexpected colors.
19441
19507
  *
19442
19508
  * The way that colors are interpolated depends on the current
19443
- * <a href="#/colorMode">colorMode()</a>.
19509
+ * <a href="#/p5/colorMode">colorMode()</a>.
19444
19510
  * @param c1 interpolate from this color.
19445
19511
  * @param c2 interpolate to this color.
19446
19512
  * @param amt number between 0 and 1.
@@ -19736,10 +19802,11 @@ function mouseClicked(event?: MouseEvent): void;
19736
19802
  * Read the <a href="#/p5.Shader/modify">reference entry for `modify()`</a>
19737
19803
  * for more info.
19738
19804
  * @param callback A function building a p5.strands shader.
19805
+ * @param scope An optional scope object passed to .modify().
19739
19806
  * @returns The material shader.
19740
19807
  */
19741
- function buildMaterialShader(callback: Function): P5.Shader;
19742
- function buildMaterialShader(hooks: object): P5.Shader;
19808
+ function buildMaterialShader(callback: Function, scope?: object): P5.Shader;
19809
+ function buildMaterialShader(hooks: object, scope?: object): P5.Shader;
19743
19810
 
19744
19811
  /**
19745
19812
  * Creates a `&lt;video&gt;` element that "captures" the audio/video stream from
@@ -19772,62 +19839,15 @@ function buildMaterialShader(hooks: object): P5.Shader;
19772
19839
  * <a href="http://stackoverflow.com/questions/34197653/getusermedia-in-chrome-47-without-using-https" target="_blank">here</a>
19773
19840
  * and <a href="https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia" target="_blank">here</a>.
19774
19841
  * @param type type of capture, either AUDIO or VIDEO,
19775
- * or a constraints object. Both video and audio
19776
- * audio streams are captured by default.
19777
- * @param flipped flip the capturing video and mirror the output with `{flipped:true}`. By
19778
- * default it is false.
19779
- * @param callback function to call once the stream
19780
- * has loaded.
19781
- * @returns new <a href="#/p5.MediaElement">p5.MediaElement</a> object.
19782
- */
19783
- function createCapture(type?: typeof P5.AUDIO | typeof P5.VIDEO | object, flipped?: object, callback?: Function): P5.MediaElement;
19784
-
19785
- /**
19786
- * Loads a new shader from a file that can change how fills are drawn. Pass the resulting
19787
- * shader into the <a href="#/p5/shader">`shader()`</a> function to apply it
19788
- * to any fills you draw.
19789
- *
19790
- * Since this function loads data from another file, it returns a `Promise`.
19791
- * Use it in an `async function setup`, and `await` its result.
19792
- *
19793
- * `let myShader;
19794
- * async function setup() {
19795
- * createCanvas(200, 200, WEBGL);
19796
- * myShader = await loadMaterialShader('myMaterial.js');
19797
- * }
19798
- *
19799
- * function draw() {
19800
- * background(255);
19801
- * shader(myShader);
19802
- * myShader.setUniform('time', millis());
19803
- * lights();
19804
- * noStroke();
19805
- * fill('red');
19806
- * sphere(50);
19807
- * }`Inside your shader file, you can call p5.strands hooks to change parts of the shader. For
19808
- * example, you might use the `worldInputs` hook to change each vertex, or you
19809
- * might use the `pixelInputs` hook to change each pixel on the surface of a shape.
19810
- *
19811
- * `// myMaterial.js
19812
- * let time = uniformFloat();
19813
- * worldInputs.begin();
19814
- * worldInputs.position.y +=
19815
- * 20 * sin(time * 0.001 + worldInputs.position.x * 0.05);
19816
- * worldInputs.end();`Read the reference for <a href="#/p5/buildMaterialShader">`buildMaterialShader`</a>,
19817
- * the version of `loadMaterialShader` that takes in a function instead of a separate file,
19818
- * for a full list of hooks you can use and examples for each.
19819
- *
19820
- * The second parameter, `successCallback`, is optional. If a function is passed, as in
19821
- * `loadMaterialShader('myShader.js', onLoaded)`, then the `onLoaded()` function will be called
19822
- * once the shader loads. The shader will be passed to `onLoaded()` as its only argument.
19823
- * The return value of `handleData()`, if present, will be used as the final return value of
19824
- * `loadMaterialShader('myShader.js', onLoaded)`.
19825
- * @param url The URL of your p5.strands JavaScript file.
19826
- * @param onSuccess A callback function to run when loading completes.
19827
- * @param onFailure A callback function to run when loading fails.
19828
- * @returns The material shader.
19842
+ * or a constraints object. Both video and audio
19843
+ * audio streams are captured by default.
19844
+ * @param flipped flip the capturing video and mirror the output with `{flipped:true}`. By
19845
+ * default it is false.
19846
+ * @param callback function to call once the stream
19847
+ * has loaded.
19848
+ * @returns new <a href="#/p5.MediaElement">p5.MediaElement</a> object.
19829
19849
  */
19830
- function loadMaterialShader(url: string, onSuccess?: Function, onFailure?: Function): Promise<P5.Shader>;
19850
+ function createCapture(type?: typeof P5.AUDIO | typeof P5.VIDEO | object, flipped?: object, callback?: Function): P5.MediaElement;
19831
19851
 
19832
19852
  /**
19833
19853
  * Sets the color used to draw points, lines, and the outlines of shapes.
@@ -19918,30 +19938,51 @@ function createColorPicker(value?: string | P5.Color): P5.Element;
19918
19938
  function save(objectOrFilename?: object | string, filename?: string, options?: boolean | string): void;
19919
19939
 
19920
19940
  /**
19921
- * Returns the default shader used for fills when lights or textures are used.
19941
+ * Loads a new shader from a file that can change how fills are drawn. Pass the resulting
19942
+ * shader into the <a href="#/p5/shader">`shader()`</a> function to apply it
19943
+ * to any fills you draw.
19922
19944
  *
19923
- * Calling <a href="#/p5/buildMaterialShader">`buildMaterialShader(shaderFunction)`</a>
19924
- * is equivalent to calling `baseMaterialShader().modify(shaderFunction)`.
19945
+ * Since this function loads data from another file, it returns a `Promise`.
19946
+ * Use it in an `async function setup`, and `await` its result.
19925
19947
  *
19926
- * Read <a href="#/p5/buildMaterialShader">the `buildMaterialShader` reference</a> or
19927
- * call `baseMaterialShader().inspectHooks()` for more information on what you can do with
19928
- * the base material shader.
19929
- * @returns The base material shader.
19930
- */
19931
- function baseMaterialShader(): P5.Shader;
19932
-
19933
- /**
19934
- * Returns the base shader used for filters.
19948
+ * `let myShader;
19949
+ * async function setup() {
19950
+ * createCanvas(200, 200, WEBGL);
19951
+ * myShader = await loadMaterialShader('myMaterial.js');
19952
+ * }
19935
19953
  *
19936
- * Calling <a href="#/p5/buildMaterialShader">`buildFilterShader(shaderFunction)`</a>
19937
- * is equivalent to calling `baseFilterShader().modify(shaderFunction)`.
19954
+ * function draw() {
19955
+ * background(255);
19956
+ * shader(myShader);
19957
+ * myShader.setUniform('time', millis());
19958
+ * lights();
19959
+ * noStroke();
19960
+ * fill('red');
19961
+ * sphere(50);
19962
+ * }`Inside your shader file, you can call p5.strands hooks to change parts of the shader. For
19963
+ * example, you might use the `worldInputs` hook to change each vertex, or you
19964
+ * might use the `pixelInputs` hook to change each pixel on the surface of a shape.
19938
19965
  *
19939
- * Read <a href="#/p5/buildFilterShader">the `buildFilterShader` reference</a> or
19940
- * call `baseFilterShader().inspectHooks()` for more information on what you can do with
19941
- * the base filter shader.
19942
- * @returns The base filter shader.
19966
+ * `// myMaterial.js
19967
+ * let time = uniformFloat();
19968
+ * worldInputs.begin();
19969
+ * worldInputs.position.y +=
19970
+ * 20 * sin(time * 0.001 + worldInputs.position.x * 0.05);
19971
+ * worldInputs.end();`Read the reference for <a href="#/p5/buildMaterialShader">`buildMaterialShader`</a>,
19972
+ * the version of `loadMaterialShader` that takes in a function instead of a separate file,
19973
+ * for a full list of hooks you can use and examples for each.
19974
+ *
19975
+ * The second parameter, `successCallback`, is optional. If a function is passed, as in
19976
+ * `loadMaterialShader('myShader.js', onLoaded)`, then the `onLoaded()` function will be called
19977
+ * once the shader loads. The shader will be passed to `onLoaded()` as its only argument.
19978
+ * The return value of `handleData()`, if present, will be used as the final return value of
19979
+ * `loadMaterialShader('myShader.js', onLoaded)`.
19980
+ * @param url The URL of your p5.strands JavaScript file.
19981
+ * @param onSuccess A callback function to run when loading completes.
19982
+ * @param onFailure A callback function to run when loading fails.
19983
+ * @returns The material shader.
19943
19984
  */
19944
- function baseFilterShader(): P5.Shader;
19985
+ function loadMaterialShader(url: string, onSuccess?: Function, onFailure?: Function): Promise<P5.Shader>;
19945
19986
 
19946
19987
  /**
19947
19988
  * Influences the shape of the Bézier curve segment in a custom shape.
@@ -20012,6 +20053,19 @@ function bezierOrder(): number;
20012
20053
  */
20013
20054
  function doubleClicked(event?: MouseEvent): void;
20014
20055
 
20056
+ /**
20057
+ * Returns the default shader used for fills when lights or textures are used.
20058
+ *
20059
+ * Calling <a href="#/p5/buildMaterialShader">`buildMaterialShader(shaderFunction)`</a>
20060
+ * is equivalent to calling `baseMaterialShader().modify(shaderFunction)`.
20061
+ *
20062
+ * Read <a href="#/p5/buildMaterialShader">the `buildMaterialShader` reference</a> or
20063
+ * call `baseMaterialShader().inspectHooks()` for more information on what you can do with
20064
+ * the base material shader.
20065
+ * @returns The base material shader.
20066
+ */
20067
+ function baseMaterialShader(): P5.Shader;
20068
+
20015
20069
  /**
20016
20070
  * Starts using shapes to erase parts of the canvas.
20017
20071
  *
@@ -20046,6 +20100,19 @@ function doubleClicked(event?: MouseEvent): void;
20046
20100
  */
20047
20101
  function erase(strengthFill?: number, strengthStroke?: number): void;
20048
20102
 
20103
+ /**
20104
+ * Returns the base shader used for filters.
20105
+ *
20106
+ * Calling <a href="#/p5/buildFilterShader">`buildFilterShader(shaderFunction)`</a>
20107
+ * is equivalent to calling `baseFilterShader().modify(shaderFunction)`.
20108
+ *
20109
+ * Read <a href="#/p5/buildFilterShader">the `buildFilterShader` reference</a> or
20110
+ * call `baseFilterShader().inspectHooks()` for more information on what you can do with
20111
+ * the base filter shader.
20112
+ * @returns The base filter shader.
20113
+ */
20114
+ function baseFilterShader(): P5.Shader;
20115
+
20049
20116
  /**
20050
20117
  * Ends erasing that was started with <a href="#/p5/erase">erase()</a>.
20051
20118
  *
@@ -20074,6 +20141,37 @@ function noErase(): void;
20074
20141
  function createInput(value?: string, type?: string): P5.Element;
20075
20142
  function createInput(value?: string): P5.Element;
20076
20143
 
20144
+ /**
20145
+ * Saves an `Object` or `Array` to a JSON file.
20146
+ *
20147
+ * JavaScript Object Notation
20148
+ * (<a href="https://developer.mozilla.org/en-US/docs/Glossary/JSON" target="_blank">JSON</a>)
20149
+ * is a standard format for sending data between applications. The format is
20150
+ * based on JavaScript objects which have keys and values. JSON files store
20151
+ * data in an object with strings as keys. Values can be strings, numbers,
20152
+ * Booleans, arrays, `null`, or other objects.
20153
+ *
20154
+ * The first parameter, `json`, is the data to save. The data can be an array,
20155
+ * as in `[1, 2, 3]`, or an object, as in
20156
+ * `{ x: 50, y: 50, color: 'deeppink' }`.
20157
+ *
20158
+ * The second parameter, `filename`, is a string that sets the file's name.
20159
+ * For example, calling `saveJSON([1, 2, 3], 'data.json')` saves the array
20160
+ * `[1, 2, 3]` to a file called `data.json` on the user's computer.
20161
+ *
20162
+ * The third parameter, `optimize`, is optional. If `true` is passed, as in
20163
+ * `saveJSON([1, 2, 3], 'data.json', true)`, then all unneeded whitespace will
20164
+ * be removed to reduce the file size.
20165
+ *
20166
+ * Note: The browser will either save the file immediately or prompt the user
20167
+ * with a dialogue window.
20168
+ * @param json data to save.
20169
+ * @param filename name of the file to be saved.
20170
+ * @param optimize whether to trim unneeded whitespace. Defaults
20171
+ * to `true`.
20172
+ */
20173
+ function saveJSON(json: any[] | object, filename: string, optimize?: boolean): void;
20174
+
20077
20175
  /**
20078
20176
  * Create a new shader that can change how fills are drawn, based on the material used
20079
20177
  * when <a href="#/p5/normalMaterial">`normalMaterial()`</a> is active. Pass the resulting
@@ -20159,41 +20257,11 @@ function createInput(value?: string): P5.Element;
20159
20257
  * Read the <a href="#/p5.Shader/modify">reference entry for `modify()`</a>
20160
20258
  * for more info.
20161
20259
  * @param callback A function building a p5.strands shader.
20260
+ * @param scope An optional scope object passed to .modify().
20162
20261
  * @returns The normal shader.
20163
20262
  */
20164
- function buildNormalShader(callback: Function): P5.Shader;
20165
- function buildNormalShader(hooks: object): P5.Shader;
20166
-
20167
- /**
20168
- * Saves an `Object` or `Array` to a JSON file.
20169
- *
20170
- * JavaScript Object Notation
20171
- * (<a href="https://developer.mozilla.org/en-US/docs/Glossary/JSON" target="_blank">JSON</a>)
20172
- * is a standard format for sending data between applications. The format is
20173
- * based on JavaScript objects which have keys and values. JSON files store
20174
- * data in an object with strings as keys. Values can be strings, numbers,
20175
- * Booleans, arrays, `null`, or other objects.
20176
- *
20177
- * The first parameter, `json`, is the data to save. The data can be an array,
20178
- * as in `[1, 2, 3]`, or an object, as in
20179
- * `{ x: 50, y: 50, color: 'deeppink' }`.
20180
- *
20181
- * The second parameter, `filename`, is a string that sets the file's name.
20182
- * For example, calling `saveJSON([1, 2, 3], 'data.json')` saves the array
20183
- * `[1, 2, 3]` to a file called `data.json` on the user's computer.
20184
- *
20185
- * The third parameter, `optimize`, is optional. If `true` is passed, as in
20186
- * `saveJSON([1, 2, 3], 'data.json', true)`, then all unneeded whitespace will
20187
- * be removed to reduce the file size.
20188
- *
20189
- * Note: The browser will either save the file immediately or prompt the user
20190
- * with a dialogue window.
20191
- * @param json data to save.
20192
- * @param filename name of the file to be saved.
20193
- * @param optimize whether to trim unneeded whitespace. Defaults
20194
- * to `true`.
20195
- */
20196
- function saveJSON(json: any[] | object, filename: string, optimize?: boolean): void;
20263
+ function buildNormalShader(callback: Function, scope?: object): P5.Shader;
20264
+ function buildNormalShader(hooks: object, scope?: object): P5.Shader;
20197
20265
 
20198
20266
  /**
20199
20267
  * A function that's called once when the mouse wheel moves.
@@ -20239,54 +20307,6 @@ function saveJSON(json: any[] | object, filename: string, optimize?: boolean): v
20239
20307
  */
20240
20308
  function mouseWheel(event?: WheelEvent): void;
20241
20309
 
20242
- /**
20243
- * Loads a new shader from a file that can change how fills are drawn, based on the material used
20244
- * when <a href="#/p5/normalMaterial">`normalMaterial()`</a> is active. Pass the resulting
20245
- * shader into the <a href="#/p5/shader">`shader()`</a> function to apply it
20246
- * to any fills you draw.
20247
- *
20248
- * Since this function loads data from another file, it returns a `Promise`.
20249
- * Use it in an `async function setup`, and `await` its result.
20250
- *
20251
- * `let myShader;
20252
- * async function setup() {
20253
- * createCanvas(200, 200, WEBGL);
20254
- * myShader = await loadNormalShader('myMaterial.js');
20255
- * }
20256
- *
20257
- * function draw() {
20258
- * background(255);
20259
- * shader(myShader);
20260
- * myShader.setUniform('time', millis());
20261
- * lights();
20262
- * noStroke();
20263
- * fill('red');
20264
- * sphere(50);
20265
- * }`Inside your shader file, you can call p5.strands hooks to change parts of the shader. For
20266
- * example, you might use the `worldInputs` hook to change each vertex, or you
20267
- * might use the `finalColor` hook to change the color of each pixel on the surface of a shape.
20268
- *
20269
- * `// myMaterial.js
20270
- * let time = uniformFloat();
20271
- * worldInputs.begin();
20272
- * worldInputs.position.y +=
20273
- * 20 * sin(time * 0.001 + worldInputs.position.x * 0.05);
20274
- * worldInputs.end();`Read the reference for <a href="#/p5/buildNormalShader">`buildNormalShader`</a>,
20275
- * the version of `loadNormalShader` that takes in a function instead of a separate file,
20276
- * for a full list of hooks you can use and examples for each.
20277
- *
20278
- * The second parameter, `successCallback`, is optional. If a function is passed, as in
20279
- * `loadNormalShader('myShader.js', onLoaded)`, then the `onLoaded()` function will be called
20280
- * once the shader loads. The shader will be passed to `onLoaded()` as its only argument.
20281
- * The return value of `handleData()`, if present, will be used as the final return value of
20282
- * `loadNormalShader('myShader.js', onLoaded)`.
20283
- * @param url The URL of your p5.strands JavaScript file.
20284
- * @param onSuccess A callback function to run when loading completes.
20285
- * @param onFailure A callback function to run when loading fails.
20286
- * @returns The normal shader.
20287
- */
20288
- function loadNormalShader(url: string, onSuccess?: Function, onFailure?: Function): Promise<P5.Shader>;
20289
-
20290
20310
  /**
20291
20311
  * Ends a drawing group that contains its own styles and transformations.
20292
20312
  *
@@ -20468,7 +20488,74 @@ function pop(): void;
20468
20488
  * @param multiple allow multiple files to be selected.
20469
20489
  * @returns The new input element.
20470
20490
  */
20471
- function createFileInput(callback: (input: P5.File) => any, multiple?: boolean): P5.Element;
20491
+ function createFileInput(callback: (input: P5.File) => any, multiple?: boolean): P5.Element;
20492
+
20493
+ /**
20494
+ * Locks the mouse pointer to its current position and makes it invisible.
20495
+ *
20496
+ * `requestPointerLock()` allows the mouse to move forever without leaving the
20497
+ * screen. Calling `requestPointerLock()` locks the values of
20498
+ * <a href="#/p5/mouseX">mouseX</a>, <a href="#/p5/mouseY">mouseY</a>,
20499
+ * <a href="#/p5/pmouseX">pmouseX</a>, and <a href="#/p5/pmouseY">pmouseY</a>.
20500
+ * <a href="#/p5/movedX">movedX</a> and <a href="#/p5/movedY">movedY</a>
20501
+ * continue updating and can be used to get the distance the mouse moved since
20502
+ * the last frame was drawn. Calling
20503
+ * <a href="#/p5/exitPointerLock">exitPointerLock()</a> resumes updating the
20504
+ * mouse system variables.
20505
+ *
20506
+ * Note: Most browsers require an input, such as a click, before calling
20507
+ * `requestPointerLock()`. It’s recommended to call `requestPointerLock()` in
20508
+ * an event function such as <a href="#/p5/doubleClicked">doubleClicked()</a>.
20509
+ */
20510
+ function requestPointerLock(): void;
20511
+
20512
+ /**
20513
+ * Loads a new shader from a file that can change how fills are drawn, based on the material used
20514
+ * when <a href="#/p5/normalMaterial">`normalMaterial()`</a> is active. Pass the resulting
20515
+ * shader into the <a href="#/p5/shader">`shader()`</a> function to apply it
20516
+ * to any fills you draw.
20517
+ *
20518
+ * Since this function loads data from another file, it returns a `Promise`.
20519
+ * Use it in an `async function setup`, and `await` its result.
20520
+ *
20521
+ * `let myShader;
20522
+ * async function setup() {
20523
+ * createCanvas(200, 200, WEBGL);
20524
+ * myShader = await loadNormalShader('myMaterial.js');
20525
+ * }
20526
+ *
20527
+ * function draw() {
20528
+ * background(255);
20529
+ * shader(myShader);
20530
+ * myShader.setUniform('time', millis());
20531
+ * lights();
20532
+ * noStroke();
20533
+ * fill('red');
20534
+ * sphere(50);
20535
+ * }`Inside your shader file, you can call p5.strands hooks to change parts of the shader. For
20536
+ * example, you might use the `worldInputs` hook to change each vertex, or you
20537
+ * might use the `finalColor` hook to change the color of each pixel on the surface of a shape.
20538
+ *
20539
+ * `// myMaterial.js
20540
+ * let time = uniformFloat();
20541
+ * worldInputs.begin();
20542
+ * worldInputs.position.y +=
20543
+ * 20 * sin(time * 0.001 + worldInputs.position.x * 0.05);
20544
+ * worldInputs.end();`Read the reference for <a href="#/p5/buildNormalShader">`buildNormalShader`</a>,
20545
+ * the version of `loadNormalShader` that takes in a function instead of a separate file,
20546
+ * for a full list of hooks you can use and examples for each.
20547
+ *
20548
+ * The second parameter, `successCallback`, is optional. If a function is passed, as in
20549
+ * `loadNormalShader('myShader.js', onLoaded)`, then the `onLoaded()` function will be called
20550
+ * once the shader loads. The shader will be passed to `onLoaded()` as its only argument.
20551
+ * The return value of `handleData()`, if present, will be used as the final return value of
20552
+ * `loadNormalShader('myShader.js', onLoaded)`.
20553
+ * @param url The URL of your p5.strands JavaScript file.
20554
+ * @param onSuccess A callback function to run when loading completes.
20555
+ * @param onFailure A callback function to run when loading fails.
20556
+ * @returns The normal shader.
20557
+ */
20558
+ function loadNormalShader(url: string, onSuccess?: Function, onFailure?: Function): Promise<P5.Shader>;
20472
20559
 
20473
20560
  /**
20474
20561
  * Returns the default shader used for fills when
@@ -20485,23 +20572,50 @@ function createFileInput(callback: (input: P5.File) => any, multiple?: boolean):
20485
20572
  function baseNormalShader(): P5.Shader;
20486
20573
 
20487
20574
  /**
20488
- * Locks the mouse pointer to its current position and makes it invisible.
20575
+ * Exits a pointer lock started with
20576
+ * <a href="#/p5/requestPointerLock">requestPointerLock</a>.
20489
20577
  *
20490
- * `requestPointerLock()` allows the mouse to move forever without leaving the
20491
- * screen. Calling `requestPointerLock()` locks the values of
20578
+ * Calling `requestPointerLock()` locks the values of
20492
20579
  * <a href="#/p5/mouseX">mouseX</a>, <a href="#/p5/mouseY">mouseY</a>,
20493
20580
  * <a href="#/p5/pmouseX">pmouseX</a>, and <a href="#/p5/pmouseY">pmouseY</a>.
20494
- * <a href="#/p5/movedX">movedX</a> and <a href="#/p5/movedY">movedY</a>
20495
- * continue updating and can be used to get the distance the mouse moved since
20496
- * the last frame was drawn. Calling
20497
- * <a href="#/p5/exitPointerLock">exitPointerLock()</a> resumes updating the
20498
- * mouse system variables.
20581
+ * Calling `exitPointerLock()` resumes updating the mouse system variables.
20499
20582
  *
20500
20583
  * Note: Most browsers require an input, such as a click, before calling
20501
20584
  * `requestPointerLock()`. It’s recommended to call `requestPointerLock()` in
20502
20585
  * an event function such as <a href="#/p5/doubleClicked">doubleClicked()</a>.
20503
20586
  */
20504
- function requestPointerLock(): void;
20587
+ function exitPointerLock(): void;
20588
+
20589
+ /**
20590
+ * Saves an `Array` of `String`s to a file, one per line.
20591
+ *
20592
+ * The first parameter, `list`, is an array with the strings to save.
20593
+ *
20594
+ * The second parameter, `filename`, is a string that sets the file's name.
20595
+ * For example, calling `saveStrings(['0', '01', '011'], 'data.txt')` saves
20596
+ * the array `['0', '01', '011']` to a file called `data.txt` on the user's
20597
+ * computer.
20598
+ *
20599
+ * The third parameter, `extension`, is optional. If a string is passed, as in
20600
+ * `saveStrings(['0', '01', '0`1'], 'data', 'txt')`, the second parameter will
20601
+ * be interpreted as the file name and the third parameter as the extension.
20602
+ *
20603
+ * The fourth parameter, `isCRLF`, is also optional, If `true` is passed, as
20604
+ * in `saveStrings(['0', '01', '011'], 'data', 'txt', true)`, then two
20605
+ * characters, `\r\n` , will be added to the end of each string to create new
20606
+ * lines in the saved file. `\r` is a carriage return (CR) and `\n` is a line
20607
+ * feed (LF). By default, only `\n` (line feed) is added to each string in
20608
+ * order to create new lines.
20609
+ *
20610
+ * Note: The browser will either save the file immediately or prompt the user
20611
+ * with a dialogue window.
20612
+ * @param list data to save.
20613
+ * @param filename name of file to be saved.
20614
+ * @param extension format to use for the file.
20615
+ * @param isCRLF whether to add `\r\n` to the end of each
20616
+ * string. Defaults to `false`.
20617
+ */
20618
+ function saveStrings(list: string[], filename: string, extension?: string, isCRLF?: boolean): void;
20505
20619
 
20506
20620
  /**
20507
20621
  * Create a new shader that can change how fills are drawn, based on the default shader
@@ -20555,56 +20669,11 @@ function requestPointerLock(): void;
20555
20669
  * Read the <a href="#/p5.Shader/modify">reference entry for `modify()`</a>
20556
20670
  * for more info.
20557
20671
  * @param callback A function building a p5.strands shader.
20672
+ * @param scope An optional scope object passed to .modify().
20558
20673
  * @returns The color shader.
20559
20674
  */
20560
- function buildColorShader(callback: Function): P5.Shader;
20561
- function buildColorShader(hooks: object): P5.Shader;
20562
-
20563
- /**
20564
- * Exits a pointer lock started with
20565
- * <a href="#/p5/requestPointerLock">requestPointerLock</a>.
20566
- *
20567
- * Calling `requestPointerLock()` locks the values of
20568
- * <a href="#/p5/mouseX">mouseX</a>, <a href="#/p5/mouseY">mouseY</a>,
20569
- * <a href="#/p5/pmouseX">pmouseX</a>, and <a href="#/p5/pmouseY">pmouseY</a>.
20570
- * Calling `exitPointerLock()` resumes updating the mouse system variables.
20571
- *
20572
- * Note: Most browsers require an input, such as a click, before calling
20573
- * `requestPointerLock()`. It’s recommended to call `requestPointerLock()` in
20574
- * an event function such as <a href="#/p5/doubleClicked">doubleClicked()</a>.
20575
- */
20576
- function exitPointerLock(): void;
20577
-
20578
- /**
20579
- * Saves an `Array` of `String`s to a file, one per line.
20580
- *
20581
- * The first parameter, `list`, is an array with the strings to save.
20582
- *
20583
- * The second parameter, `filename`, is a string that sets the file's name.
20584
- * For example, calling `saveStrings(['0', '01', '011'], 'data.txt')` saves
20585
- * the array `['0', '01', '011']` to a file called `data.txt` on the user's
20586
- * computer.
20587
- *
20588
- * The third parameter, `extension`, is optional. If a string is passed, as in
20589
- * `saveStrings(['0', '01', '0`1'], 'data', 'txt')`, the second parameter will
20590
- * be interpreted as the file name and the third parameter as the extension.
20591
- *
20592
- * The fourth parameter, `isCRLF`, is also optional, If `true` is passed, as
20593
- * in `saveStrings(['0', '01', '011'], 'data', 'txt', true)`, then two
20594
- * characters, `\r\n` , will be added to the end of each string to create new
20595
- * lines in the saved file. `\r` is a carriage return (CR) and `\n` is a line
20596
- * feed (LF). By default, only `\n` (line feed) is added to each string in
20597
- * order to create new lines.
20598
- *
20599
- * Note: The browser will either save the file immediately or prompt the user
20600
- * with a dialogue window.
20601
- * @param list data to save.
20602
- * @param filename name of file to be saved.
20603
- * @param extension format to use for the file.
20604
- * @param isCRLF whether to add `\r\n` to the end of each
20605
- * string. Defaults to `false`.
20606
- */
20607
- function saveStrings(list: string[], filename: string, extension?: string, isCRLF?: boolean): void;
20675
+ function buildColorShader(callback: Function, scope?: object): P5.Shader;
20676
+ function buildColorShader(hooks: object, scope?: object): P5.Shader;
20608
20677
 
20609
20678
  /**
20610
20679
  * Connects points with a smooth curve (a spline).
@@ -20674,6 +20743,18 @@ function splineVertex(x: number, y: number, z?: number): void;
20674
20743
  function splineVertex(x: number, y: number, u?: number, v?: number): void;
20675
20744
  function splineVertex(x: number, y: number, z: number, u?: number, v?: number): void;
20676
20745
 
20746
+ /**
20747
+ * Writes the contents of a <a href="#/p5.Table">Table</a> object to a file. Defaults to a
20748
+ * text file with comma-separated-values ('csv') but can also
20749
+ * use tab separation ('tsv'), or generate an HTML table ('html').
20750
+ * The file saving process and location of the saved file will
20751
+ * vary between web browsers.
20752
+ * @param Table the <a href="#/p5.Table">Table</a> object to save to a file
20753
+ * @param filename the filename to which the Table should be saved
20754
+ * @param options can be one of "tsv", "csv", or "html"
20755
+ */
20756
+ function saveTable(Table: P5.Table, filename: string, options?: string): void;
20757
+
20677
20758
  /**
20678
20759
  * Loads a new shader from a file that can change how fills are drawn, based on the material used
20679
20760
  * when no lights or textures are active. Pass the resulting
@@ -20722,18 +20803,6 @@ function splineVertex(x: number, y: number, z: number, u?: number, v?: number):
20722
20803
  */
20723
20804
  function loadColorShader(url: string, onSuccess?: Function, onFailure?: Function): Promise<P5.Shader>;
20724
20805
 
20725
- /**
20726
- * Writes the contents of a <a href="#/p5.Table">Table</a> object to a file. Defaults to a
20727
- * text file with comma-separated-values ('csv') but can also
20728
- * use tab separation ('tsv'), or generate an HTML table ('html').
20729
- * The file saving process and location of the saved file will
20730
- * vary between web browsers.
20731
- * @param Table the <a href="#/p5.Table">Table</a> object to save to a file
20732
- * @param filename the filename to which the Table should be saved
20733
- * @param options can be one of "tsv", "csv", or "html"
20734
- */
20735
- function saveTable(Table: P5.Table, filename: string, options?: string): void;
20736
-
20737
20806
  /**
20738
20807
  * Returns the default shader used for fills when no lights or textures are activate.
20739
20808
  *
@@ -21031,62 +21100,11 @@ function camera(x?: number, y?: number, z?: number, centerX?: number, centerY?:
21031
21100
  * Read the <a href="#/p5.Shader/modify">reference entry for `modify()`</a>
21032
21101
  * for more info.
21033
21102
  * @param callback A function building a p5.strands shader.
21103
+ * @param scope An optional scope object passed to .modify().
21034
21104
  * @returns The stroke shader.
21035
21105
  */
21036
- function buildStrokeShader(callback: Function): P5.Shader;
21037
- function buildStrokeShader(hooks: object): P5.Shader;
21038
-
21039
- /**
21040
- * Loads a new shader from a file that can change how strokes are drawn. Pass the resulting
21041
- * shader into the <a href="#/p5/strokeShader">`strokeShader()`</a> function to apply it
21042
- * to any strokes you draw.
21043
- *
21044
- * Since this function loads data from another file, it returns a `Promise`.
21045
- * Use it in an `async function setup`, and `await` its result.
21046
- *
21047
- * `let myShader;
21048
- * async function setup() {
21049
- * createCanvas(200, 200, WEBGL);
21050
- * myShader = await loadStrokeShader('myMaterial.js');
21051
- * }
21052
- *
21053
- * function draw() {
21054
- * background(255);
21055
- * strokeShader(myShader);
21056
- * strokeWeight(30);
21057
- * line(
21058
- * -width/3,
21059
- * sin(millis()*0.001) * height/4,
21060
- * width/3,
21061
- * sin(millis()*0.001 + 1) * height/4
21062
- * );
21063
- * }`Inside your shader file, you can call p5.strands hooks to change parts of the shader. For
21064
- * example, you might use the `worldInputs` hook to change each vertex, or you
21065
- * might use the `pixelInputs` hook to change each pixel on the surface of a stroke.
21066
- *
21067
- * `// myMaterial.js
21068
- * pixelInputs.begin();
21069
- * let opacity = 1 - smoothstep(
21070
- * 0,
21071
- * 15,
21072
- * length(pixelInputs.position - pixelInputs.center)
21073
- * );
21074
- * pixelInputs.color.a *= opacity;
21075
- * pixelInputs.end();`Read the reference for <a href="#/p5/buildStrokeShader">`buildStrokeShader`</a>,
21076
- * the version of `loadStrokeShader` that takes in a function instead of a separate file,
21077
- * for a full list of hooks you can use and examples for each.
21078
- *
21079
- * The second parameter, `successCallback`, is optional. If a function is passed, as in
21080
- * `loadStrokeShader('myShader.js', onLoaded)`, then the `onLoaded()` function will be called
21081
- * once the shader loads. The shader will be passed to `onLoaded()` as its only argument.
21082
- * The return value of `handleData()`, if present, will be used as the final return value of
21083
- * `loadStrokeShader('myShader.js', onLoaded)`.
21084
- * @param url The URL of your p5.strands JavaScript file.
21085
- * @param onSuccess A callback function to run when loading completes.
21086
- * @param onFailure A callback function to run when loading fails.
21087
- * @returns The stroke shader.
21088
- */
21089
- function loadStrokeShader(url: string, onSuccess?: Function, onFailure?: Function): Promise<P5.Shader>;
21106
+ function buildStrokeShader(callback: Function, scope?: object): P5.Shader;
21107
+ function buildStrokeShader(hooks: object, scope?: object): P5.Shader;
21090
21108
 
21091
21109
  /**
21092
21110
  * Gets or sets a given spline property.
@@ -21211,6 +21229,58 @@ function splineProperty(property: string): void;
21211
21229
  */
21212
21230
  function perspective(fovy?: number, aspect?: number, near?: number, far?: number): void;
21213
21231
 
21232
+ /**
21233
+ * Loads a new shader from a file that can change how strokes are drawn. Pass the resulting
21234
+ * shader into the <a href="#/p5/strokeShader">`strokeShader()`</a> function to apply it
21235
+ * to any strokes you draw.
21236
+ *
21237
+ * Since this function loads data from another file, it returns a `Promise`.
21238
+ * Use it in an `async function setup`, and `await` its result.
21239
+ *
21240
+ * `let myShader;
21241
+ * async function setup() {
21242
+ * createCanvas(200, 200, WEBGL);
21243
+ * myShader = await loadStrokeShader('myMaterial.js');
21244
+ * }
21245
+ *
21246
+ * function draw() {
21247
+ * background(255);
21248
+ * strokeShader(myShader);
21249
+ * strokeWeight(30);
21250
+ * line(
21251
+ * -width/3,
21252
+ * sin(millis()*0.001) * height/4,
21253
+ * width/3,
21254
+ * sin(millis()*0.001 + 1) * height/4
21255
+ * );
21256
+ * }`Inside your shader file, you can call p5.strands hooks to change parts of the shader. For
21257
+ * example, you might use the `worldInputs` hook to change each vertex, or you
21258
+ * might use the `pixelInputs` hook to change each pixel on the surface of a stroke.
21259
+ *
21260
+ * `// myMaterial.js
21261
+ * pixelInputs.begin();
21262
+ * let opacity = 1 - smoothstep(
21263
+ * 0,
21264
+ * 15,
21265
+ * length(pixelInputs.position - pixelInputs.center)
21266
+ * );
21267
+ * pixelInputs.color.a *= opacity;
21268
+ * pixelInputs.end();`Read the reference for <a href="#/p5/buildStrokeShader">`buildStrokeShader`</a>,
21269
+ * the version of `loadStrokeShader` that takes in a function instead of a separate file,
21270
+ * for a full list of hooks you can use and examples for each.
21271
+ *
21272
+ * The second parameter, `successCallback`, is optional. If a function is passed, as in
21273
+ * `loadStrokeShader('myShader.js', onLoaded)`, then the `onLoaded()` function will be called
21274
+ * once the shader loads. The shader will be passed to `onLoaded()` as its only argument.
21275
+ * The return value of `handleData()`, if present, will be used as the final return value of
21276
+ * `loadStrokeShader('myShader.js', onLoaded)`.
21277
+ * @param url The URL of your p5.strands JavaScript file.
21278
+ * @param onSuccess A callback function to run when loading completes.
21279
+ * @param onFailure A callback function to run when loading fails.
21280
+ * @returns The stroke shader.
21281
+ */
21282
+ function loadStrokeShader(url: string, onSuccess?: Function, onFailure?: Function): Promise<P5.Shader>;
21283
+
21214
21284
  /**
21215
21285
  * Returns the default shader used for strokes.
21216
21286
  *
@@ -21224,17 +21294,6 @@ function perspective(fovy?: number, aspect?: number, near?: number, far?: number
21224
21294
  */
21225
21295
  function baseStrokeShader(): P5.Shader;
21226
21296
 
21227
- /**
21228
- * Restores the default shaders.
21229
- *
21230
- * `resetShader()` deactivates any shaders previously applied by
21231
- * <a href="#/p5/shader">shader()</a>, <a href="#/p5/strokeShader">strokeShader()</a>,
21232
- * or <a href="#/p5/imageShader">imageShader()</a>.
21233
- *
21234
- * Note: Shaders can only be used in WebGL mode.
21235
- */
21236
- function resetShader(): void;
21237
-
21238
21297
  /**
21239
21298
  * Sets multiple properties for spline curves at once.
21240
21299
  *
@@ -21303,6 +21362,17 @@ function splineProperties(values: object): object;
21303
21362
  function linePerspective(enable: boolean): boolean;
21304
21363
  function linePerspective(): boolean;
21305
21364
 
21365
+ /**
21366
+ * Restores the default shaders.
21367
+ *
21368
+ * `resetShader()` deactivates any shaders previously applied by
21369
+ * <a href="#/p5/shader">shader()</a>, <a href="#/p5/strokeShader">strokeShader()</a>,
21370
+ * or <a href="#/p5/imageShader">imageShader()</a>.
21371
+ *
21372
+ * Note: Shaders can only be used in WebGL mode.
21373
+ */
21374
+ function resetShader(): void;
21375
+
21306
21376
  /**
21307
21377
  * Sets an orthographic projection for the current camera in a 3D sketch.
21308
21378
  *