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/p5.d.ts CHANGED
@@ -5581,6 +5581,112 @@ declare class p5 {
5581
5581
  min(n0: number, n1: number): number;
5582
5582
  min(nums: number[]): number;
5583
5583
 
5584
+ /**
5585
+ * A function that's called when the browser window is resized.
5586
+ *
5587
+ * Code placed in the body of `windowResized()` will run when the
5588
+ * browser window's size changes. It's a good place to call
5589
+ * <a href="#/p5/resizeCanvas">resizeCanvas()</a> or make other
5590
+ * adjustments to accommodate the new window size.
5591
+ *
5592
+ * The `event` parameter is optional. If added to the function declaration, it
5593
+ * can be used for debugging or other purposes.
5594
+ * @param event optional resize Event.
5595
+ */
5596
+ windowResized(event?: Event): void;
5597
+
5598
+ /**
5599
+ * Shuffles the elements of an array.
5600
+ *
5601
+ * The first parameter, `array`, is the array to be shuffled. For example,
5602
+ * calling `shuffle(myArray)` will shuffle the elements of `myArray`. By
5603
+ * default, the original array won’t be modified. Instead, a copy will be
5604
+ * created, shuffled, and returned.
5605
+ *
5606
+ * The second parameter, `modify`, is optional. If `true` is passed, as in
5607
+ * `shuffle(myArray, true)`, then the array will be shuffled in place without
5608
+ * making a copy.
5609
+ * @param array array to shuffle.
5610
+ * @param modify if `true`, shuffle the original array in place. Defaults to `false`.
5611
+ * @returns shuffled array.
5612
+ */
5613
+ shuffle<T>(array: T[], modify?: boolean): T[];
5614
+
5615
+ /**
5616
+ * This method is suitable for fetching files up to size of 64MB.
5617
+ * @param file name of the file or URL to load
5618
+ * @param callback function to be executed after <a href="#/p5/loadBytes">loadBytes()</a>
5619
+ * completes
5620
+ * @param errorCallback function to be executed if there
5621
+ * is an error
5622
+ * @returns a Uint8Array containing the loaded buffer
5623
+ */
5624
+ loadBytes(file: string | Request, callback?: Function, errorCallback?: Function): Promise<Uint8Array>;
5625
+
5626
+ /**
5627
+ * Turns off <a href="#/p5/debugMode">debugMode()</a> in a 3D sketch.
5628
+ */
5629
+ noDebugMode(): void;
5630
+
5631
+ /**
5632
+ * Gets the blue value of a color.
5633
+ *
5634
+ * `blue()` extracts the blue value from a
5635
+ * <a href="/reference/p5/p5.Color/">p5.Color</a> object, an array of color components, or
5636
+ * a CSS color string.
5637
+ *
5638
+ * By default, `blue()` returns a color's blue value in the range 0
5639
+ * to 255. If the <a href="/reference/p5/colorMode/">colorMode()</a> is set to RGB, it
5640
+ * returns the blue value in the given range.
5641
+ * @param color <a href="/reference/p5/p5.Color/">p5.Color</a> object, array of
5642
+ * color components, or CSS color string.
5643
+ * @returns the blue value.
5644
+ */
5645
+ blue(color: p5.Color | number[] | string): number;
5646
+
5647
+ /**
5648
+ * Converts a single-character `String` to a `Number`.
5649
+ *
5650
+ * `unchar()` converts single-character strings to their corresponding
5651
+ * integer (whole number).
5652
+ *
5653
+ * The parameter, `n`, is the character to convert. For example,
5654
+ * `unchar('A')`, returns the number 65. If an array is passed, as in
5655
+ * `unchar(['A', 'B', 'C'])`, an array of integers is returned.
5656
+ * @param n value to convert.
5657
+ * @returns converted number.
5658
+ */
5659
+ unchar(n: string): number;
5660
+ unchar(ns: string[]): number[];
5661
+
5662
+ /**
5663
+ * Changes the unit system used to measure angles.
5664
+ *
5665
+ * Degrees and radians are both units for measuring angles. There are 360˚ in
5666
+ * one full rotation. A full rotation is 2 × π (about 6.28) radians.
5667
+ *
5668
+ * Functions such as <a href="#/p5/rotate">rotate()</a> and
5669
+ * <a href="#/p5/sin">sin()</a> expect angles measured radians by default.
5670
+ * Calling `angleMode(DEGREES)` switches to degrees. Calling
5671
+ * `angleMode(RADIANS)` switches back to radians.
5672
+ *
5673
+ * Calling `angleMode()` with no arguments returns current angle mode, which
5674
+ * is either `RADIANS` or `DEGREES`.
5675
+ * @param mode either RADIANS or DEGREES.
5676
+ * @returns mode either RADIANS or DEGREES
5677
+ */
5678
+ angleMode(mode: typeof p5.RADIANS | typeof p5.DEGREES): typeof p5.RADIANS | typeof p5.DEGREES;
5679
+ angleMode(): typeof p5.RADIANS | typeof p5.DEGREES;
5680
+
5681
+ /**
5682
+ * Loads the current value of each pixel on the canvas into the
5683
+ * <a href="#/p5/pixels">pixels</a> array.
5684
+ *
5685
+ * `loadPixels()` must be called before reading from or writing to
5686
+ * <a href="#/p5/pixels">pixels</a>.
5687
+ */
5688
+ loadPixels(): void;
5689
+
5584
5690
  /**
5585
5691
  * Creates a <a href="#/p5.Shader">p5.Shader</a> object to be used with the
5586
5692
  * <a href="#/p5/filter">filter()</a> function.
@@ -5700,6 +5806,36 @@ declare class p5 {
5700
5806
  * function draw() {
5701
5807
  * myFilter.setUniform('time', millis());
5702
5808
  * filter(myFilter);
5809
+ * }`We can use the `noise()` function built into strands to generate a color for each pixel. (Again no need here for underlying content for the filter to operate on.) Again we'll animate by passing in an announced uniform variable `time` with `setUniform()`, each frame.
5810
+ *
5811
+ * `let myFilter;
5812
+ *
5813
+ * function setup() {
5814
+ * createCanvas(100, 100, WEBGL);
5815
+ * myFilter = buildFilterShader(noiseShaderCallback);
5816
+ * describe('Evolving animated cloud-like noise in cyan and magenta');
5817
+ * }
5818
+ *
5819
+ * function noiseShaderCallback() {
5820
+ * let time = uniformFloat();
5821
+ * filterColor.begin();
5822
+ * let coord = filterColor.texCoord;
5823
+ *
5824
+ * //generate a value roughly between 0 and 1
5825
+ * let noiseVal = noise(coord.x, coord.y, time / 2000);
5826
+ *
5827
+ * let result = mix(
5828
+ * [1, 0, 1, 1], // Magenta
5829
+ * [0, 1, 1, 1], // Cyan
5830
+ * noiseVal
5831
+ * );
5832
+ * filterColor.set(result);
5833
+ * filterColor.end();
5834
+ * }
5835
+ *
5836
+ * function draw() {
5837
+ * myFilter.setUniform("time", millis());
5838
+ * filter(myFilter);
5703
5839
  * }`Like the `modify()` method on shaders,
5704
5840
  * 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>
5705
5841
  * instead of JavaScript.
@@ -5710,116 +5846,11 @@ declare class p5 {
5710
5846
  * For more info about filters and shaders, see Adam Ferriss' <a href="https://github.com/aferriss/p5jsShaderExamples">repo of shader examples</a>
5711
5847
  * or the <a href="https://p5js.org/learn/getting-started-in-webgl-shaders.html">Introduction to Shaders</a> tutorial.
5712
5848
  * @param callback A function building a p5.strands shader.
5849
+ * @param scope An optional scope object passed to .modify().
5713
5850
  * @returns The material shader
5714
5851
  */
5715
- buildFilterShader(callback: Function): p5.Shader;
5716
- buildFilterShader(hooks: object): p5.Shader;
5717
-
5718
- /**
5719
- * A function that's called when the browser window is resized.
5720
- *
5721
- * Code placed in the body of `windowResized()` will run when the
5722
- * browser window's size changes. It's a good place to call
5723
- * <a href="#/p5/resizeCanvas">resizeCanvas()</a> or make other
5724
- * adjustments to accommodate the new window size.
5725
- *
5726
- * The `event` parameter is optional. If added to the function declaration, it
5727
- * can be used for debugging or other purposes.
5728
- * @param event optional resize Event.
5729
- */
5730
- windowResized(event?: Event): void;
5731
-
5732
- /**
5733
- * Shuffles the elements of an array.
5734
- *
5735
- * The first parameter, `array`, is the array to be shuffled. For example,
5736
- * calling `shuffle(myArray)` will shuffle the elements of `myArray`. By
5737
- * default, the original array won’t be modified. Instead, a copy will be
5738
- * created, shuffled, and returned.
5739
- *
5740
- * The second parameter, `modify`, is optional. If `true` is passed, as in
5741
- * `shuffle(myArray, true)`, then the array will be shuffled in place without
5742
- * making a copy.
5743
- * @param array array to shuffle.
5744
- * @param modify if `true`, shuffle the original array in place. Defaults to `false`.
5745
- * @returns shuffled array.
5746
- */
5747
- shuffle<T>(array: T[], modify?: boolean): T[];
5748
-
5749
- /**
5750
- * This method is suitable for fetching files up to size of 64MB.
5751
- * @param file name of the file or URL to load
5752
- * @param callback function to be executed after <a href="#/p5/loadBytes">loadBytes()</a>
5753
- * completes
5754
- * @param errorCallback function to be executed if there
5755
- * is an error
5756
- * @returns a Uint8Array containing the loaded buffer
5757
- */
5758
- loadBytes(file: string | Request, callback?: Function, errorCallback?: Function): Promise<Uint8Array>;
5759
-
5760
- /**
5761
- * Turns off <a href="#/p5/debugMode">debugMode()</a> in a 3D sketch.
5762
- */
5763
- noDebugMode(): void;
5764
-
5765
- /**
5766
- * Gets the blue value of a color.
5767
- *
5768
- * `blue()` extracts the blue value from a
5769
- * <a href="/reference/p5/p5.Color/">p5.Color</a> object, an array of color components, or
5770
- * a CSS color string.
5771
- *
5772
- * By default, `blue()` returns a color's blue value in the range 0
5773
- * to 255. If the <a href="/reference/p5/colorMode/">colorMode()</a> is set to RGB, it
5774
- * returns the blue value in the given range.
5775
- * @param color <a href="/reference/p5/p5.Color/">p5.Color</a> object, array of
5776
- * color components, or CSS color string.
5777
- * @returns the blue value.
5778
- */
5779
- blue(color: p5.Color | number[] | string): number;
5780
-
5781
- /**
5782
- * Converts a single-character `String` to a `Number`.
5783
- *
5784
- * `unchar()` converts single-character strings to their corresponding
5785
- * integer (whole number).
5786
- *
5787
- * The parameter, `n`, is the character to convert. For example,
5788
- * `unchar('A')`, returns the number 65. If an array is passed, as in
5789
- * `unchar(['A', 'B', 'C'])`, an array of integers is returned.
5790
- * @param n value to convert.
5791
- * @returns converted number.
5792
- */
5793
- unchar(n: string): number;
5794
- unchar(ns: string[]): number[];
5795
-
5796
- /**
5797
- * Changes the unit system used to measure angles.
5798
- *
5799
- * Degrees and radians are both units for measuring angles. There are 360˚ in
5800
- * one full rotation. A full rotation is 2 × π (about 6.28) radians.
5801
- *
5802
- * Functions such as <a href="#/p5/rotate">rotate()</a> and
5803
- * <a href="#/p5/sin">sin()</a> expect angles measured radians by default.
5804
- * Calling `angleMode(DEGREES)` switches to degrees. Calling
5805
- * `angleMode(RADIANS)` switches back to radians.
5806
- *
5807
- * Calling `angleMode()` with no arguments returns current angle mode, which
5808
- * is either `RADIANS` or `DEGREES`.
5809
- * @param mode either RADIANS or DEGREES.
5810
- * @returns mode either RADIANS or DEGREES
5811
- */
5812
- angleMode(mode: typeof p5.RADIANS | typeof p5.DEGREES): typeof p5.RADIANS | typeof p5.DEGREES;
5813
- angleMode(): typeof p5.RADIANS | typeof p5.DEGREES;
5814
-
5815
- /**
5816
- * Loads the current value of each pixel on the canvas into the
5817
- * <a href="#/p5/pixels">pixels</a> array.
5818
- *
5819
- * `loadPixels()` must be called before reading from or writing to
5820
- * <a href="#/p5/pixels">pixels</a>.
5821
- */
5822
- loadPixels(): void;
5852
+ buildFilterShader(callback: Function, scope?: object): p5.Shader;
5853
+ buildFilterShader(hooks: object, scope?: object): p5.Shader;
5823
5854
 
5824
5855
  /**
5825
5856
  * Creates a slider `&lt;input&gt;&lt;/input&gt;` element.
@@ -5985,53 +6016,14 @@ declare class p5 {
5985
6016
  fullscreen(val?: boolean): boolean;
5986
6017
 
5987
6018
  /**
5988
- * Creates a <a href="#/p5.Shader">p5.Shader</a> object to be used with the
5989
- * <a href="#/p5/filter">filter()</a> function using GLSL.
5990
- *
5991
- * Since this method requires you to write your shaders in GLSL, it is most suitable
5992
- * for advanced use cases. Consider using <a href="#/p5/buildFilterShader">`buildFilterShader`</a>
5993
- * first, as a way to create filters in JavaScript using p5.strands.
5994
- *
5995
- * `createFilterShader()` works like
5996
- * <a href="#/p5/createShader">createShader()</a> but has a default vertex
5997
- * shader included. `createFilterShader()` is intended to be used along with
5998
- * <a href="#/p5/filter">filter()</a> for filtering the contents of a canvas.
5999
- * A filter shader will be applied to the whole canvas instead of just
6000
- * <a href="#/p5.Geometry">p5.Geometry</a> objects.
6019
+ * Creates a light that shines from a point in all directions.
6001
6020
  *
6002
- * The parameter, `fragSrc`, sets the fragment shader. It’s a string that
6003
- * contains the fragment shader program written in
6004
- * <a href="https://developer.mozilla.org/en-US/docs/Games/Techniques/3D_on_the_web/GLSL_Shaders" target="_blank">GLSL</a>.
6021
+ * Point lights are like light bulbs that shine in all directions. They can be
6022
+ * placed at different positions to achieve different lighting effects. A
6023
+ * maximum of 5 point lights can be active at once.
6005
6024
  *
6006
- * The <a href="#/p5.Shader">p5.Shader</a> object that's created has some
6007
- * uniforms that can be set:
6008
- *
6009
- * - `sampler2D tex0`, which contains the canvas contents as a texture.
6010
- *
6011
- * - `vec2 canvasSize`, which is the width and height of the canvas, not including pixel density.
6012
- *
6013
- * - `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.
6014
- *
6015
- * The <a href="#/p5.Shader">p5.Shader</a> that's created also provides
6016
- * `varying vec2 vTexCoord`, a coordinate with values between 0 and 1.
6017
- * `vTexCoord` describes where on the canvas the pixel will be drawn.
6018
- *
6019
- * For more info about filters and shaders, see Adam Ferriss' <a href="https://github.com/aferriss/p5jsShaderExamples">repo of shader examples</a>
6020
- * or the <a href="https://p5js.org/learn/getting-started-in-webgl-shaders.html">Introduction to Shaders</a> tutorial.
6021
- * @param fragSrc source code for the fragment shader.
6022
- * @returns new shader object created from the fragment shader.
6023
- */
6024
- createFilterShader(fragSrc: string): p5.Shader;
6025
-
6026
- /**
6027
- * Creates a light that shines from a point in all directions.
6028
- *
6029
- * Point lights are like light bulbs that shine in all directions. They can be
6030
- * placed at different positions to achieve different lighting effects. A
6031
- * maximum of 5 point lights can be active at once.
6032
- *
6033
- * There are four ways to call `pointLight()` with parameters to set the
6034
- * light’s color and position.
6025
+ * There are four ways to call `pointLight()` with parameters to set the
6026
+ * light’s color and position.
6035
6027
  *
6036
6028
  * The first way to call `pointLight()` has six parameters. The first three
6037
6029
  * parameters, `v1`, `v2`, and `v3`, set the light’s color using the current
@@ -6130,6 +6122,45 @@ declare class p5 {
6130
6122
  */
6131
6123
  createButton(label: string, value?: string): p5.Element;
6132
6124
 
6125
+ /**
6126
+ * Creates a <a href="#/p5.Shader">p5.Shader</a> object to be used with the
6127
+ * <a href="#/p5/filter">filter()</a> function using GLSL.
6128
+ *
6129
+ * Since this method requires you to write your shaders in GLSL, it is most suitable
6130
+ * for advanced use cases. Consider using <a href="#/p5/buildFilterShader">`buildFilterShader`</a>
6131
+ * first, as a way to create filters in JavaScript using p5.strands.
6132
+ *
6133
+ * `createFilterShader()` works like
6134
+ * <a href="#/p5/createShader">createShader()</a> but has a default vertex
6135
+ * shader included. `createFilterShader()` is intended to be used along with
6136
+ * <a href="#/p5/filter">filter()</a> for filtering the contents of a canvas.
6137
+ * A filter shader will be applied to the whole canvas instead of just
6138
+ * <a href="#/p5.Geometry">p5.Geometry</a> objects.
6139
+ *
6140
+ * The parameter, `fragSrc`, sets the fragment shader. It’s a string that
6141
+ * contains the fragment shader program written in
6142
+ * <a href="https://developer.mozilla.org/en-US/docs/Games/Techniques/3D_on_the_web/GLSL_Shaders" target="_blank">GLSL</a>.
6143
+ *
6144
+ * The <a href="#/p5.Shader">p5.Shader</a> object that's created has some
6145
+ * uniforms that can be set:
6146
+ *
6147
+ * - `sampler2D tex0`, which contains the canvas contents as a texture.
6148
+ *
6149
+ * - `vec2 canvasSize`, which is the width and height of the canvas, not including pixel density.
6150
+ *
6151
+ * - `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.
6152
+ *
6153
+ * The <a href="#/p5.Shader">p5.Shader</a> that's created also provides
6154
+ * `varying vec2 vTexCoord`, a coordinate with values between 0 and 1.
6155
+ * `vTexCoord` describes where on the canvas the pixel will be drawn.
6156
+ *
6157
+ * For more info about filters and shaders, see Adam Ferriss' <a href="https://github.com/aferriss/p5jsShaderExamples">repo of shader examples</a>
6158
+ * or the <a href="https://p5js.org/learn/getting-started-in-webgl-shaders.html">Introduction to Shaders</a> tutorial.
6159
+ * @param fragSrc source code for the fragment shader.
6160
+ * @returns new shader object created from the fragment shader.
6161
+ */
6162
+ createFilterShader(fragSrc: string): p5.Shader;
6163
+
6133
6164
  /**
6134
6165
  * Concludes the vertices of a custom shape.
6135
6166
  *
@@ -6807,169 +6838,6 @@ declare class p5 {
6807
6838
  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;
6808
6839
  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;
6809
6840
 
6810
- /**
6811
- * Sets the <a href="#/p5.Shader">p5.Shader</a> object to apply while drawing.
6812
- *
6813
- * Shaders are programs that run on the graphics processing unit (GPU). They
6814
- * can process many pixels or vertices at the same time, making them fast for
6815
- * many graphics tasks.
6816
- *
6817
- * You can make new shaders using p5.strands with the
6818
- * <a href="#/p5/buildMaterialShader">`buildMaterialShader`</a>,
6819
- * <a href="#/p5/buildColorShader">`buildColorShader`</a>, and
6820
- * <a href="#/p5/buildNormalShader">`buildNormalShader`</a> functions. You can also use
6821
- * <a href="#/p5/buildFilterShader">`buildFilterShader`</a> alongside
6822
- * <a href="#/p5/filter">`filter`</a>, and
6823
- * <a href="#/p5/buildStrokeShader">`buildStrokeShader`</a> alongside
6824
- * <a href="#/p5/stroke">`stroke`</a>.
6825
- *
6826
- * The parameter, `s`, is the <a href="#/p5.Shader">p5.Shader</a> object to
6827
- * apply. For example, calling `shader(myShader)` applies `myShader` to
6828
- * process each pixel on the canvas. This only changes the fill (the inner part of shapes),
6829
- * but does not affect the outlines (strokes) or any images drawn using the `image()` function.
6830
- * The source code from a <a href="#/p5.Shader">p5.Shader</a> object's
6831
- * fragment and vertex shaders will be compiled the first time it's passed to
6832
- * `shader()`.
6833
- *
6834
- * Calling <a href="#/p5/resetShader">resetShader()</a> restores a sketch’s
6835
- * default shaders.
6836
- *
6837
- * Note: Shaders can only be used in WebGL mode.
6838
- *
6839
- * `let myShader;
6840
- *
6841
- * function setup() {
6842
- * createCanvas(200, 200, WEBGL);
6843
- * myShader = buildMaterialShader(material);
6844
- * noStroke();
6845
- * describe('A square with dynamically changing colors on a beige background.');
6846
- * }
6847
- *
6848
- * function material() {
6849
- * let time = uniformFloat();
6850
- * finalColor.begin();
6851
- * let r = 0.2 + 0.5 * abs(sin(time + 0));
6852
- * let g = 0.2 + 0.5 * abs(sin(time + 1));
6853
- * let b = 0.2 + 0.5 * abs(sin(time + 2));
6854
- * finalColor.set([r, g, b, 1]);
6855
- * finalColor.end();
6856
- * }
6857
- *
6858
- * function draw() {
6859
- * background(245, 245, 220);
6860
- * myShader.setUniform('time', millis() / 1000);
6861
- * shader(myShader);
6862
- *
6863
- * rectMode(CENTER);
6864
- * rect(0, 0, 50, 50);
6865
- * }`For advanced usage, shaders can be written in a language called
6866
- * <a href="https://developer.mozilla.org/en-US/docs/Games/Techniques/3D_on_the_web/GLSL_Shaders" target="_blank">GLSL</a>.
6867
- * <a href="#/p5.Shader">p5.Shader</a> objects can be created in this way using the
6868
- * <a href="#/p5/createShader">createShader()</a> and
6869
- * <a href="#/p5/loadShader">loadShader()</a> functions.
6870
- *
6871
- * `let fillShader;
6872
- *
6873
- * let vertSrc = `
6874
- * precision highp float;
6875
- * attribute vec3 aPosition;
6876
- * uniform mat4 uModelViewMatrix;
6877
- * uniform mat4 uProjectionMatrix;
6878
- * varying vec3 vPosition;
6879
- *
6880
- * void main() {
6881
- * vPosition = aPosition;
6882
- * gl_Position = uProjectionMatrix * uModelViewMatrix * vec4(aPosition, 1.0);
6883
- * }
6884
- * `;
6885
- *
6886
- * let fragSrc = `
6887
- * precision highp float;
6888
- * uniform vec3 uLightDir;
6889
- * varying vec3 vPosition;
6890
- *
6891
- * void main() {
6892
- * vec3 lightDir = normalize(uLightDir);
6893
- * float brightness = dot(lightDir, normalize(vPosition));
6894
- * brightness = clamp(brightness, 0.4, 1.0);
6895
- * vec3 color = vec3(0.3, 0.5, 1.0);
6896
- * color = color * brightness * 3.0;
6897
- * gl_FragColor = vec4(color, 1.0);
6898
- * }
6899
- * `;
6900
- *
6901
- * function setup() {
6902
- * createCanvas(200, 200, WEBGL);
6903
- * fillShader = createShader(vertSrc, fragSrc);
6904
- * noStroke();
6905
- * describe('A rotating torus with simulated directional lighting.');
6906
- * }
6907
- *
6908
- * function draw() {
6909
- * background(20, 20, 40);
6910
- * let lightDir = [0.5, 0.5, 1.0];
6911
- * fillShader.setUniform('uLightDir', lightDir);
6912
- * shader(fillShader);
6913
- * rotateY(frameCount * 0.02);
6914
- * rotateX(frameCount * 0.02);
6915
- * torus(25, 10, 30, 30);
6916
- * }``let fillShader;
6917
- *
6918
- * let vertSrc = `
6919
- * precision highp float;
6920
- * attribute vec3 aPosition;
6921
- * uniform mat4 uProjectionMatrix;
6922
- * uniform mat4 uModelViewMatrix;
6923
- * varying vec3 vPosition;
6924
- * void main() {
6925
- * vPosition = aPosition;
6926
- * gl_Position = uProjectionMatrix * uModelViewMatrix * vec4(aPosition, 1.0);
6927
- * }
6928
- * `;
6929
- *
6930
- * let fragSrc = `
6931
- * precision highp float;
6932
- * uniform vec3 uLightPos;
6933
- * uniform vec3 uFillColor;
6934
- * varying vec3 vPosition;
6935
- * void main() {
6936
- * float brightness = dot(normalize(uLightPos), normalize(vPosition));
6937
- * brightness = clamp(brightness, 0.0, 1.0);
6938
- * vec3 color = uFillColor * brightness;
6939
- * gl_FragColor = vec4(color, 1.0);
6940
- * }
6941
- * `;
6942
- *
6943
- * function setup() {
6944
- * createCanvas(200, 200, WEBGL);
6945
- * fillShader = createShader(vertSrc, fragSrc);
6946
- * shader(fillShader);
6947
- * noStroke();
6948
- * describe('A square affected by both fill color and lighting, with lights controlled by mouse.');
6949
- * }
6950
- *
6951
- * function draw() {
6952
- * let lightPos = [(mouseX - width / 2) / width,
6953
- * (mouseY - height / 2) / height, 1.0];
6954
- * fillShader.setUniform('uLightPos', lightPos);
6955
- * let fillColor = [map(mouseX, 0, width, 0, 1),
6956
- * map(mouseY, 0, height, 0, 1), 0.5];
6957
- * fillShader.setUniform('uFillColor', fillColor);
6958
- * plane(width, height);
6959
- * }`<div>
6960
- * <p>If you want to apply shaders to strokes or images, use the following methods:
6961
- *
6962
- * - <a href="#/p5/strokeShader">strokeShader()</a> : Applies a shader to the stroke (outline) of shapes, allowing independent control over the stroke rendering using shaders.
6963
- *
6964
- * - <a href="#/p5/imageShader">imageShader()</a> : Applies a shader to images or textures, controlling how the shader modifies their appearance during rendering.
6965
- *
6966
- * </p>
6967
- * </div>
6968
- * @param s <a href="#/p5.Shader">p5.Shader</a> object
6969
- * to apply.
6970
- */
6971
- shader(s: p5.Shader): void;
6972
-
6973
6841
  /**
6974
6842
  * Returns the current
6975
6843
  * <a href="https://developer.mozilla.org/en-US/docs/Learn/Common_questions/Web_mechanics/What_is_a_URL#parameters" target="_blank">URL parameters</a>
@@ -7155,61 +7023,213 @@ declare class p5 {
7155
7023
  * // Code to run if the mouse is on the left.
7156
7024
  * }
7157
7025
  *
7158
- * if (mouseY > 50) {
7159
- * // Code to run if the mouse is near the bottom.
7026
+ * if (mouseY > 50) {
7027
+ * // Code to run if the mouse is near the bottom.
7028
+ * }
7029
+ * }`The parameter, `event`, is optional. `mouseDragged()` is always passed a
7030
+ * <a href="https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent" target="_blank">MouseEvent</a>
7031
+ * object with properties that describe the mouse drag event:
7032
+ *
7033
+ * `function mouseDragged(event) {
7034
+ * // Code to run that uses the event.
7035
+ * console.log(event);
7036
+ * }`On touchscreen devices, `mouseDragged()` will run when a user moves a touch
7037
+ * point.
7038
+ *
7039
+ * Browsers may have default behaviors attached to various mouse events. For
7040
+ * example, some browsers highlight text when the user moves the mouse while
7041
+ * pressing a mouse button. To prevent any default behavior for this event,
7042
+ * add `return false;` to the end of the function.
7043
+ * @param event optional `MouseEvent` argument.
7044
+ */
7045
+ mouseDragged(event?: MouseEvent): void;
7046
+
7047
+ /**
7048
+ * Returns `true` if the key it’s checking is pressed and `false` if not.
7049
+ *
7050
+ * `keyIsDown()` is helpful when checking for multiple different key presses.
7051
+ * For example, `keyIsDown()` can be used to check if both `LEFT_ARROW` and
7052
+ * `UP_ARROW` are pressed:
7053
+ *
7054
+ * `if (keyIsDown(LEFT_ARROW) && keyIsDown(UP_ARROW)) {
7055
+ * // Move diagonally.
7056
+ * }``keyIsDown()` can check for key presses using strings based on
7057
+ * <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key" target="_blank">KeyboardEvent.key</a>
7058
+ * or <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code" target="_blank">KeyboardEvent.code</a> values,
7059
+ * such as `keyIsDown('x')` or `keyIsDown('ArrowLeft')`.
7060
+ *
7061
+ * Note: In p5.js 2.0 and newer, numeric keycodes (such as 88 for 'X') are no longer supported.
7062
+ * This is a breaking change from previous versions.
7063
+ *
7064
+ * You can still use the p5 constants like `LEFT_ARROW` which now map to string values
7065
+ * internally rather than numeric codes.
7066
+ * @param code key to check.
7067
+ * @returns whether the key is down or not.
7068
+ */
7069
+ keyIsDown(code: number | string): boolean;
7070
+
7071
+ /**
7072
+ * Sets the <a href="#/p5.Shader">p5.Shader</a> object to apply while drawing.
7073
+ *
7074
+ * Shaders are programs that run on the graphics processing unit (GPU). They
7075
+ * can process many pixels or vertices at the same time, making them fast for
7076
+ * many graphics tasks.
7077
+ *
7078
+ * You can make new shaders using p5.strands with the
7079
+ * <a href="#/p5/buildMaterialShader">`buildMaterialShader`</a>,
7080
+ * <a href="#/p5/buildColorShader">`buildColorShader`</a>, and
7081
+ * <a href="#/p5/buildNormalShader">`buildNormalShader`</a> functions. You can also use
7082
+ * <a href="#/p5/buildFilterShader">`buildFilterShader`</a> alongside
7083
+ * <a href="#/p5/filter">`filter`</a>, and
7084
+ * <a href="#/p5/buildStrokeShader">`buildStrokeShader`</a> alongside
7085
+ * <a href="#/p5/stroke">`stroke`</a>.
7086
+ *
7087
+ * The parameter, `s`, is the <a href="#/p5.Shader">p5.Shader</a> object to
7088
+ * apply. For example, calling `shader(myShader)` applies `myShader` to
7089
+ * process each pixel on the canvas. This only changes the fill (the inner part of shapes),
7090
+ * but does not affect the outlines (strokes) or any images drawn using the `image()` function.
7091
+ * The source code from a <a href="#/p5.Shader">p5.Shader</a> object's
7092
+ * fragment and vertex shaders will be compiled the first time it's passed to
7093
+ * `shader()`.
7094
+ *
7095
+ * Calling <a href="#/p5/resetShader">resetShader()</a> restores a sketch’s
7096
+ * default shaders.
7097
+ *
7098
+ * Note: Shaders can only be used in WebGL mode.
7099
+ *
7100
+ * `let myShader;
7101
+ *
7102
+ * function setup() {
7103
+ * createCanvas(200, 200, WEBGL);
7104
+ * myShader = buildMaterialShader(material);
7105
+ * noStroke();
7106
+ * describe('A square with dynamically changing colors on a beige background.');
7107
+ * }
7108
+ *
7109
+ * function material() {
7110
+ * let time = uniformFloat();
7111
+ * finalColor.begin();
7112
+ * let r = 0.2 + 0.5 * abs(sin(time + 0));
7113
+ * let g = 0.2 + 0.5 * abs(sin(time + 1));
7114
+ * let b = 0.2 + 0.5 * abs(sin(time + 2));
7115
+ * finalColor.set([r, g, b, 1]);
7116
+ * finalColor.end();
7117
+ * }
7118
+ *
7119
+ * function draw() {
7120
+ * background(245, 245, 220);
7121
+ * myShader.setUniform('time', millis() / 1000);
7122
+ * shader(myShader);
7123
+ *
7124
+ * rectMode(CENTER);
7125
+ * rect(0, 0, 50, 50);
7126
+ * }`For advanced usage, shaders can be written in a language called
7127
+ * <a href="https://developer.mozilla.org/en-US/docs/Games/Techniques/3D_on_the_web/GLSL_Shaders" target="_blank">GLSL</a>.
7128
+ * <a href="#/p5.Shader">p5.Shader</a> objects can be created in this way using the
7129
+ * <a href="#/p5/createShader">createShader()</a> and
7130
+ * <a href="#/p5/loadShader">loadShader()</a> functions.
7131
+ *
7132
+ * `let fillShader;
7133
+ *
7134
+ * let vertSrc = `
7135
+ * precision highp float;
7136
+ * attribute vec3 aPosition;
7137
+ * uniform mat4 uModelViewMatrix;
7138
+ * uniform mat4 uProjectionMatrix;
7139
+ * varying vec3 vPosition;
7140
+ *
7141
+ * void main() {
7142
+ * vPosition = aPosition;
7143
+ * gl_Position = uProjectionMatrix * uModelViewMatrix * vec4(aPosition, 1.0);
7144
+ * }
7145
+ * `;
7146
+ *
7147
+ * let fragSrc = `
7148
+ * precision highp float;
7149
+ * uniform vec3 uLightDir;
7150
+ * varying vec3 vPosition;
7151
+ *
7152
+ * void main() {
7153
+ * vec3 lightDir = normalize(uLightDir);
7154
+ * float brightness = dot(lightDir, normalize(vPosition));
7155
+ * brightness = clamp(brightness, 0.4, 1.0);
7156
+ * vec3 color = vec3(0.3, 0.5, 1.0);
7157
+ * color = color * brightness * 3.0;
7158
+ * gl_FragColor = vec4(color, 1.0);
7159
+ * }
7160
+ * `;
7161
+ *
7162
+ * function setup() {
7163
+ * createCanvas(200, 200, WEBGL);
7164
+ * fillShader = createShader(vertSrc, fragSrc);
7165
+ * noStroke();
7166
+ * describe('A rotating torus with simulated directional lighting.');
7160
7167
  * }
7161
- * }`The parameter, `event`, is optional. `mouseDragged()` is always passed a
7162
- * <a href="https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent" target="_blank">MouseEvent</a>
7163
- * object with properties that describe the mouse drag event:
7164
7168
  *
7165
- * `function mouseDragged(event) {
7166
- * // Code to run that uses the event.
7167
- * console.log(event);
7168
- * }`On touchscreen devices, `mouseDragged()` will run when a user moves a touch
7169
- * point.
7169
+ * function draw() {
7170
+ * background(20, 20, 40);
7171
+ * let lightDir = [0.5, 0.5, 1.0];
7172
+ * fillShader.setUniform('uLightDir', lightDir);
7173
+ * shader(fillShader);
7174
+ * rotateY(frameCount * 0.02);
7175
+ * rotateX(frameCount * 0.02);
7176
+ * torus(25, 10, 30, 30);
7177
+ * }``let fillShader;
7170
7178
  *
7171
- * Browsers may have default behaviors attached to various mouse events. For
7172
- * example, some browsers highlight text when the user moves the mouse while
7173
- * pressing a mouse button. To prevent any default behavior for this event,
7174
- * add `return false;` to the end of the function.
7175
- * @param event optional `MouseEvent` argument.
7176
- */
7177
- mouseDragged(event?: MouseEvent): void;
7178
-
7179
- /**
7180
- * Returns `true` if the key it’s checking is pressed and `false` if not.
7179
+ * let vertSrc = `
7180
+ * precision highp float;
7181
+ * attribute vec3 aPosition;
7182
+ * uniform mat4 uProjectionMatrix;
7183
+ * uniform mat4 uModelViewMatrix;
7184
+ * varying vec3 vPosition;
7185
+ * void main() {
7186
+ * vPosition = aPosition;
7187
+ * gl_Position = uProjectionMatrix * uModelViewMatrix * vec4(aPosition, 1.0);
7188
+ * }
7189
+ * `;
7181
7190
  *
7182
- * `keyIsDown()` is helpful when checking for multiple different key presses.
7183
- * For example, `keyIsDown()` can be used to check if both `LEFT_ARROW` and
7184
- * `UP_ARROW` are pressed:
7191
+ * let fragSrc = `
7192
+ * precision highp float;
7193
+ * uniform vec3 uLightPos;
7194
+ * uniform vec3 uFillColor;
7195
+ * varying vec3 vPosition;
7196
+ * void main() {
7197
+ * float brightness = dot(normalize(uLightPos), normalize(vPosition));
7198
+ * brightness = clamp(brightness, 0.0, 1.0);
7199
+ * vec3 color = uFillColor * brightness;
7200
+ * gl_FragColor = vec4(color, 1.0);
7201
+ * }
7202
+ * `;
7185
7203
  *
7186
- * `if (keyIsDown(LEFT_ARROW) && keyIsDown(UP_ARROW)) {
7187
- * // Move diagonally.
7188
- * }``keyIsDown()` can check for key presses using strings based on
7189
- * <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key" target="_blank">KeyboardEvent.key</a>
7190
- * or <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code" target="_blank">KeyboardEvent.code</a> values,
7191
- * such as `keyIsDown('x')` or `keyIsDown('ArrowLeft')`.
7204
+ * function setup() {
7205
+ * createCanvas(200, 200, WEBGL);
7206
+ * fillShader = createShader(vertSrc, fragSrc);
7207
+ * shader(fillShader);
7208
+ * noStroke();
7209
+ * describe('A square affected by both fill color and lighting, with lights controlled by mouse.');
7210
+ * }
7192
7211
  *
7193
- * Note: In p5.js 2.0 and newer, numeric keycodes (such as 88 for 'X') are no longer supported.
7194
- * This is a breaking change from previous versions.
7212
+ * function draw() {
7213
+ * let lightPos = [(mouseX - width / 2) / width,
7214
+ * (mouseY - height / 2) / height, 1.0];
7215
+ * fillShader.setUniform('uLightPos', lightPos);
7216
+ * let fillColor = [map(mouseX, 0, width, 0, 1),
7217
+ * map(mouseY, 0, height, 0, 1), 0.5];
7218
+ * fillShader.setUniform('uFillColor', fillColor);
7219
+ * plane(width, height);
7220
+ * }`<div>
7221
+ * <p>If you want to apply shaders to strokes or images, use the following methods:
7195
7222
  *
7196
- * You can still use the p5 constants like `LEFT_ARROW` which now map to string values
7197
- * internally rather than numeric codes.
7198
- * @param code key to check.
7199
- * @returns whether the key is down or not.
7200
- */
7201
- keyIsDown(code: number | string): boolean;
7202
-
7203
- /**
7204
- * Sets the element's content.
7223
+ * - <a href="#/p5/strokeShader">strokeShader()</a> : Applies a shader to the stroke (outline) of shapes, allowing independent control over the stroke rendering using shaders.
7205
7224
  *
7206
- * An element's content is the text between its tags. For example, the element
7207
- * `&lt;language&gt;JavaScript&lt;/language&gt;` has the content `JavaScript`.
7225
+ * - <a href="#/p5/imageShader">imageShader()</a> : Applies a shader to images or textures, controlling how the shader modifies their appearance during rendering.
7208
7226
  *
7209
- * The parameter, `content`, is a string with the element's new content.
7210
- * @param content new content for the element.
7227
+ * </p>
7228
+ * </div>
7229
+ * @param s <a href="#/p5.Shader">p5.Shader</a> object
7230
+ * to apply.
7211
7231
  */
7212
- setContent(content: string): void;
7232
+ shader(s: p5.Shader): void;
7213
7233
 
7214
7234
  /**
7215
7235
  * Draws a <a href="#/p5.Geometry">p5.Geometry</a> object to the canvas.
@@ -7228,6 +7248,17 @@ declare class p5 {
7228
7248
  */
7229
7249
  model(model: p5.Geometry, count?: number): void;
7230
7250
 
7251
+ /**
7252
+ * Sets the element's content.
7253
+ *
7254
+ * An element's content is the text between its tags. For example, the element
7255
+ * `&lt;language&gt;JavaScript&lt;/language&gt;` has the content `JavaScript`.
7256
+ *
7257
+ * The parameter, `content`, is a string with the element's new content.
7258
+ * @param content new content for the element.
7259
+ */
7260
+ setContent(content: string): void;
7261
+
7231
7262
  /**
7232
7263
  * Method for executing an HTTP request. If data type is not specified,
7233
7264
  * it will default to `'text'`.
@@ -7507,26 +7538,6 @@ declare class p5 {
7507
7538
  */
7508
7539
  square(x: number, y: number, s: number, tl?: number, tr?: number, br?: number, bl?: number): void;
7509
7540
 
7510
- /**
7511
- * Sets the <a href="#/p5.Shader">p5.Shader</a> object to apply for strokes.
7512
- *
7513
- * This method applies the given shader to strokes, allowing customization of
7514
- * how lines and outlines are drawn in 3D space. The shader will be used for
7515
- * strokes until <a href="#/p5/resetShader">resetShader()</a> is called or another
7516
- * strokeShader is applied.
7517
- *
7518
- * The shader will be used for:
7519
- *
7520
- * - Strokes only, regardless of whether the uniform `uStrokeWeight` is present.
7521
- *
7522
- * To further customize its behavior, refer to the various hooks provided by
7523
- * the <a href="#/p5/baseStrokeShader">baseStrokeShader()</a> method, which allow
7524
- * control over stroke weight, vertex positions, colors, and more.
7525
- * @param s <a href="#/p5.Shader">p5.Shader</a> object
7526
- * to apply for strokes.
7527
- */
7528
- strokeShader(s: p5.Shader): void;
7529
-
7530
7541
  /**
7531
7542
  * Converts 2D screen coordinates to 3D world coordinates.
7532
7543
  *
@@ -7588,6 +7599,26 @@ declare class p5 {
7588
7599
  */
7589
7600
  mousePressed(event?: MouseEvent): void;
7590
7601
 
7602
+ /**
7603
+ * Sets the <a href="#/p5.Shader">p5.Shader</a> object to apply for strokes.
7604
+ *
7605
+ * This method applies the given shader to strokes, allowing customization of
7606
+ * how lines and outlines are drawn in 3D space. The shader will be used for
7607
+ * strokes until <a href="#/p5/resetShader">resetShader()</a> is called or another
7608
+ * strokeShader is applied.
7609
+ *
7610
+ * The shader will be used for:
7611
+ *
7612
+ * - Strokes only, regardless of whether the uniform `uStrokeWeight` is present.
7613
+ *
7614
+ * To further customize its behavior, refer to the various hooks provided by
7615
+ * the <a href="#/p5/baseStrokeShader">baseStrokeShader()</a> method, which allow
7616
+ * control over stroke weight, vertex positions, colors, and more.
7617
+ * @param s <a href="#/p5.Shader">p5.Shader</a> object
7618
+ * to apply for strokes.
7619
+ */
7620
+ strokeShader(s: p5.Shader): void;
7621
+
7591
7622
  /**
7592
7623
  * Tints images using a color.
7593
7624
  *
@@ -8184,25 +8215,6 @@ declare class p5 {
8184
8215
  */
8185
8216
  noFill(): void;
8186
8217
 
8187
- /**
8188
- * Sets the <a href="#/p5.Shader">p5.Shader</a> object to apply for images.
8189
- *
8190
- * This method allows the user to apply a custom shader to images, enabling
8191
- * advanced visual effects such as pixel manipulation, color adjustments,
8192
- * or dynamic behavior. The shader will be applied to the image drawn using
8193
- * the <a href="#/p5/image">image()</a> function.
8194
- *
8195
- * The shader will be used exclusively for:
8196
- *
8197
- * - `image()` calls, applying only when drawing 2D images.
8198
- *
8199
- * - This shader will NOT apply to images used in <a href="#/p5/texture">texture()</a> or other 3D contexts.
8200
- * Any attempts to use the imageShader in these cases will be ignored.
8201
- * @param s <a href="#/p5.Shader">p5.Shader</a> object
8202
- * to apply for images.
8203
- */
8204
- imageShader(s: p5.Shader): void;
8205
-
8206
8218
  /**
8207
8219
  * Removes all lights from the sketch.
8208
8220
  *
@@ -8311,6 +8323,25 @@ declare class p5 {
8311
8323
  */
8312
8324
  mouseReleased(event?: MouseEvent): void;
8313
8325
 
8326
+ /**
8327
+ * Sets the <a href="#/p5.Shader">p5.Shader</a> object to apply for images.
8328
+ *
8329
+ * This method allows the user to apply a custom shader to images, enabling
8330
+ * advanced visual effects such as pixel manipulation, color adjustments,
8331
+ * or dynamic behavior. The shader will be applied to the image drawn using
8332
+ * the <a href="#/p5/image">image()</a> function.
8333
+ *
8334
+ * The shader will be used exclusively for:
8335
+ *
8336
+ * - `image()` calls, applying only when drawing 2D images.
8337
+ *
8338
+ * - This shader will NOT apply to images used in <a href="#/p5/texture">texture()</a> or other 3D contexts.
8339
+ * Any attempts to use the imageShader in these cases will be ignored.
8340
+ * @param s <a href="#/p5.Shader">p5.Shader</a> object
8341
+ * to apply for images.
8342
+ */
8343
+ imageShader(s: p5.Shader): void;
8344
+
8314
8345
  /**
8315
8346
  * Disables drawing points, lines, and the outlines of shapes.
8316
8347
  *
@@ -8428,11 +8459,11 @@ declare class p5 {
8428
8459
  * values. 0 is equal to the first color, 0.1 is very near the first color,
8429
8460
  * 0.5 is halfway between the two colors, and so on. Negative numbers are set
8430
8461
  * to 0. Numbers greater than 1 are set to 1. This differs from the behavior of
8431
- * <a href="#/lerp">lerp</a>. It's necessary because numbers outside of the
8462
+ * <a href="#/p5/lerp">lerp</a>. It's necessary because numbers outside of the
8432
8463
  * interval [0, 1] will produce strange and unexpected colors.
8433
8464
  *
8434
8465
  * The way that colors are interpolated depends on the current
8435
- * <a href="#/colorMode">colorMode()</a>.
8466
+ * <a href="#/p5/colorMode">colorMode()</a>.
8436
8467
  * @param c1 interpolate from this color.
8437
8468
  * @param c2 interpolate to this color.
8438
8469
  * @param amt number between 0 and 1.
@@ -8728,10 +8759,11 @@ declare class p5 {
8728
8759
  * Read the <a href="#/p5.Shader/modify">reference entry for `modify()`</a>
8729
8760
  * for more info.
8730
8761
  * @param callback A function building a p5.strands shader.
8762
+ * @param scope An optional scope object passed to .modify().
8731
8763
  * @returns The material shader.
8732
8764
  */
8733
- buildMaterialShader(callback: Function): p5.Shader;
8734
- buildMaterialShader(hooks: object): p5.Shader;
8765
+ buildMaterialShader(callback: Function, scope?: object): p5.Shader;
8766
+ buildMaterialShader(hooks: object, scope?: object): p5.Shader;
8735
8767
 
8736
8768
  /**
8737
8769
  * Creates a `&lt;video&gt;` element that "captures" the audio/video stream from
@@ -8764,62 +8796,15 @@ declare class p5 {
8764
8796
  * <a href="http://stackoverflow.com/questions/34197653/getusermedia-in-chrome-47-without-using-https" target="_blank">here</a>
8765
8797
  * and <a href="https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia" target="_blank">here</a>.
8766
8798
  * @param type type of capture, either AUDIO or VIDEO,
8767
- * or a constraints object. Both video and audio
8768
- * audio streams are captured by default.
8769
- * @param flipped flip the capturing video and mirror the output with `{flipped:true}`. By
8770
- * default it is false.
8771
- * @param callback function to call once the stream
8772
- * has loaded.
8773
- * @returns new <a href="#/p5.MediaElement">p5.MediaElement</a> object.
8774
- */
8775
- createCapture(type?: typeof p5.AUDIO | typeof p5.VIDEO | object, flipped?: object, callback?: Function): p5.MediaElement;
8776
-
8777
- /**
8778
- * Loads a new shader from a file that can change how fills are drawn. Pass the resulting
8779
- * shader into the <a href="#/p5/shader">`shader()`</a> function to apply it
8780
- * to any fills you draw.
8781
- *
8782
- * Since this function loads data from another file, it returns a `Promise`.
8783
- * Use it in an `async function setup`, and `await` its result.
8784
- *
8785
- * `let myShader;
8786
- * async function setup() {
8787
- * createCanvas(200, 200, WEBGL);
8788
- * myShader = await loadMaterialShader('myMaterial.js');
8789
- * }
8790
- *
8791
- * function draw() {
8792
- * background(255);
8793
- * shader(myShader);
8794
- * myShader.setUniform('time', millis());
8795
- * lights();
8796
- * noStroke();
8797
- * fill('red');
8798
- * sphere(50);
8799
- * }`Inside your shader file, you can call p5.strands hooks to change parts of the shader. For
8800
- * example, you might use the `worldInputs` hook to change each vertex, or you
8801
- * might use the `pixelInputs` hook to change each pixel on the surface of a shape.
8802
- *
8803
- * `// myMaterial.js
8804
- * let time = uniformFloat();
8805
- * worldInputs.begin();
8806
- * worldInputs.position.y +=
8807
- * 20 * sin(time * 0.001 + worldInputs.position.x * 0.05);
8808
- * worldInputs.end();`Read the reference for <a href="#/p5/buildMaterialShader">`buildMaterialShader`</a>,
8809
- * the version of `loadMaterialShader` that takes in a function instead of a separate file,
8810
- * for a full list of hooks you can use and examples for each.
8811
- *
8812
- * The second parameter, `successCallback`, is optional. If a function is passed, as in
8813
- * `loadMaterialShader('myShader.js', onLoaded)`, then the `onLoaded()` function will be called
8814
- * once the shader loads. The shader will be passed to `onLoaded()` as its only argument.
8815
- * The return value of `handleData()`, if present, will be used as the final return value of
8816
- * `loadMaterialShader('myShader.js', onLoaded)`.
8817
- * @param url The URL of your p5.strands JavaScript file.
8818
- * @param onSuccess A callback function to run when loading completes.
8819
- * @param onFailure A callback function to run when loading fails.
8820
- * @returns The material shader.
8799
+ * or a constraints object. Both video and audio
8800
+ * audio streams are captured by default.
8801
+ * @param flipped flip the capturing video and mirror the output with `{flipped:true}`. By
8802
+ * default it is false.
8803
+ * @param callback function to call once the stream
8804
+ * has loaded.
8805
+ * @returns new <a href="#/p5.MediaElement">p5.MediaElement</a> object.
8821
8806
  */
8822
- loadMaterialShader(url: string, onSuccess?: Function, onFailure?: Function): Promise<p5.Shader>;
8807
+ createCapture(type?: typeof p5.AUDIO | typeof p5.VIDEO | object, flipped?: object, callback?: Function): p5.MediaElement;
8823
8808
 
8824
8809
  /**
8825
8810
  * Sets the color used to draw points, lines, and the outlines of shapes.
@@ -8910,30 +8895,51 @@ declare class p5 {
8910
8895
  save(objectOrFilename?: object | string, filename?: string, options?: boolean | string): void;
8911
8896
 
8912
8897
  /**
8913
- * Returns the default shader used for fills when lights or textures are used.
8898
+ * Loads a new shader from a file that can change how fills are drawn. Pass the resulting
8899
+ * shader into the <a href="#/p5/shader">`shader()`</a> function to apply it
8900
+ * to any fills you draw.
8914
8901
  *
8915
- * Calling <a href="#/p5/buildMaterialShader">`buildMaterialShader(shaderFunction)`</a>
8916
- * is equivalent to calling `baseMaterialShader().modify(shaderFunction)`.
8902
+ * Since this function loads data from another file, it returns a `Promise`.
8903
+ * Use it in an `async function setup`, and `await` its result.
8917
8904
  *
8918
- * Read <a href="#/p5/buildMaterialShader">the `buildMaterialShader` reference</a> or
8919
- * call `baseMaterialShader().inspectHooks()` for more information on what you can do with
8920
- * the base material shader.
8921
- * @returns The base material shader.
8922
- */
8923
- baseMaterialShader(): p5.Shader;
8924
-
8925
- /**
8926
- * Returns the base shader used for filters.
8905
+ * `let myShader;
8906
+ * async function setup() {
8907
+ * createCanvas(200, 200, WEBGL);
8908
+ * myShader = await loadMaterialShader('myMaterial.js');
8909
+ * }
8927
8910
  *
8928
- * Calling <a href="#/p5/buildMaterialShader">`buildFilterShader(shaderFunction)`</a>
8929
- * is equivalent to calling `baseFilterShader().modify(shaderFunction)`.
8911
+ * function draw() {
8912
+ * background(255);
8913
+ * shader(myShader);
8914
+ * myShader.setUniform('time', millis());
8915
+ * lights();
8916
+ * noStroke();
8917
+ * fill('red');
8918
+ * sphere(50);
8919
+ * }`Inside your shader file, you can call p5.strands hooks to change parts of the shader. For
8920
+ * example, you might use the `worldInputs` hook to change each vertex, or you
8921
+ * might use the `pixelInputs` hook to change each pixel on the surface of a shape.
8930
8922
  *
8931
- * Read <a href="#/p5/buildFilterShader">the `buildFilterShader` reference</a> or
8932
- * call `baseFilterShader().inspectHooks()` for more information on what you can do with
8933
- * the base filter shader.
8934
- * @returns The base filter shader.
8923
+ * `// myMaterial.js
8924
+ * let time = uniformFloat();
8925
+ * worldInputs.begin();
8926
+ * worldInputs.position.y +=
8927
+ * 20 * sin(time * 0.001 + worldInputs.position.x * 0.05);
8928
+ * worldInputs.end();`Read the reference for <a href="#/p5/buildMaterialShader">`buildMaterialShader`</a>,
8929
+ * the version of `loadMaterialShader` that takes in a function instead of a separate file,
8930
+ * for a full list of hooks you can use and examples for each.
8931
+ *
8932
+ * The second parameter, `successCallback`, is optional. If a function is passed, as in
8933
+ * `loadMaterialShader('myShader.js', onLoaded)`, then the `onLoaded()` function will be called
8934
+ * once the shader loads. The shader will be passed to `onLoaded()` as its only argument.
8935
+ * The return value of `handleData()`, if present, will be used as the final return value of
8936
+ * `loadMaterialShader('myShader.js', onLoaded)`.
8937
+ * @param url The URL of your p5.strands JavaScript file.
8938
+ * @param onSuccess A callback function to run when loading completes.
8939
+ * @param onFailure A callback function to run when loading fails.
8940
+ * @returns The material shader.
8935
8941
  */
8936
- baseFilterShader(): p5.Shader;
8942
+ loadMaterialShader(url: string, onSuccess?: Function, onFailure?: Function): Promise<p5.Shader>;
8937
8943
 
8938
8944
  /**
8939
8945
  * Influences the shape of the Bézier curve segment in a custom shape.
@@ -9004,6 +9010,19 @@ declare class p5 {
9004
9010
  */
9005
9011
  doubleClicked(event?: MouseEvent): void;
9006
9012
 
9013
+ /**
9014
+ * Returns the default shader used for fills when lights or textures are used.
9015
+ *
9016
+ * Calling <a href="#/p5/buildMaterialShader">`buildMaterialShader(shaderFunction)`</a>
9017
+ * is equivalent to calling `baseMaterialShader().modify(shaderFunction)`.
9018
+ *
9019
+ * Read <a href="#/p5/buildMaterialShader">the `buildMaterialShader` reference</a> or
9020
+ * call `baseMaterialShader().inspectHooks()` for more information on what you can do with
9021
+ * the base material shader.
9022
+ * @returns The base material shader.
9023
+ */
9024
+ baseMaterialShader(): p5.Shader;
9025
+
9007
9026
  /**
9008
9027
  * Starts using shapes to erase parts of the canvas.
9009
9028
  *
@@ -9038,6 +9057,19 @@ declare class p5 {
9038
9057
  */
9039
9058
  erase(strengthFill?: number, strengthStroke?: number): void;
9040
9059
 
9060
+ /**
9061
+ * Returns the base shader used for filters.
9062
+ *
9063
+ * Calling <a href="#/p5/buildFilterShader">`buildFilterShader(shaderFunction)`</a>
9064
+ * is equivalent to calling `baseFilterShader().modify(shaderFunction)`.
9065
+ *
9066
+ * Read <a href="#/p5/buildFilterShader">the `buildFilterShader` reference</a> or
9067
+ * call `baseFilterShader().inspectHooks()` for more information on what you can do with
9068
+ * the base filter shader.
9069
+ * @returns The base filter shader.
9070
+ */
9071
+ baseFilterShader(): p5.Shader;
9072
+
9041
9073
  /**
9042
9074
  * Ends erasing that was started with <a href="#/p5/erase">erase()</a>.
9043
9075
  *
@@ -9066,6 +9098,37 @@ declare class p5 {
9066
9098
  createInput(value?: string, type?: string): p5.Element;
9067
9099
  createInput(value?: string): p5.Element;
9068
9100
 
9101
+ /**
9102
+ * Saves an `Object` or `Array` to a JSON file.
9103
+ *
9104
+ * JavaScript Object Notation
9105
+ * (<a href="https://developer.mozilla.org/en-US/docs/Glossary/JSON" target="_blank">JSON</a>)
9106
+ * is a standard format for sending data between applications. The format is
9107
+ * based on JavaScript objects which have keys and values. JSON files store
9108
+ * data in an object with strings as keys. Values can be strings, numbers,
9109
+ * Booleans, arrays, `null`, or other objects.
9110
+ *
9111
+ * The first parameter, `json`, is the data to save. The data can be an array,
9112
+ * as in `[1, 2, 3]`, or an object, as in
9113
+ * `{ x: 50, y: 50, color: 'deeppink' }`.
9114
+ *
9115
+ * The second parameter, `filename`, is a string that sets the file's name.
9116
+ * For example, calling `saveJSON([1, 2, 3], 'data.json')` saves the array
9117
+ * `[1, 2, 3]` to a file called `data.json` on the user's computer.
9118
+ *
9119
+ * The third parameter, `optimize`, is optional. If `true` is passed, as in
9120
+ * `saveJSON([1, 2, 3], 'data.json', true)`, then all unneeded whitespace will
9121
+ * be removed to reduce the file size.
9122
+ *
9123
+ * Note: The browser will either save the file immediately or prompt the user
9124
+ * with a dialogue window.
9125
+ * @param json data to save.
9126
+ * @param filename name of the file to be saved.
9127
+ * @param optimize whether to trim unneeded whitespace. Defaults
9128
+ * to `true`.
9129
+ */
9130
+ saveJSON(json: any[] | object, filename: string, optimize?: boolean): void;
9131
+
9069
9132
  /**
9070
9133
  * Create a new shader that can change how fills are drawn, based on the material used
9071
9134
  * when <a href="#/p5/normalMaterial">`normalMaterial()`</a> is active. Pass the resulting
@@ -9151,41 +9214,11 @@ declare class p5 {
9151
9214
  * Read the <a href="#/p5.Shader/modify">reference entry for `modify()`</a>
9152
9215
  * for more info.
9153
9216
  * @param callback A function building a p5.strands shader.
9217
+ * @param scope An optional scope object passed to .modify().
9154
9218
  * @returns The normal shader.
9155
9219
  */
9156
- buildNormalShader(callback: Function): p5.Shader;
9157
- buildNormalShader(hooks: object): p5.Shader;
9158
-
9159
- /**
9160
- * Saves an `Object` or `Array` to a JSON file.
9161
- *
9162
- * JavaScript Object Notation
9163
- * (<a href="https://developer.mozilla.org/en-US/docs/Glossary/JSON" target="_blank">JSON</a>)
9164
- * is a standard format for sending data between applications. The format is
9165
- * based on JavaScript objects which have keys and values. JSON files store
9166
- * data in an object with strings as keys. Values can be strings, numbers,
9167
- * Booleans, arrays, `null`, or other objects.
9168
- *
9169
- * The first parameter, `json`, is the data to save. The data can be an array,
9170
- * as in `[1, 2, 3]`, or an object, as in
9171
- * `{ x: 50, y: 50, color: 'deeppink' }`.
9172
- *
9173
- * The second parameter, `filename`, is a string that sets the file's name.
9174
- * For example, calling `saveJSON([1, 2, 3], 'data.json')` saves the array
9175
- * `[1, 2, 3]` to a file called `data.json` on the user's computer.
9176
- *
9177
- * The third parameter, `optimize`, is optional. If `true` is passed, as in
9178
- * `saveJSON([1, 2, 3], 'data.json', true)`, then all unneeded whitespace will
9179
- * be removed to reduce the file size.
9180
- *
9181
- * Note: The browser will either save the file immediately or prompt the user
9182
- * with a dialogue window.
9183
- * @param json data to save.
9184
- * @param filename name of the file to be saved.
9185
- * @param optimize whether to trim unneeded whitespace. Defaults
9186
- * to `true`.
9187
- */
9188
- saveJSON(json: any[] | object, filename: string, optimize?: boolean): void;
9220
+ buildNormalShader(callback: Function, scope?: object): p5.Shader;
9221
+ buildNormalShader(hooks: object, scope?: object): p5.Shader;
9189
9222
 
9190
9223
  /**
9191
9224
  * A function that's called once when the mouse wheel moves.
@@ -9231,54 +9264,6 @@ declare class p5 {
9231
9264
  */
9232
9265
  mouseWheel(event?: WheelEvent): void;
9233
9266
 
9234
- /**
9235
- * Loads a new shader from a file that can change how fills are drawn, based on the material used
9236
- * when <a href="#/p5/normalMaterial">`normalMaterial()`</a> is active. Pass the resulting
9237
- * shader into the <a href="#/p5/shader">`shader()`</a> function to apply it
9238
- * to any fills you draw.
9239
- *
9240
- * Since this function loads data from another file, it returns a `Promise`.
9241
- * Use it in an `async function setup`, and `await` its result.
9242
- *
9243
- * `let myShader;
9244
- * async function setup() {
9245
- * createCanvas(200, 200, WEBGL);
9246
- * myShader = await loadNormalShader('myMaterial.js');
9247
- * }
9248
- *
9249
- * function draw() {
9250
- * background(255);
9251
- * shader(myShader);
9252
- * myShader.setUniform('time', millis());
9253
- * lights();
9254
- * noStroke();
9255
- * fill('red');
9256
- * sphere(50);
9257
- * }`Inside your shader file, you can call p5.strands hooks to change parts of the shader. For
9258
- * example, you might use the `worldInputs` hook to change each vertex, or you
9259
- * might use the `finalColor` hook to change the color of each pixel on the surface of a shape.
9260
- *
9261
- * `// myMaterial.js
9262
- * let time = uniformFloat();
9263
- * worldInputs.begin();
9264
- * worldInputs.position.y +=
9265
- * 20 * sin(time * 0.001 + worldInputs.position.x * 0.05);
9266
- * worldInputs.end();`Read the reference for <a href="#/p5/buildNormalShader">`buildNormalShader`</a>,
9267
- * the version of `loadNormalShader` that takes in a function instead of a separate file,
9268
- * for a full list of hooks you can use and examples for each.
9269
- *
9270
- * The second parameter, `successCallback`, is optional. If a function is passed, as in
9271
- * `loadNormalShader('myShader.js', onLoaded)`, then the `onLoaded()` function will be called
9272
- * once the shader loads. The shader will be passed to `onLoaded()` as its only argument.
9273
- * The return value of `handleData()`, if present, will be used as the final return value of
9274
- * `loadNormalShader('myShader.js', onLoaded)`.
9275
- * @param url The URL of your p5.strands JavaScript file.
9276
- * @param onSuccess A callback function to run when loading completes.
9277
- * @param onFailure A callback function to run when loading fails.
9278
- * @returns The normal shader.
9279
- */
9280
- loadNormalShader(url: string, onSuccess?: Function, onFailure?: Function): Promise<p5.Shader>;
9281
-
9282
9267
  /**
9283
9268
  * Ends a drawing group that contains its own styles and transformations.
9284
9269
  *
@@ -9460,7 +9445,74 @@ declare class p5 {
9460
9445
  * @param multiple allow multiple files to be selected.
9461
9446
  * @returns The new input element.
9462
9447
  */
9463
- createFileInput(callback: (input: p5.File) => any, multiple?: boolean): p5.Element;
9448
+ createFileInput(callback: (input: p5.File) => any, multiple?: boolean): p5.Element;
9449
+
9450
+ /**
9451
+ * Locks the mouse pointer to its current position and makes it invisible.
9452
+ *
9453
+ * `requestPointerLock()` allows the mouse to move forever without leaving the
9454
+ * screen. Calling `requestPointerLock()` locks the values of
9455
+ * <a href="#/p5/mouseX">mouseX</a>, <a href="#/p5/mouseY">mouseY</a>,
9456
+ * <a href="#/p5/pmouseX">pmouseX</a>, and <a href="#/p5/pmouseY">pmouseY</a>.
9457
+ * <a href="#/p5/movedX">movedX</a> and <a href="#/p5/movedY">movedY</a>
9458
+ * continue updating and can be used to get the distance the mouse moved since
9459
+ * the last frame was drawn. Calling
9460
+ * <a href="#/p5/exitPointerLock">exitPointerLock()</a> resumes updating the
9461
+ * mouse system variables.
9462
+ *
9463
+ * Note: Most browsers require an input, such as a click, before calling
9464
+ * `requestPointerLock()`. It’s recommended to call `requestPointerLock()` in
9465
+ * an event function such as <a href="#/p5/doubleClicked">doubleClicked()</a>.
9466
+ */
9467
+ requestPointerLock(): void;
9468
+
9469
+ /**
9470
+ * Loads a new shader from a file that can change how fills are drawn, based on the material used
9471
+ * when <a href="#/p5/normalMaterial">`normalMaterial()`</a> is active. Pass the resulting
9472
+ * shader into the <a href="#/p5/shader">`shader()`</a> function to apply it
9473
+ * to any fills you draw.
9474
+ *
9475
+ * Since this function loads data from another file, it returns a `Promise`.
9476
+ * Use it in an `async function setup`, and `await` its result.
9477
+ *
9478
+ * `let myShader;
9479
+ * async function setup() {
9480
+ * createCanvas(200, 200, WEBGL);
9481
+ * myShader = await loadNormalShader('myMaterial.js');
9482
+ * }
9483
+ *
9484
+ * function draw() {
9485
+ * background(255);
9486
+ * shader(myShader);
9487
+ * myShader.setUniform('time', millis());
9488
+ * lights();
9489
+ * noStroke();
9490
+ * fill('red');
9491
+ * sphere(50);
9492
+ * }`Inside your shader file, you can call p5.strands hooks to change parts of the shader. For
9493
+ * example, you might use the `worldInputs` hook to change each vertex, or you
9494
+ * might use the `finalColor` hook to change the color of each pixel on the surface of a shape.
9495
+ *
9496
+ * `// myMaterial.js
9497
+ * let time = uniformFloat();
9498
+ * worldInputs.begin();
9499
+ * worldInputs.position.y +=
9500
+ * 20 * sin(time * 0.001 + worldInputs.position.x * 0.05);
9501
+ * worldInputs.end();`Read the reference for <a href="#/p5/buildNormalShader">`buildNormalShader`</a>,
9502
+ * the version of `loadNormalShader` that takes in a function instead of a separate file,
9503
+ * for a full list of hooks you can use and examples for each.
9504
+ *
9505
+ * The second parameter, `successCallback`, is optional. If a function is passed, as in
9506
+ * `loadNormalShader('myShader.js', onLoaded)`, then the `onLoaded()` function will be called
9507
+ * once the shader loads. The shader will be passed to `onLoaded()` as its only argument.
9508
+ * The return value of `handleData()`, if present, will be used as the final return value of
9509
+ * `loadNormalShader('myShader.js', onLoaded)`.
9510
+ * @param url The URL of your p5.strands JavaScript file.
9511
+ * @param onSuccess A callback function to run when loading completes.
9512
+ * @param onFailure A callback function to run when loading fails.
9513
+ * @returns The normal shader.
9514
+ */
9515
+ loadNormalShader(url: string, onSuccess?: Function, onFailure?: Function): Promise<p5.Shader>;
9464
9516
 
9465
9517
  /**
9466
9518
  * Returns the default shader used for fills when
@@ -9477,23 +9529,50 @@ declare class p5 {
9477
9529
  baseNormalShader(): p5.Shader;
9478
9530
 
9479
9531
  /**
9480
- * Locks the mouse pointer to its current position and makes it invisible.
9532
+ * Exits a pointer lock started with
9533
+ * <a href="#/p5/requestPointerLock">requestPointerLock</a>.
9481
9534
  *
9482
- * `requestPointerLock()` allows the mouse to move forever without leaving the
9483
- * screen. Calling `requestPointerLock()` locks the values of
9535
+ * Calling `requestPointerLock()` locks the values of
9484
9536
  * <a href="#/p5/mouseX">mouseX</a>, <a href="#/p5/mouseY">mouseY</a>,
9485
9537
  * <a href="#/p5/pmouseX">pmouseX</a>, and <a href="#/p5/pmouseY">pmouseY</a>.
9486
- * <a href="#/p5/movedX">movedX</a> and <a href="#/p5/movedY">movedY</a>
9487
- * continue updating and can be used to get the distance the mouse moved since
9488
- * the last frame was drawn. Calling
9489
- * <a href="#/p5/exitPointerLock">exitPointerLock()</a> resumes updating the
9490
- * mouse system variables.
9538
+ * Calling `exitPointerLock()` resumes updating the mouse system variables.
9491
9539
  *
9492
9540
  * Note: Most browsers require an input, such as a click, before calling
9493
9541
  * `requestPointerLock()`. It’s recommended to call `requestPointerLock()` in
9494
9542
  * an event function such as <a href="#/p5/doubleClicked">doubleClicked()</a>.
9495
9543
  */
9496
- requestPointerLock(): void;
9544
+ exitPointerLock(): void;
9545
+
9546
+ /**
9547
+ * Saves an `Array` of `String`s to a file, one per line.
9548
+ *
9549
+ * The first parameter, `list`, is an array with the strings to save.
9550
+ *
9551
+ * The second parameter, `filename`, is a string that sets the file's name.
9552
+ * For example, calling `saveStrings(['0', '01', '011'], 'data.txt')` saves
9553
+ * the array `['0', '01', '011']` to a file called `data.txt` on the user's
9554
+ * computer.
9555
+ *
9556
+ * The third parameter, `extension`, is optional. If a string is passed, as in
9557
+ * `saveStrings(['0', '01', '0`1'], 'data', 'txt')`, the second parameter will
9558
+ * be interpreted as the file name and the third parameter as the extension.
9559
+ *
9560
+ * The fourth parameter, `isCRLF`, is also optional, If `true` is passed, as
9561
+ * in `saveStrings(['0', '01', '011'], 'data', 'txt', true)`, then two
9562
+ * characters, `\r\n` , will be added to the end of each string to create new
9563
+ * lines in the saved file. `\r` is a carriage return (CR) and `\n` is a line
9564
+ * feed (LF). By default, only `\n` (line feed) is added to each string in
9565
+ * order to create new lines.
9566
+ *
9567
+ * Note: The browser will either save the file immediately or prompt the user
9568
+ * with a dialogue window.
9569
+ * @param list data to save.
9570
+ * @param filename name of file to be saved.
9571
+ * @param extension format to use for the file.
9572
+ * @param isCRLF whether to add `\r\n` to the end of each
9573
+ * string. Defaults to `false`.
9574
+ */
9575
+ saveStrings(list: string[], filename: string, extension?: string, isCRLF?: boolean): void;
9497
9576
 
9498
9577
  /**
9499
9578
  * Create a new shader that can change how fills are drawn, based on the default shader
@@ -9547,56 +9626,11 @@ declare class p5 {
9547
9626
  * Read the <a href="#/p5.Shader/modify">reference entry for `modify()`</a>
9548
9627
  * for more info.
9549
9628
  * @param callback A function building a p5.strands shader.
9629
+ * @param scope An optional scope object passed to .modify().
9550
9630
  * @returns The color shader.
9551
9631
  */
9552
- buildColorShader(callback: Function): p5.Shader;
9553
- buildColorShader(hooks: object): p5.Shader;
9554
-
9555
- /**
9556
- * Exits a pointer lock started with
9557
- * <a href="#/p5/requestPointerLock">requestPointerLock</a>.
9558
- *
9559
- * Calling `requestPointerLock()` locks the values of
9560
- * <a href="#/p5/mouseX">mouseX</a>, <a href="#/p5/mouseY">mouseY</a>,
9561
- * <a href="#/p5/pmouseX">pmouseX</a>, and <a href="#/p5/pmouseY">pmouseY</a>.
9562
- * Calling `exitPointerLock()` resumes updating the mouse system variables.
9563
- *
9564
- * Note: Most browsers require an input, such as a click, before calling
9565
- * `requestPointerLock()`. It’s recommended to call `requestPointerLock()` in
9566
- * an event function such as <a href="#/p5/doubleClicked">doubleClicked()</a>.
9567
- */
9568
- exitPointerLock(): void;
9569
-
9570
- /**
9571
- * Saves an `Array` of `String`s to a file, one per line.
9572
- *
9573
- * The first parameter, `list`, is an array with the strings to save.
9574
- *
9575
- * The second parameter, `filename`, is a string that sets the file's name.
9576
- * For example, calling `saveStrings(['0', '01', '011'], 'data.txt')` saves
9577
- * the array `['0', '01', '011']` to a file called `data.txt` on the user's
9578
- * computer.
9579
- *
9580
- * The third parameter, `extension`, is optional. If a string is passed, as in
9581
- * `saveStrings(['0', '01', '0`1'], 'data', 'txt')`, the second parameter will
9582
- * be interpreted as the file name and the third parameter as the extension.
9583
- *
9584
- * The fourth parameter, `isCRLF`, is also optional, If `true` is passed, as
9585
- * in `saveStrings(['0', '01', '011'], 'data', 'txt', true)`, then two
9586
- * characters, `\r\n` , will be added to the end of each string to create new
9587
- * lines in the saved file. `\r` is a carriage return (CR) and `\n` is a line
9588
- * feed (LF). By default, only `\n` (line feed) is added to each string in
9589
- * order to create new lines.
9590
- *
9591
- * Note: The browser will either save the file immediately or prompt the user
9592
- * with a dialogue window.
9593
- * @param list data to save.
9594
- * @param filename name of file to be saved.
9595
- * @param extension format to use for the file.
9596
- * @param isCRLF whether to add `\r\n` to the end of each
9597
- * string. Defaults to `false`.
9598
- */
9599
- saveStrings(list: string[], filename: string, extension?: string, isCRLF?: boolean): void;
9632
+ buildColorShader(callback: Function, scope?: object): p5.Shader;
9633
+ buildColorShader(hooks: object, scope?: object): p5.Shader;
9600
9634
 
9601
9635
  /**
9602
9636
  * Connects points with a smooth curve (a spline).
@@ -9666,6 +9700,18 @@ declare class p5 {
9666
9700
  splineVertex(x: number, y: number, u?: number, v?: number): void;
9667
9701
  splineVertex(x: number, y: number, z: number, u?: number, v?: number): void;
9668
9702
 
9703
+ /**
9704
+ * Writes the contents of a <a href="#/p5.Table">Table</a> object to a file. Defaults to a
9705
+ * text file with comma-separated-values ('csv') but can also
9706
+ * use tab separation ('tsv'), or generate an HTML table ('html').
9707
+ * The file saving process and location of the saved file will
9708
+ * vary between web browsers.
9709
+ * @param Table the <a href="#/p5.Table">Table</a> object to save to a file
9710
+ * @param filename the filename to which the Table should be saved
9711
+ * @param options can be one of "tsv", "csv", or "html"
9712
+ */
9713
+ saveTable(Table: p5.Table, filename: string, options?: string): void;
9714
+
9669
9715
  /**
9670
9716
  * Loads a new shader from a file that can change how fills are drawn, based on the material used
9671
9717
  * when no lights or textures are active. Pass the resulting
@@ -9714,18 +9760,6 @@ declare class p5 {
9714
9760
  */
9715
9761
  loadColorShader(url: string, onSuccess?: Function, onFailure?: Function): Promise<p5.Shader>;
9716
9762
 
9717
- /**
9718
- * Writes the contents of a <a href="#/p5.Table">Table</a> object to a file. Defaults to a
9719
- * text file with comma-separated-values ('csv') but can also
9720
- * use tab separation ('tsv'), or generate an HTML table ('html').
9721
- * The file saving process and location of the saved file will
9722
- * vary between web browsers.
9723
- * @param Table the <a href="#/p5.Table">Table</a> object to save to a file
9724
- * @param filename the filename to which the Table should be saved
9725
- * @param options can be one of "tsv", "csv", or "html"
9726
- */
9727
- saveTable(Table: p5.Table, filename: string, options?: string): void;
9728
-
9729
9763
  /**
9730
9764
  * Returns the default shader used for fills when no lights or textures are activate.
9731
9765
  *
@@ -10023,62 +10057,11 @@ declare class p5 {
10023
10057
  * Read the <a href="#/p5.Shader/modify">reference entry for `modify()`</a>
10024
10058
  * for more info.
10025
10059
  * @param callback A function building a p5.strands shader.
10060
+ * @param scope An optional scope object passed to .modify().
10026
10061
  * @returns The stroke shader.
10027
10062
  */
10028
- buildStrokeShader(callback: Function): p5.Shader;
10029
- buildStrokeShader(hooks: object): p5.Shader;
10030
-
10031
- /**
10032
- * Loads a new shader from a file that can change how strokes are drawn. Pass the resulting
10033
- * shader into the <a href="#/p5/strokeShader">`strokeShader()`</a> function to apply it
10034
- * to any strokes you draw.
10035
- *
10036
- * Since this function loads data from another file, it returns a `Promise`.
10037
- * Use it in an `async function setup`, and `await` its result.
10038
- *
10039
- * `let myShader;
10040
- * async function setup() {
10041
- * createCanvas(200, 200, WEBGL);
10042
- * myShader = await loadStrokeShader('myMaterial.js');
10043
- * }
10044
- *
10045
- * function draw() {
10046
- * background(255);
10047
- * strokeShader(myShader);
10048
- * strokeWeight(30);
10049
- * line(
10050
- * -width/3,
10051
- * sin(millis()*0.001) * height/4,
10052
- * width/3,
10053
- * sin(millis()*0.001 + 1) * height/4
10054
- * );
10055
- * }`Inside your shader file, you can call p5.strands hooks to change parts of the shader. For
10056
- * example, you might use the `worldInputs` hook to change each vertex, or you
10057
- * might use the `pixelInputs` hook to change each pixel on the surface of a stroke.
10058
- *
10059
- * `// myMaterial.js
10060
- * pixelInputs.begin();
10061
- * let opacity = 1 - smoothstep(
10062
- * 0,
10063
- * 15,
10064
- * length(pixelInputs.position - pixelInputs.center)
10065
- * );
10066
- * pixelInputs.color.a *= opacity;
10067
- * pixelInputs.end();`Read the reference for <a href="#/p5/buildStrokeShader">`buildStrokeShader`</a>,
10068
- * the version of `loadStrokeShader` that takes in a function instead of a separate file,
10069
- * for a full list of hooks you can use and examples for each.
10070
- *
10071
- * The second parameter, `successCallback`, is optional. If a function is passed, as in
10072
- * `loadStrokeShader('myShader.js', onLoaded)`, then the `onLoaded()` function will be called
10073
- * once the shader loads. The shader will be passed to `onLoaded()` as its only argument.
10074
- * The return value of `handleData()`, if present, will be used as the final return value of
10075
- * `loadStrokeShader('myShader.js', onLoaded)`.
10076
- * @param url The URL of your p5.strands JavaScript file.
10077
- * @param onSuccess A callback function to run when loading completes.
10078
- * @param onFailure A callback function to run when loading fails.
10079
- * @returns The stroke shader.
10080
- */
10081
- loadStrokeShader(url: string, onSuccess?: Function, onFailure?: Function): Promise<p5.Shader>;
10063
+ buildStrokeShader(callback: Function, scope?: object): p5.Shader;
10064
+ buildStrokeShader(hooks: object, scope?: object): p5.Shader;
10082
10065
 
10083
10066
  /**
10084
10067
  * Gets or sets a given spline property.
@@ -10203,6 +10186,58 @@ declare class p5 {
10203
10186
  */
10204
10187
  perspective(fovy?: number, aspect?: number, near?: number, far?: number): void;
10205
10188
 
10189
+ /**
10190
+ * Loads a new shader from a file that can change how strokes are drawn. Pass the resulting
10191
+ * shader into the <a href="#/p5/strokeShader">`strokeShader()`</a> function to apply it
10192
+ * to any strokes you draw.
10193
+ *
10194
+ * Since this function loads data from another file, it returns a `Promise`.
10195
+ * Use it in an `async function setup`, and `await` its result.
10196
+ *
10197
+ * `let myShader;
10198
+ * async function setup() {
10199
+ * createCanvas(200, 200, WEBGL);
10200
+ * myShader = await loadStrokeShader('myMaterial.js');
10201
+ * }
10202
+ *
10203
+ * function draw() {
10204
+ * background(255);
10205
+ * strokeShader(myShader);
10206
+ * strokeWeight(30);
10207
+ * line(
10208
+ * -width/3,
10209
+ * sin(millis()*0.001) * height/4,
10210
+ * width/3,
10211
+ * sin(millis()*0.001 + 1) * height/4
10212
+ * );
10213
+ * }`Inside your shader file, you can call p5.strands hooks to change parts of the shader. For
10214
+ * example, you might use the `worldInputs` hook to change each vertex, or you
10215
+ * might use the `pixelInputs` hook to change each pixel on the surface of a stroke.
10216
+ *
10217
+ * `// myMaterial.js
10218
+ * pixelInputs.begin();
10219
+ * let opacity = 1 - smoothstep(
10220
+ * 0,
10221
+ * 15,
10222
+ * length(pixelInputs.position - pixelInputs.center)
10223
+ * );
10224
+ * pixelInputs.color.a *= opacity;
10225
+ * pixelInputs.end();`Read the reference for <a href="#/p5/buildStrokeShader">`buildStrokeShader`</a>,
10226
+ * the version of `loadStrokeShader` that takes in a function instead of a separate file,
10227
+ * for a full list of hooks you can use and examples for each.
10228
+ *
10229
+ * The second parameter, `successCallback`, is optional. If a function is passed, as in
10230
+ * `loadStrokeShader('myShader.js', onLoaded)`, then the `onLoaded()` function will be called
10231
+ * once the shader loads. The shader will be passed to `onLoaded()` as its only argument.
10232
+ * The return value of `handleData()`, if present, will be used as the final return value of
10233
+ * `loadStrokeShader('myShader.js', onLoaded)`.
10234
+ * @param url The URL of your p5.strands JavaScript file.
10235
+ * @param onSuccess A callback function to run when loading completes.
10236
+ * @param onFailure A callback function to run when loading fails.
10237
+ * @returns The stroke shader.
10238
+ */
10239
+ loadStrokeShader(url: string, onSuccess?: Function, onFailure?: Function): Promise<p5.Shader>;
10240
+
10206
10241
  /**
10207
10242
  * Returns the default shader used for strokes.
10208
10243
  *
@@ -10216,17 +10251,6 @@ declare class p5 {
10216
10251
  */
10217
10252
  baseStrokeShader(): p5.Shader;
10218
10253
 
10219
- /**
10220
- * Restores the default shaders.
10221
- *
10222
- * `resetShader()` deactivates any shaders previously applied by
10223
- * <a href="#/p5/shader">shader()</a>, <a href="#/p5/strokeShader">strokeShader()</a>,
10224
- * or <a href="#/p5/imageShader">imageShader()</a>.
10225
- *
10226
- * Note: Shaders can only be used in WebGL mode.
10227
- */
10228
- resetShader(): void;
10229
-
10230
10254
  /**
10231
10255
  * Sets multiple properties for spline curves at once.
10232
10256
  *
@@ -10295,6 +10319,17 @@ declare class p5 {
10295
10319
  linePerspective(enable: boolean): boolean;
10296
10320
  linePerspective(): boolean;
10297
10321
 
10322
+ /**
10323
+ * Restores the default shaders.
10324
+ *
10325
+ * `resetShader()` deactivates any shaders previously applied by
10326
+ * <a href="#/p5/shader">shader()</a>, <a href="#/p5/strokeShader">strokeShader()</a>,
10327
+ * or <a href="#/p5/imageShader">imageShader()</a>.
10328
+ *
10329
+ * Note: Shaders can only be used in WebGL mode.
10330
+ */
10331
+ resetShader(): void;
10332
+
10298
10333
  /**
10299
10334
  * Sets an orthographic projection for the current camera in a 3D sketch.
10300
10335
  *