p5 2.0.1 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (160) hide show
  1. package/dist/accessibility/color_namer.js +5 -5
  2. package/dist/accessibility/describe.js +10 -0
  3. package/dist/accessibility/index.js +5 -5
  4. package/dist/accessibility/outputs.js +21 -0
  5. package/dist/app.js +5 -5
  6. package/dist/color/color_conversion.js +5 -5
  7. package/dist/color/creating_reading.js +1 -1
  8. package/dist/color/index.js +2 -2
  9. package/dist/color/p5.Color.js +1 -1
  10. package/dist/color/setting.js +2 -2
  11. package/dist/{constants-C-g_eAdC.js → constants-BRcElHU3.js} +19 -3
  12. package/dist/core/constants.js +1 -1
  13. package/dist/core/environment.js +6 -5
  14. package/dist/core/friendly_errors/fes_core.js +1 -1
  15. package/dist/core/friendly_errors/index.js +1 -1
  16. package/dist/core/friendly_errors/param_validator.js +46 -93
  17. package/dist/core/friendly_errors/sketch_reader.js +5 -5
  18. package/dist/core/friendly_errors/sketch_verifier.js +1 -1
  19. package/dist/core/friendly_errors/validate_params.js +5 -5
  20. package/dist/core/helpers.js +1 -1
  21. package/dist/core/init.js +5 -5
  22. package/dist/core/legacy.js +5 -5
  23. package/dist/core/main.js +5 -5
  24. package/dist/core/p5.Graphics.js +4 -4
  25. package/dist/core/p5.Renderer.js +3 -3
  26. package/dist/core/p5.Renderer2D.js +5 -5
  27. package/dist/core/rendering.js +4 -4
  28. package/dist/{creating_reading-D4AAKRbx.js → creating_reading-Cr8L2Jnm.js} +2 -2
  29. package/dist/dom/dom.js +10 -10
  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/events/acceleration.js +24 -24
  34. package/dist/events/keyboard.js +11 -6
  35. package/dist/image/const.js +1 -1
  36. package/dist/image/filterRenderer2D.js +4 -4
  37. package/dist/image/image.js +4 -4
  38. package/dist/image/index.js +4 -4
  39. package/dist/image/loading_displaying.js +4 -4
  40. package/dist/image/p5.Image.js +3 -3
  41. package/dist/image/pixels.js +1 -0
  42. package/dist/io/files.js +4 -4
  43. package/dist/io/index.js +4 -4
  44. package/dist/io/p5.TableRow.js +2 -2
  45. package/dist/{main-s72KWcUy.js → main-BKN5yFoS.js} +12 -9
  46. package/dist/math/Matrices/Matrix.js +1 -1
  47. package/dist/math/Matrices/MatrixNumjs.js +1 -1
  48. package/dist/math/index.js +1 -1
  49. package/dist/math/math.js +1 -1
  50. package/dist/math/p5.Matrix.js +1 -1
  51. package/dist/math/p5.Vector.js +1 -1
  52. package/dist/math/trigonometry.js +1 -1
  53. package/dist/{p5.Renderer-CwAYZOC2.js → p5.Renderer-R23xoC7s.js} +5 -5
  54. package/dist/{rendering--aAe5aq3.js → rendering-CvUVN-Vb.js} +101 -66
  55. package/dist/shape/2d_primitives.js +1 -1
  56. package/dist/shape/attributes.js +1 -1
  57. package/dist/shape/custom_shapes.js +2 -2
  58. package/dist/shape/index.js +2 -2
  59. package/dist/type/index.js +3 -3
  60. package/dist/type/p5.Font.js +3 -5
  61. package/dist/type/textCore.js +4 -4
  62. package/dist/webgl/3d_primitives.js +4 -4
  63. package/dist/webgl/GeometryBuilder.js +1 -1
  64. package/dist/webgl/ShapeBuilder.js +1 -1
  65. package/dist/webgl/index.js +4 -4
  66. package/dist/webgl/interaction.js +1 -1
  67. package/dist/webgl/light.js +4 -4
  68. package/dist/webgl/loading.js +5 -4
  69. package/dist/webgl/material.js +4 -4
  70. package/dist/webgl/p5.Camera.js +4 -4
  71. package/dist/webgl/p5.Framebuffer.js +4 -4
  72. package/dist/webgl/p5.Geometry.js +1 -1
  73. package/dist/webgl/p5.Quat.js +1 -1
  74. package/dist/webgl/p5.RendererGL.js +4 -4
  75. package/dist/webgl/p5.Shader.js +4 -4
  76. package/dist/webgl/p5.Texture.js +4 -4
  77. package/dist/webgl/text.js +32 -34
  78. package/lib/p5.esm.js +289 -247
  79. package/lib/p5.js +289 -247
  80. package/lib/p5.min.js +1 -1
  81. package/package.json +1 -2
  82. package/types/accessibility/color_namer.d.ts +8 -0
  83. package/types/accessibility/describe.d.ts +184 -0
  84. package/types/accessibility/gridOutput.d.ts +8 -0
  85. package/types/accessibility/outputs.d.ts +235 -0
  86. package/types/accessibility/textOutput.d.ts +8 -0
  87. package/types/color/color_conversion.d.ts +47 -0
  88. package/types/color/creating_reading.d.ts +1348 -0
  89. package/types/color/p5.Color.d.ts +1070 -0
  90. package/types/color/setting.d.ts +2085 -0
  91. package/types/core/constants.d.ts +341 -0
  92. package/types/core/environment.d.ts +668 -0
  93. package/types/core/friendly_errors/fes_core.d.ts +8 -0
  94. package/types/core/friendly_errors/file_errors.d.ts +8 -0
  95. package/types/core/friendly_errors/param_validator.d.ts +30 -0
  96. package/types/core/friendly_errors/sketch_reader.d.ts +8 -0
  97. package/types/core/friendly_errors/stacktrace.d.ts +11 -0
  98. package/types/core/friendly_errors/validate_params.d.ts +8 -0
  99. package/types/core/helpers.d.ts +8 -0
  100. package/types/core/legacy.d.ts +8 -0
  101. package/types/core/main.d.ts +5999 -0
  102. package/types/core/p5.Graphics.d.ts +484 -0
  103. package/types/core/p5.Renderer.d.ts +14 -0
  104. package/types/core/reference.d.ts +8 -0
  105. package/types/core/rendering.d.ts +481 -0
  106. package/types/core/structure.d.ts +492 -0
  107. package/types/core/transform.d.ts +1638 -0
  108. package/types/data/local_storage.d.ts +323 -0
  109. package/types/dom/dom.d.ts +1295 -0
  110. package/types/dom/p5.Element.d.ts +2011 -0
  111. package/types/dom/p5.File.d.ts +13 -0
  112. package/types/dom/p5.MediaElement.d.ts +1249 -0
  113. package/types/events/acceleration.d.ts +193 -0
  114. package/types/events/keyboard.d.ts +501 -0
  115. package/types/events/pointer.d.ts +782 -0
  116. package/types/global.d.ts +5544 -0
  117. package/types/image/filterRenderer2D.d.ts +54 -0
  118. package/types/image/image.d.ts +326 -0
  119. package/types/image/loading_displaying.d.ts +580 -0
  120. package/types/image/p5.Image.d.ts +5882 -0
  121. package/types/image/pixels.d.ts +832 -0
  122. package/types/io/files.d.ts +1447 -0
  123. package/types/io/p5.Table.d.ts +1247 -0
  124. package/types/io/p5.TableRow.d.ts +343 -0
  125. package/types/io/p5.XML.d.ts +1188 -0
  126. package/types/math/Matrices/Matrix.d.ts +1029 -0
  127. package/types/math/Matrices/MatrixNumjs.d.ts +8 -0
  128. package/types/math/calculation.d.ts +923 -0
  129. package/types/math/math.d.ts +90 -0
  130. package/types/math/noise.d.ts +311 -0
  131. package/types/math/p5.Matrix.d.ts +8 -0
  132. package/types/math/p5.Vector.d.ts +3416 -0
  133. package/types/math/random.d.ts +267 -0
  134. package/types/math/trigonometry.d.ts +663 -0
  135. package/types/p5.d.ts +6666 -0
  136. package/types/shape/2d_primitives.d.ts +1033 -0
  137. package/types/shape/attributes.d.ts +466 -0
  138. package/types/shape/curves.d.ts +740 -0
  139. package/types/shape/custom_shapes.d.ts +888 -0
  140. package/types/shape/vertex.d.ts +1141 -0
  141. package/types/type/p5.Font.d.ts +575 -0
  142. package/types/type/textCore.d.ts +1198 -0
  143. package/types/utilities/conversion.d.ts +894 -0
  144. package/types/utilities/time_date.d.ts +295 -0
  145. package/types/utilities/utility_functions.d.ts +587 -0
  146. package/types/webgl/3d_primitives.d.ts +1432 -0
  147. package/types/webgl/ShaderGenerator.d.ts +8 -0
  148. package/types/webgl/interaction.d.ts +371 -0
  149. package/types/webgl/light.d.ts +1184 -0
  150. package/types/webgl/loading.d.ts +482 -0
  151. package/types/webgl/material.d.ts +2656 -0
  152. package/types/webgl/p5.Camera.d.ts +3023 -0
  153. package/types/webgl/p5.DataArray.d.ts +61 -0
  154. package/types/webgl/p5.Framebuffer.d.ts +760 -0
  155. package/types/webgl/p5.Geometry.d.ts +1191 -0
  156. package/types/webgl/p5.Quat.d.ts +45 -0
  157. package/types/webgl/p5.RendererGL.d.ts +234 -0
  158. package/types/webgl/p5.Shader.d.ts +660 -0
  159. package/types/webgl/p5.Texture.d.ts +61 -0
  160. package/types/webgl/text.d.ts +74 -0
package/lib/p5.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! p5.js v2.0.1 April 23, 2025 */
1
+ /*! p5.js v2.0.3 May 30, 2025 */
2
2
  /**
3
3
  * @module Constants
4
4
  * @submodule Constants
@@ -12,17 +12,33 @@ const _PI = Math.PI;
12
12
  * @property {String} VERSION
13
13
  * @final
14
14
  */
15
- const VERSION = '2.0.1';
15
+ const VERSION = '2.0.3';
16
16
 
17
17
  // GRAPHICS RENDERER
18
18
  /**
19
- * The default, two-dimensional renderer.
20
- * @typedef {unique symbol} P2D
19
+ * The default, two-dimensional renderer in p5.js.
20
+ *
21
+ * Use this when calling <a href="#/p5/createCanvas"> (for example,
22
+ * `createCanvas(400, 400, P2D)`) to specify a 2D context.
23
+ *
24
+ * @typedef {'p2d'} P2D
21
25
  * @property {P2D} P2D
22
26
  * @final
23
27
  */
24
28
  const P2D = 'p2d';
25
29
 
30
+ /**
31
+ * A high-dynamic-range (HDR) variant of the default, two-dimensional renderer.
32
+ *
33
+ * When available, this mode can allow for extended color ranges and more
34
+ * dynamic color representation. Use it similarly to `P2D`:
35
+ * `createCanvas(400, 400, P2DHDR)`.
36
+ *
37
+ * @typedef {'p2d-hdr'} P2DHDR
38
+ * @property {P2DHDR} P2DHDR
39
+ * @final
40
+ */
41
+
26
42
  const P2DHDR = 'p2d-hdr';
27
43
 
28
44
  /**
@@ -8010,8 +8026,8 @@ function environment$1(p5, fn){
8010
8026
  * @method print
8011
8027
  * @param {Any} contents content to print to the console.
8012
8028
  * @example
8013
- * <div>
8014
- * <code class="norender">
8029
+ * <div class="norender">
8030
+ * <code>
8015
8031
  * function setup() {
8016
8032
  * // Prints "hello, world" to the console.
8017
8033
  * print('hello, world');
@@ -8019,8 +8035,8 @@ function environment$1(p5, fn){
8019
8035
  * </code>
8020
8036
  * </div>
8021
8037
  *
8022
- * <div>
8023
- * <code class="norender">
8038
+ * <div class="norender">
8039
+ * <code>
8024
8040
  * function setup() {
8025
8041
  * let name = 'ada';
8026
8042
  * // Prints "hello, ada" to the console.
@@ -8493,6 +8509,7 @@ function environment$1(p5, fn){
8493
8509
  * - `WEBGL2` whose value is `'webgl2'`,
8494
8510
  * - `WEBGL` whose value is `'webgl'`, or
8495
8511
  * - `P2D` whose value is `'p2d'`. This is the default for 2D sketches.
8512
+ * - `P2DHDR` whose value is `'p2d-hdr'` (used for HDR 2D sketches, if available).
8496
8513
  *
8497
8514
  * See <a href="#/p5/setAttributes">setAttributes()</a> for ways to set the
8498
8515
  * WebGL version.
@@ -13840,7 +13857,7 @@ class Color {
13840
13857
  * }
13841
13858
  * </code>
13842
13859
  * </div>
13843
- **/
13860
+ */
13844
13861
  setGreen(new_green, max=[0, 1]) {
13845
13862
  if(!Array.isArray(max)){
13846
13863
  max = [0, max];
@@ -13951,7 +13968,7 @@ class Color {
13951
13968
  * }
13952
13969
  * </code>
13953
13970
  * </div>
13954
- **/
13971
+ */
13955
13972
  setAlpha(new_alpha, max=[0, 1]) {
13956
13973
  if(!Array.isArray(max)){
13957
13974
  max = [0, max];
@@ -22658,7 +22675,7 @@ class Image {
22658
22675
  *
22659
22676
  * async function setup() {
22660
22677
  * // Load the image.
22661
- * gif = await loadImage('assets/arnott-wallace-wink-loop-forever.gif');
22678
+ * gif = await loadImage('assets/arnott-wallace-eye-loop-forever.gif');
22662
22679
  *
22663
22680
  * createCanvas(100, 100);
22664
22681
  *
@@ -22698,7 +22715,7 @@ class Image {
22698
22715
  *
22699
22716
  * async function setup() {
22700
22717
  * // Load the image.
22701
- * gif = await loadImage('assets/arnott-wallace-wink-loop-forever.gif');
22718
+ * gif = await loadImage('assets/arnott-wallace-eye-loop-forever.gif');
22702
22719
  *
22703
22720
  * createCanvas(100, 100);
22704
22721
  *
@@ -22754,7 +22771,7 @@ class Image {
22754
22771
  *
22755
22772
  * async function setup() {
22756
22773
  * // Load the image.
22757
- * gif = await loadImage('assets/arnott-wallace-wink-loop-forever.gif');
22774
+ * gif = await loadImage('assets/arnott-wallace-eye-loop-forever.gif');
22758
22775
  *
22759
22776
  * createCanvas(100, 100);
22760
22777
  *
@@ -37616,7 +37633,7 @@ function files(p5, fn){
37616
37633
  * }
37617
37634
  *
37618
37635
  * function mousePressed() {
37619
- * httpPost(url, 'json', postData, function(result) {
37636
+ * httpPost(url, postData, 'json', function(result) {
37620
37637
  * strokeWeight(2);
37621
37638
  * text(result.body, mouseX, mouseY);
37622
37639
  * });
@@ -37636,8 +37653,8 @@ function files(p5, fn){
37636
37653
  * function mousePressed() {
37637
37654
  * httpPost(
37638
37655
  * url,
37639
- * 'json',
37640
37656
  * postData,
37657
+ * 'json',
37641
37658
  * function(result) {
37642
37659
  * // ... won't be called
37643
37660
  * },
@@ -37755,20 +37772,29 @@ function files(p5, fn){
37755
37772
  * let eqFeatureIndex = 0;
37756
37773
  *
37757
37774
  * function setup() {
37775
+ * createCanvas(100,100);
37776
+ *
37758
37777
  * let url = 'https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson';
37778
+ *
37779
+ * const req = new Request(url, {
37780
+ * method: 'GET',
37781
+ * headers: {authorization: 'Bearer secretKey'}
37782
+ * });
37783
+ * // httpDo(path, method, datatype, success, error)
37784
+ *
37759
37785
  * httpDo(
37760
- * url,
37761
- * {
37762
- * method: 'GET',
37763
- * // Other Request options, like special headers for apis
37764
- * headers: { authorization: 'Bearer secretKey' }
37786
+ * req,
37787
+ * 'GET',
37788
+ * 'json',
37789
+ * res => {
37790
+ * earthquakes = res;
37765
37791
  * },
37766
- * function(res) {
37767
- * earthquakes = res;
37768
- * }
37769
- * );
37792
+ * err => {
37793
+ * console.error('Error loading data:', err);
37794
+ * }
37795
+ * );
37770
37796
  * }
37771
- *
37797
+ *
37772
37798
  * function draw() {
37773
37799
  * // wait until the data is loaded
37774
37800
  * if (!earthquakes || !earthquakes.features[eqFeatureIndex]) {
@@ -39764,7 +39790,7 @@ function loadingDisplaying(p5, fn){
39764
39790
  * are set to `CENTER`.
39765
39791
  *
39766
39792
  * @method image
39767
- * @param {p5.Image|p5.Element|p5.Texture|p5.Framebuffer|p5.FramebufferTexture} img image to display.
39793
+ * @param {p5.Image|p5.Element|p5.Texture|p5.Framebuffer|p5.FramebufferTexture|p5.Renderer|p5.Graphics} img image to display.
39768
39794
  * @param {Number} x x-coordinate of the top-left corner of the image.
39769
39795
  * @param {Number} y y-coordinate of the top-left corner of the image.
39770
39796
  * @param {Number} [width] width to draw the image.
@@ -40331,6 +40357,7 @@ function pixels(p5, fn){
40331
40357
  * <code>
40332
40358
  * function setup() {
40333
40359
  * createCanvas(100, 100);
40360
+ * background(128);
40334
40361
  *
40335
40362
  * // Load the pixels array.
40336
40363
  * loadPixels();
@@ -46686,7 +46713,7 @@ class Camera {
46686
46713
  * fill(0);
46687
46714
  *
46688
46715
  * // Display the value of eyeX, rounded to the nearest integer.
46689
- * text(`eyeX: ${round(cam.eyeX)}`, 0, 55);
46716
+ * text(`eyeX: ${round(cam.eyeX)}`, 0, 45);
46690
46717
  * }
46691
46718
  * </code>
46692
46719
  * </div>
@@ -46704,9 +46731,6 @@ class Camera {
46704
46731
  * // Create a p5.Camera object.
46705
46732
  * cam = createCamera();
46706
46733
  *
46707
- * // Set the camera
46708
- * setCamera(cam);
46709
- *
46710
46734
  * // Place the camera at the top-center.
46711
46735
  * cam.setPosition(0, -400, 800);
46712
46736
  *
@@ -46740,7 +46764,7 @@ class Camera {
46740
46764
  * cam.setPosition(x, -400, 800);
46741
46765
  *
46742
46766
  * // Display the value of eyeX, rounded to the nearest integer.
46743
- * text(`eyeX: ${round(cam.eyeX)}`, 0, 55);
46767
+ * text(`eyeX: ${round(cam.eyeX)}`, 0, 45);
46744
46768
  * }
46745
46769
  * </code>
46746
46770
  * </div>
@@ -46798,7 +46822,7 @@ class Camera {
46798
46822
  * fill(0);
46799
46823
  *
46800
46824
  * // Display the value of eyeY, rounded to the nearest integer.
46801
- * text(`eyeY: ${round(cam.eyeY)}`, 0, 55);
46825
+ * text(`eyeY: ${round(cam.eyeY)}`, 0, 45);
46802
46826
  * }
46803
46827
  * </code>
46804
46828
  * </div>
@@ -46852,7 +46876,7 @@ class Camera {
46852
46876
  * cam.setPosition(0, y, 800);
46853
46877
  *
46854
46878
  * // Display the value of eyeY, rounded to the nearest integer.
46855
- * text(`eyeY: ${round(cam.eyeY)}`, 0, 55);
46879
+ * text(`eyeY: ${round(cam.eyeY)}`, 0, 45);
46856
46880
  * }
46857
46881
  * </code>
46858
46882
  * </div>
@@ -46910,7 +46934,7 @@ class Camera {
46910
46934
  * fill(0);
46911
46935
  *
46912
46936
  * // Display the value of eyeZ, rounded to the nearest integer.
46913
- * text(`eyeZ: ${round(cam.eyeZ)}`, 0, 55);
46937
+ * text(`eyeZ: ${round(cam.eyeZ)}`, 0, 45);
46914
46938
  * }
46915
46939
  * </code>
46916
46940
  * </div>
@@ -46964,7 +46988,7 @@ class Camera {
46964
46988
  * cam.setPosition(0, -400, z);
46965
46989
  *
46966
46990
  * // Display the value of eyeZ, rounded to the nearest integer.
46967
- * text(`eyeZ: ${round(cam.eyeZ)}`, 0, 55);
46991
+ * text(`eyeZ: ${round(cam.eyeZ)}`, 0, 45);
46968
46992
  * }
46969
46993
  * </code>
46970
46994
  * </div>
@@ -47023,7 +47047,7 @@ class Camera {
47023
47047
  * fill(0);
47024
47048
  *
47025
47049
  * // Display the value of centerX, rounded to the nearest integer.
47026
- * text(`centerX: ${round(cam.centerX)}`, 0, 55);
47050
+ * text(`centerX: ${round(cam.centerX)}`, 0, 45);
47027
47051
  * }
47028
47052
  * </code>
47029
47053
  * </div>
@@ -47077,7 +47101,7 @@ class Camera {
47077
47101
  * cam.lookAt(x, 20, -30);
47078
47102
  *
47079
47103
  * // Display the value of centerX, rounded to the nearest integer.
47080
- * text(`centerX: ${round(cam.centerX)}`, 0, 55);
47104
+ * text(`centerX: ${round(cam.centerX)}`, 0, 45);
47081
47105
  * }
47082
47106
  * </code>
47083
47107
  * </div>
@@ -47136,7 +47160,7 @@ class Camera {
47136
47160
  * fill(0);
47137
47161
  *
47138
47162
  * // Display the value of centerY, rounded to the nearest integer.
47139
- * text(`centerY: ${round(cam.centerY)}`, 0, 55);
47163
+ * text(`centerY: ${round(cam.centerY)}`, 0, 45);
47140
47164
  * }
47141
47165
  * </code>
47142
47166
  * </div>
@@ -47190,7 +47214,7 @@ class Camera {
47190
47214
  * cam.lookAt(10, y, -30);
47191
47215
  *
47192
47216
  * // Display the value of centerY, rounded to the nearest integer.
47193
- * text(`centerY: ${round(cam.centerY)}`, 0, 55);
47217
+ * text(`centerY: ${round(cam.centerY)}`, 0, 45);
47194
47218
  * }
47195
47219
  * </code>
47196
47220
  * </div>
@@ -47249,7 +47273,7 @@ class Camera {
47249
47273
  * fill(0);
47250
47274
  *
47251
47275
  * // Display the value of centerZ, rounded to the nearest integer.
47252
- * text(`centerZ: ${round(cam.centerZ)}`, 0, 55);
47276
+ * text(`centerZ: ${round(cam.centerZ)}`, 0, 45);
47253
47277
  * }
47254
47278
  * </code>
47255
47279
  * </div>
@@ -47267,9 +47291,6 @@ class Camera {
47267
47291
  * // Create a p5.Camera object.
47268
47292
  * cam = createCamera();
47269
47293
  *
47270
- * // Set the camera
47271
- * setCamera(cam);
47272
- *
47273
47294
  * // Place the camera at the top-right.
47274
47295
  * cam.setPosition(100, -400, 800);
47275
47296
  *
@@ -47303,7 +47324,7 @@ class Camera {
47303
47324
  * cam.lookAt(10, 20, z);
47304
47325
  *
47305
47326
  * // Display the value of centerZ, rounded to the nearest integer.
47306
- * text(`centerZ: ${round(cam.centerZ)}`, 0, 55);
47327
+ * text(`centerZ: ${round(cam.centerZ)}`, 0, 45);
47307
47328
  * }
47308
47329
  * </code>
47309
47330
  * </div>
@@ -47361,7 +47382,7 @@ class Camera {
47361
47382
  * fill(0);
47362
47383
  *
47363
47384
  * // Display the value of upX, rounded to the nearest tenth.
47364
- * text(`upX: ${round(cam.upX, 1)}`, 0, 55);
47385
+ * text(`upX: ${round(cam.upX, 1)}`, 0, 45);
47365
47386
  * }
47366
47387
  * </code>
47367
47388
  * </div>
@@ -47414,7 +47435,7 @@ class Camera {
47414
47435
  * cam.camera(100, -400, 800, 0, 0, 0, x, 1, 0);
47415
47436
  *
47416
47437
  * // Display the value of upX, rounded to the nearest tenth.
47417
- * text(`upX: ${round(cam.upX, 1)}`, 0, 55);
47438
+ * text(`upX: ${round(cam.upX, 1)}`, 0, 45);
47418
47439
  * }
47419
47440
  * </code>
47420
47441
  * </div>
@@ -47472,7 +47493,7 @@ class Camera {
47472
47493
  * fill(0);
47473
47494
  *
47474
47495
  * // Display the value of upY, rounded to the nearest tenth.
47475
- * text(`upY: ${round(cam.upY, 1)}`, 0, 55);
47496
+ * text(`upY: ${round(cam.upY, 1)}`, 0, 45);
47476
47497
  * }
47477
47498
  * </code>
47478
47499
  * </div>
@@ -47525,7 +47546,7 @@ class Camera {
47525
47546
  * cam.camera(100, -400, 800, 0, 0, 0, 0, y, 0);
47526
47547
  *
47527
47548
  * // Display the value of upY, rounded to the nearest tenth.
47528
- * text(`upY: ${round(cam.upY, 1)}`, 0, 55);
47549
+ * text(`upY: ${round(cam.upY, 1)}`, 0, 45);
47529
47550
  * }
47530
47551
  * </code>
47531
47552
  * </div>
@@ -47583,7 +47604,7 @@ class Camera {
47583
47604
  * fill(0);
47584
47605
  *
47585
47606
  * // Display the value of upZ, rounded to the nearest tenth.
47586
- * text(`upZ: ${round(cam.upZ, 1)}`, 0, 55);
47607
+ * text(`upZ: ${round(cam.upZ, 1)}`, 0, 45);
47587
47608
  * }
47588
47609
  * </code>
47589
47610
  * </div>
@@ -47636,7 +47657,7 @@ class Camera {
47636
47657
  * cam.camera(100, -400, 800, 0, 0, 0, 0, 1, z);
47637
47658
  *
47638
47659
  * // Display the value of upZ, rounded to the nearest tenth.
47639
- * text(`upZ: ${round(cam.upZ, 1)}`, 0, 55);
47660
+ * text(`upZ: ${round(cam.upZ, 1)}`, 0, 45);
47640
47661
  * }
47641
47662
  * </code>
47642
47663
  * </div>
@@ -55471,11 +55492,10 @@ function rendererGL(p5, fn) {
55471
55492
  * }
55472
55493
  * </code>
55473
55494
  * </div>
55474
- * <br>
55475
- * Now with the antialias attribute set to true.
55476
- * <br>
55495
+ *
55477
55496
  * <div>
55478
55497
  * <code>
55498
+ * // Now with the antialias attribute set to true.
55479
55499
  * function setup() {
55480
55500
  * setAttributes('antialias', true);
55481
55501
  * createCanvas(100, 100, WEBGL);
@@ -58927,7 +58947,7 @@ function light(p5, fn){
58927
58947
  * three parameters, `v1`, `v2`, and `v3`, set the light’s color using the
58928
58948
  * current <a href="#/p5/colorMode">colorMode()</a>. The last parameter,
58929
58949
  * `direction` sets the light’s direction using a
58930
- * <a href="#/p5.Geometry">p5.Geometry</a> object. For example,
58950
+ * <a href="#/p5.Vector">p5.Vector</a> object. For example,
58931
58951
  * `directionalLight(255, 0, 0, lightDir)` creates a red `(255, 0, 0)` light
58932
58952
  * that shines in the direction the `lightDir` vector points.
58933
58953
  *
@@ -58942,7 +58962,7 @@ function light(p5, fn){
58942
58962
  * parameter, `color`, sets the light’s color using a
58943
58963
  * <a href="#/p5.Color">p5.Color</a> object or an array of color values. The
58944
58964
  * second parameter, `direction`, sets the light’s direction using a
58945
- * <a href="#/p5.Color">p5.Color</a> object. For example,
58965
+ * <a href="#/p5.Vector">p5.Vector</a> object. For example,
58946
58966
  * `directionalLight(myColor, lightDir)` creates a light that shines in the
58947
58967
  * direction the `lightDir` vector points with the color value of `myColor`.
58948
58968
  *
@@ -65842,6 +65862,7 @@ class Texture {
65842
65862
  // FramebufferTexture instances wrap raw WebGL textures already, which
65843
65863
  // don't need any extra updating, as they already live on the GPU
65844
65864
  if (this.isFramebufferTexture) {
65865
+ this.src.update();
65845
65866
  return false;
65846
65867
  }
65847
65868
 
@@ -66233,6 +66254,10 @@ class FramebufferTexture {
66233
66254
  return this.framebuffer.height * this.framebuffer.density;
66234
66255
  }
66235
66256
 
66257
+ update() {
66258
+ this.framebuffer._update(this.property);
66259
+ }
66260
+
66236
66261
  rawTexture() {
66237
66262
  return this.framebuffer[this.property];
66238
66263
  }
@@ -66245,6 +66270,8 @@ class Framebuffer {
66245
66270
 
66246
66271
  this._isClipApplied = false;
66247
66272
 
66273
+ this.dirty = { colorTexture: false, depthTexture: false };
66274
+
66248
66275
  this.pixels = [];
66249
66276
 
66250
66277
  this.format = settings.format || UNSIGNED_BYTE;
@@ -67284,6 +67311,49 @@ class Framebuffer {
67284
67311
  }
67285
67312
  }
67286
67313
 
67314
+ /**
67315
+ * Ensure all readable textures are up-to-date.
67316
+ * @private
67317
+ * @property {'colorTexutre'|'depthTexture'} property The property to update
67318
+ */
67319
+ _update(property) {
67320
+ if (this.dirty[property] && this.antialias) {
67321
+ const gl = this.gl;
67322
+ gl.bindFramebuffer(gl.READ_FRAMEBUFFER, this.aaFramebuffer);
67323
+ gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, this.framebuffer);
67324
+ const partsToCopy = {
67325
+ colorTexture: [gl.COLOR_BUFFER_BIT, this.colorP5Texture.glMagFilter],
67326
+ };
67327
+ if (this.useDepth) {
67328
+ partsToCopy.depthTexture = [
67329
+ gl.DEPTH_BUFFER_BIT,
67330
+ this.depthP5Texture.glMagFilter
67331
+ ];
67332
+ }
67333
+ const [flag, filter] = partsToCopy[property];
67334
+ gl.blitFramebuffer(
67335
+ 0,
67336
+ 0,
67337
+ this.width * this.density,
67338
+ this.height * this.density,
67339
+ 0,
67340
+ 0,
67341
+ this.width * this.density,
67342
+ this.height * this.density,
67343
+ flag,
67344
+ filter
67345
+ );
67346
+ this.dirty[property] = false;
67347
+
67348
+ const activeFbo = this.renderer.activeFramebuffer();
67349
+ if (activeFbo) {
67350
+ gl.bindFramebuffer(gl.FRAMEBUFFER, activeFbo._framebufferToBind());
67351
+ } else {
67352
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
67353
+ }
67354
+ }
67355
+ }
67356
+
67287
67357
  /**
67288
67358
  * Ensures that the framebuffer is ready to be drawn to
67289
67359
  *
@@ -67305,27 +67375,7 @@ class Framebuffer {
67305
67375
  */
67306
67376
  _beforeEnd() {
67307
67377
  if (this.antialias) {
67308
- const gl = this.gl;
67309
- gl.bindFramebuffer(gl.READ_FRAMEBUFFER, this.aaFramebuffer);
67310
- gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, this.framebuffer);
67311
- const partsToCopy = [
67312
- [gl.COLOR_BUFFER_BIT, this.colorP5Texture.glMagFilter]
67313
- ];
67314
- if (this.useDepth) {
67315
- partsToCopy.push(
67316
- [gl.DEPTH_BUFFER_BIT, this.depthP5Texture.glMagFilter]
67317
- );
67318
- }
67319
- for (const [flag, filter] of partsToCopy) {
67320
- gl.blitFramebuffer(
67321
- 0, 0,
67322
- this.width * this.density, this.height * this.density,
67323
- 0, 0,
67324
- this.width * this.density, this.height * this.density,
67325
- flag,
67326
- filter
67327
- );
67328
- }
67378
+ this.dirty = { colorTexture: true, depthTexture: true };
67329
67379
  }
67330
67380
  }
67331
67381
 
@@ -67505,6 +67555,7 @@ class Framebuffer {
67505
67555
  * </div>
67506
67556
  */
67507
67557
  loadPixels() {
67558
+ this._update('colorTexture');
67508
67559
  const gl = this.gl;
67509
67560
  const prevFramebuffer = this.renderer.activeFramebuffer();
67510
67561
  gl.bindFramebuffer(gl.FRAMEBUFFER, this.framebuffer);
@@ -67563,6 +67614,7 @@ class Framebuffer {
67563
67614
  * @return {Number[]} color of the pixel at `(x, y)` as an array of color values `[R, G, B, A]`.
67564
67615
  */
67565
67616
  get(x, y, w, h) {
67617
+ this._update('colorTexture');
67566
67618
  // p5._validateParameters('p5.Framebuffer.get', arguments);
67567
67619
  const colorFormat = this._glColorFormat();
67568
67620
  if (x === undefined && y === undefined) {
@@ -67729,6 +67781,7 @@ class Framebuffer {
67729
67781
  this.pixels
67730
67782
  );
67731
67783
  this.colorP5Texture.unbindTexture();
67784
+ this.dirty.colorTexture = false;
67732
67785
 
67733
67786
  const prevFramebuffer = this.renderer.activeFramebuffer();
67734
67787
  if (this.antialias) {
@@ -70537,10 +70590,14 @@ for (const k in constants) {
70537
70590
  * ```
70538
70591
  *
70539
70592
  * Code placed in `setup()` will run once before code placed in
70540
- * <a href="#/p5/draw">draw()</a> begins looping. If the
70541
- * <a href="#/p5/preload">preload()</a> is declared, then `setup()` will
70542
- * run immediately after <a href="#/p5/preload">preload()</a> finishes
70543
- *
70593
+ * <a href="#/p5/draw">draw()</a> begins looping.
70594
+ * If `setup()` is declared `async` (e.g. `async function setup()`),
70595
+ * execution pauses at each `await` until its promise resolves.
70596
+ * For example, `font = await loadFont(...)` waits for the font asset
70597
+ * to load because `loadFont()` function returns a promise, and the await
70598
+ * keyword means the program will wait for the promise to resolve.
70599
+ * This ensures that all assets are fully loaded before the sketch continues.
70600
+
70544
70601
  *
70545
70602
  * loading assets.
70546
70603
  *
@@ -70612,7 +70669,6 @@ for (const k in constants) {
70612
70669
  * </code>
70613
70670
  * </div>
70614
70671
  */
70615
-
70616
70672
  /**
70617
70673
  * A function that's called repeatedly while the sketch runs.
70618
70674
  *
@@ -70840,6 +70896,11 @@ function describe(p5, fn){
70840
70896
  *
70841
70897
  * <div>
70842
70898
  * <code>
70899
+ *
70900
+ * function setup(){
70901
+ * createCanvas(100, 100);
70902
+ * };
70903
+ *
70843
70904
  * function draw() {
70844
70905
  * background(200);
70845
70906
  *
@@ -70861,6 +70922,11 @@ function describe(p5, fn){
70861
70922
  *
70862
70923
  * <div>
70863
70924
  * <code>
70925
+ *
70926
+ * function setup(){
70927
+ * createCanvas(100, 100);
70928
+ * }
70929
+ *
70864
70930
  * function draw() {
70865
70931
  * background(200);
70866
70932
  *
@@ -71633,6 +71699,11 @@ function outputs(p5, fn){
71633
71699
  *
71634
71700
  * <div>
71635
71701
  * <code>
71702
+ *
71703
+ * function setup(){
71704
+ * createCanvas(100, 100);
71705
+ * }
71706
+ *
71636
71707
  * function draw() {
71637
71708
  * // Add the text description.
71638
71709
  * textOutput();
@@ -71653,6 +71724,11 @@ function outputs(p5, fn){
71653
71724
  *
71654
71725
  * <div>
71655
71726
  * <code>
71727
+ *
71728
+ * function setup(){
71729
+ * createCanvas(100, 100);
71730
+ * }
71731
+ *
71656
71732
  * function draw() {
71657
71733
  * // Add the text description and
71658
71734
  * // display it for debugging.
@@ -71767,6 +71843,11 @@ function outputs(p5, fn){
71767
71843
  *
71768
71844
  * <div>
71769
71845
  * <code>
71846
+ *
71847
+ * function setup() {
71848
+ * createCanvas(100, 100);
71849
+ * }
71850
+ *
71770
71851
  * function draw() {
71771
71852
  * // Add the grid description.
71772
71853
  * gridOutput();
@@ -71787,6 +71868,11 @@ function outputs(p5, fn){
71787
71868
  *
71788
71869
  * <div>
71789
71870
  * <code>
71871
+ *
71872
+ * function setup(){
71873
+ * createCanvas(100, 100);
71874
+ * }
71875
+ *
71790
71876
  * function draw() {
71791
71877
  * // Add the grid description and
71792
71878
  * // display it for debugging.
@@ -71807,6 +71893,7 @@ function outputs(p5, fn){
71807
71893
  * </div>
71808
71894
  */
71809
71895
 
71896
+
71810
71897
  fn.gridOutput = function(display) {
71811
71898
  // p5._validateParameters('gridOutput', arguments);
71812
71899
  //if gridOutput is already true
@@ -82764,7 +82851,7 @@ var p5$1 = {
82764
82851
  image: {
82765
82852
  overloads: [
82766
82853
  [
82767
- "p5.Image|p5.Element|p5.Texture|p5.Framebuffer|p5.FramebufferTexture",
82854
+ "p5.Image|p5.Element|p5.Texture|p5.Framebuffer|p5.FramebufferTexture|p5.Renderer|p5.Graphics",
82768
82855
  "Number",
82769
82856
  "Number",
82770
82857
  "Number?",
@@ -83262,14 +83349,7 @@ var p5$1 = {
83262
83349
  createVector: {
83263
83350
  overloads: [
83264
83351
  [
83265
- null
83266
- ]
83267
- ]
83268
- },
83269
- createMatrix: {
83270
- overloads: [
83271
- [
83272
- "Number[]"
83352
+ "...Number[]"
83273
83353
  ]
83274
83354
  ]
83275
83355
  },
@@ -83695,14 +83775,23 @@ var p5$1 = {
83695
83775
  bezierOrder: {
83696
83776
  overloads: [
83697
83777
  [
83778
+ "Number"
83698
83779
  ],
83699
83780
  [
83700
- "Number"
83701
83781
  ]
83702
83782
  ]
83703
83783
  },
83704
83784
  splineVertex: {
83705
83785
  overloads: [
83786
+ [
83787
+ "Number",
83788
+ "Number"
83789
+ ],
83790
+ [
83791
+ "Number",
83792
+ "Number",
83793
+ "Number?"
83794
+ ],
83706
83795
  [
83707
83796
  "Number",
83708
83797
  "Number",
@@ -83720,21 +83809,21 @@ var p5$1 = {
83720
83809
  },
83721
83810
  splineProperty: {
83722
83811
  overloads: [
83723
- [
83724
- "String"
83725
- ],
83726
83812
  [
83727
83813
  "String",
83728
83814
  null
83815
+ ],
83816
+ [
83817
+ "String"
83729
83818
  ]
83730
83819
  ]
83731
83820
  },
83732
83821
  splineProperties: {
83733
83822
  overloads: [
83734
83823
  [
83824
+ "Object"
83735
83825
  ],
83736
83826
  [
83737
- "Object"
83738
83827
  ]
83739
83828
  ]
83740
83829
  },
@@ -83796,19 +83885,6 @@ var p5$1 = {
83796
83885
  ]
83797
83886
  ]
83798
83887
  },
83799
- curveVertex: {
83800
- overloads: [
83801
- [
83802
- "Number",
83803
- "Number"
83804
- ],
83805
- [
83806
- "Number",
83807
- "Number",
83808
- "Number?"
83809
- ]
83810
- ]
83811
- },
83812
83888
  endShape: {
83813
83889
  overloads: [
83814
83890
  [
@@ -83843,7 +83919,6 @@ var p5$1 = {
83843
83919
  "String",
83844
83920
  "String?",
83845
83921
  "Object?",
83846
- "String|String[]?",
83847
83922
  "Function?",
83848
83923
  "Function?"
83849
83924
  ],
@@ -84605,56 +84680,15 @@ var p5$1 = {
84605
84680
  ],
84606
84681
  [
84607
84682
  "String|Request",
84608
- "Object?",
84609
- "String?",
84610
- "function(p5.Geometry)?",
84611
- "function(Event)?",
84612
- "Boolean?",
84613
- "Boolean?",
84614
- "Boolean?"
84615
- ]
84616
- ]
84617
- },
84618
- parseObj: {
84619
- overloads: [
84620
- [
84621
- ]
84622
- ]
84623
- },
84624
- parseSTL: {
84625
- overloads: [
84626
- [
84627
- ]
84628
- ]
84629
- },
84630
- isBinary: {
84631
- overloads: [
84632
- [
84633
- ]
84634
- ]
84635
- },
84636
- matchDataViewAt: {
84637
- overloads: [
84638
- [
84639
- ]
84640
- ]
84641
- },
84642
- parseBinarySTL: {
84643
- overloads: [
84644
- [
84645
- ]
84646
- ]
84647
- },
84648
- parseASCIISTL: {
84649
- overloads: [
84650
- [
84683
+ "Object?"
84651
84684
  ]
84652
84685
  ]
84653
84686
  },
84654
84687
  model: {
84655
84688
  overloads: [
84656
84689
  [
84657
- "p5.Geometry"
84690
+ "p5.Geometry",
84691
+ "Number?"
84658
84692
  ]
84659
84693
  ]
84660
84694
  },
@@ -84676,12 +84710,7 @@ var p5$1 = {
84676
84710
  [
84677
84711
  "String",
84678
84712
  "String?",
84679
- "Object?",
84680
- "function(p5.Geometry)?",
84681
- "function(Event)?",
84682
- "boolean?",
84683
- "boolean?",
84684
- "boolean?"
84713
+ "Object?"
84685
84714
  ]
84686
84715
  ]
84687
84716
  },
@@ -86468,9 +86497,7 @@ var dataDoc = {
86468
86497
  "Number",
86469
86498
  "Number",
86470
86499
  "Number",
86471
- "Object?",
86472
- "Number?",
86473
- "Number?"
86500
+ "Object?"
86474
86501
  ]
86475
86502
  ]
86476
86503
  }
@@ -86917,9 +86944,14 @@ function validateParams(p5, fn, lifecycles) {
86917
86944
  const isOptional = param?.endsWith('?');
86918
86945
  param = param?.replace(/\?$/, '');
86919
86946
 
86920
- let schema = generateTypeSchema(param);
86947
+ const isRest = param?.startsWith('...') && param?.endsWith('[]');
86948
+ param = param?.replace(/^\.\.\.(.+)\[\]$/, '$1');
86921
86949
 
86922
- return isOptional ? schema.optional() : schema;
86950
+ let schema = generateTypeSchema(param);
86951
+ if (isOptional) {
86952
+ schema = schema.optional();
86953
+ }
86954
+ return { schema, rest: isRest };
86923
86955
  };
86924
86956
 
86925
86957
  // Note that in Zod, `optional()` only checks for undefined, not the absence
@@ -86953,14 +86985,22 @@ function validateParams(p5, fn, lifecycles) {
86953
86985
  const overloadSchemas = overloads.flatMap(overload => {
86954
86986
  const combinations = generateOverloadCombinations(overload);
86955
86987
 
86956
- return combinations.map(combo =>
86957
- tupleType(
86958
- combo
86959
- .map(p => generateParamSchema(p))
86960
- // For now, ignore schemas that cannot be mapped to a defined type
86961
- .filter(schema => schema !== undefined)
86962
- )
86963
- );
86988
+ return combinations.map(combo => {
86989
+ const params = combo
86990
+ .map(p => generateParamSchema(p))
86991
+ .filter(s => s.schema !== undefined);
86992
+
86993
+ let rest;
86994
+ if (params.at(-1)?.rest) {
86995
+ rest = params.pop();
86996
+ }
86997
+
86998
+ let combined = tupleType(params.map(s => s.schema));
86999
+ if (rest) {
87000
+ combined = combined.rest(rest.schema);
87001
+ }
87002
+ return combined;
87003
+ });
86964
87004
  });
86965
87005
 
86966
87006
  return overloadSchemas.length === 1
@@ -87195,7 +87235,7 @@ function validateParams(p5, fn, lifecycles) {
87195
87235
  // theoretically allowed to stay undefined and valid, it is likely that the
87196
87236
  // user intended to call the function with non-undefined arguments. Skip
87197
87237
  // regular workflow and return a friendly error message right away.
87198
- if (Array.isArray(args) && args.every(arg => arg === undefined)) {
87238
+ if (Array.isArray(args) && args.length > 0 && args.every(arg => arg === undefined)) {
87199
87239
  const undefinedErrorMessage = `🌸 p5.js says: All arguments for ${func}() are undefined. There is likely an error in the code.`;
87200
87240
 
87201
87241
  return {
@@ -94818,7 +94858,7 @@ function dom$1(p5, fn){
94818
94858
  * let slider;
94819
94859
  *
94820
94860
  * function setup() {
94821
- * createCanvas(100, 100);
94861
+ * createCanvas(200, 200);
94822
94862
  *
94823
94863
  * // Create a paragraph element and place
94824
94864
  * // it at the top of the canvas.
@@ -95059,10 +95099,10 @@ function dom$1(p5, fn){
95059
95099
  * background(200);
95060
95100
  *
95061
95101
  * let img = createImg(
95062
- * 'https://p5js.org/assets/img/asterisk-01.png',
95063
- * 'The p5.js magenta asterisk.'
95102
+ * '/assets/cat.jpg',
95103
+ * 'image of a cat'
95064
95104
  * );
95065
- * img.position(0, -10);
95105
+ * img.position(0, 10);
95066
95106
  *
95067
95107
  * describe('A gray square with a magenta asterisk in its center.');
95068
95108
  * }
@@ -95411,7 +95451,7 @@ function dom$1(p5, fn){
95411
95451
  *
95412
95452
  * // Create a checkbox and place it beneath the canvas.
95413
95453
  * checkbox = createCheckbox();
95414
- * checkbox.position(0, 100);
95454
+ * checkbox.position(0, 70);
95415
95455
  *
95416
95456
  * describe('A black square with a checkbox beneath it. The square turns white when the box is checked.');
95417
95457
  * }
@@ -95437,7 +95477,7 @@ function dom$1(p5, fn){
95437
95477
  * // Create a checkbox and place it beneath the canvas.
95438
95478
  * // Label the checkbox "white".
95439
95479
  * checkbox = createCheckbox(' white');
95440
- * checkbox.position(0, 100);
95480
+ * checkbox.position(0, 70);
95441
95481
  *
95442
95482
  * describe('A black square with a checkbox labeled "white" beneath it. The square turns white when the box is checked.');
95443
95483
  * }
@@ -95463,7 +95503,7 @@ function dom$1(p5, fn){
95463
95503
  * // Create a checkbox and place it beneath the canvas.
95464
95504
  * // Label the checkbox "white" and set its value to true.
95465
95505
  * checkbox = createCheckbox(' white', true);
95466
- * checkbox.position(0, 100);
95506
+ * checkbox.position(0, 70);
95467
95507
  *
95468
95508
  * describe('A white square with a checkbox labeled "white" beneath it. The square turns black when the box is unchecked.');
95469
95509
  * }
@@ -96342,7 +96382,7 @@ function dom$1(p5, fn){
96342
96382
  * let img;
96343
96383
  *
96344
96384
  * function setup() {
96345
- * createCanvas(100, 100);
96385
+ * createCanvas(200, 200);
96346
96386
  *
96347
96387
  * // Create a file input and place it beneath
96348
96388
  * // the canvas.
@@ -96596,18 +96636,18 @@ function acceleration(p5, fn){
96596
96636
  * @example
96597
96637
  * <div>
96598
96638
  * <code>
96639
+ * let rotationX = 0; // Angle in degrees
96640
+ *
96599
96641
  * function setup() {
96600
- * createCanvas(100, 100, WEBGL);
96642
+ * createCanvas(200, 200, WEBGL); // Create 3D canvas
96601
96643
  * }
96602
96644
  *
96603
96645
  * function draw() {
96604
- * background(200);
96605
- * //rotateZ(radians(rotationZ));
96606
- * rotateX(radians(rotationX));
96607
- * //rotateY(radians(rotationY));
96608
- * box(200, 200, 200);
96609
- * describe(`red horizontal line right, green vertical line bottom.
96610
- * black background.`);
96646
+ * background(220); // Set light gray background
96647
+ * rotateX(radians(rotationX)); // Rotate around X-axis
96648
+ * normalMaterial(); // Apply simple shaded material
96649
+ * box(60); // Draw 3D cube (60 units wide)
96650
+ * rotationX = (rotationX + 2) % 360; // Increment rotation (2° per frame)
96611
96651
  * }
96612
96652
  * </code>
96613
96653
  * </div>
@@ -96629,18 +96669,18 @@ function acceleration(p5, fn){
96629
96669
  * @example
96630
96670
  * <div>
96631
96671
  * <code>
96672
+ * let rotationY = 0; // Angle in degrees
96673
+ *
96632
96674
  * function setup() {
96633
- * createCanvas(100, 100, WEBGL);
96675
+ * createCanvas(200, 200, WEBGL); // Create 3D canvas
96634
96676
  * }
96635
96677
  *
96636
96678
  * function draw() {
96637
- * background(200);
96638
- * //rotateZ(radians(rotationZ));
96639
- * //rotateX(radians(rotationX));
96640
- * rotateY(radians(rotationY));
96641
- * box(200, 200, 200);
96642
- * describe(`red horizontal line right, green vertical line bottom.
96643
- * black background.`);
96679
+ * background(220); // Set light gray background
96680
+ * rotateY(radians(rotationY)); // Rotate around Y-axis (vertical)
96681
+ * normalMaterial(); // Apply simple shaded material
96682
+ * box(60); // Draw 3D cube (60 units wide)
96683
+ * rotationY = (rotationY + 2) % 360; // Increment rotation (2° per frame)
96644
96684
  * }
96645
96685
  * </code>
96646
96686
  * </div>
@@ -96663,18 +96703,18 @@ function acceleration(p5, fn){
96663
96703
  * @example
96664
96704
  * <div>
96665
96705
  * <code>
96706
+ * let rotationZ = 0; // Angle in degrees
96707
+ *
96666
96708
  * function setup() {
96667
- * createCanvas(100, 100, WEBGL);
96709
+ * createCanvas(200, 200, WEBGL); // Create 3D canvas
96668
96710
  * }
96669
96711
  *
96670
96712
  * function draw() {
96671
- * background(200);
96672
- * rotateZ(radians(rotationZ));
96673
- * //rotateX(radians(rotationX));
96674
- * //rotateY(radians(rotationY));
96675
- * box(200, 200, 200);
96676
- * describe(`red horizontal line right, green vertical line bottom.
96677
- * black background.`);
96713
+ * background(220);
96714
+ * rotateZ(radians(rotationZ)); // Rotate around Z-axis
96715
+ * normalMaterial(); // Apply simple shaded material
96716
+ * box(60); // Draw 3D cube
96717
+ * rotationZ = (rotationZ + 2) % 360; // Increment rotation angle
96678
96718
  * }
96679
96719
  * </code>
96680
96720
  * </div>
@@ -97863,7 +97903,6 @@ function keyboard(p5, fn){
97863
97903
 
97864
97904
  };
97865
97905
 
97866
-
97867
97906
  /**
97868
97907
  * A function that's called once when keys with printable characters are pressed.
97869
97908
  *
@@ -97995,7 +98034,7 @@ function keyboard(p5, fn){
97995
98034
  * </div>
97996
98035
  */
97997
98036
  fn._onkeypress = function(e) {
97998
- if (e.which === this._lastKeyCodeTyped) {
98037
+ if (e.which === this._lastKeyCodeTyped && e.repeat) {
97999
98038
  // prevent multiple firings
98000
98039
  return;
98001
98040
  }
@@ -98033,10 +98072,16 @@ function keyboard(p5, fn){
98033
98072
  * }
98034
98073
  * ```
98035
98074
  *
98036
- * `keyIsDown()` can check for key presses using
98037
- * <a href="#/p5/keyCode">keyCode</a> values, as in `keyIsDown(37)` or
98038
- * `keyIsDown(LEFT_ARROW)`. Key codes can be found on websites such as
98039
- * <a href="https://keycode.info" target="_blank">keycode.info</a>.
98075
+ * `keyIsDown()` can check for key presses using strings based on
98076
+ * <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key" target="_blank">KeyboardEvent.key</a>
98077
+ * or <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code" target="_blank">KeyboardEvent.code</a> values,
98078
+ * such as `keyIsDown('x')` or `keyIsDown('ArrowLeft')`.
98079
+ *
98080
+ * Note: In p5.js 2.0 and newer, numeric keycodes (such as 88 for 'X') are no longer supported.
98081
+ * This is a breaking change from previous versions.
98082
+ *
98083
+ * You can still use the p5 constants like `LEFT_ARROW` which now map to string values
98084
+ * internally rather than numeric codes.
98040
98085
  *
98041
98086
  * @method keyIsDown
98042
98087
  * @param {Number|String} code key to check.
@@ -101905,8 +101950,8 @@ class TableRow {
101905
101950
  * let table;
101906
101951
  *
101907
101952
  * async function setup() {
101908
- * // Create a 200x100 canvas and set a white background
101909
- * createCanvas(200, 100);
101953
+ * // Create a 300x100 canvas and set a white background
101954
+ * createCanvas(300, 100);
101910
101955
  * background(255);
101911
101956
  *
101912
101957
  * // Load the CSV file with a header row
@@ -104048,7 +104093,7 @@ function math$1(p5, fn) {
104048
104093
  * <a href="#/p5.Vector">p5.Vector</a> class.
104049
104094
  *
104050
104095
  * @method createVector
104051
- * @param {...Number} components Components of the vector.
104096
+ * @param {...Number} x Zero or more numbers, representing each component of the vector.
104052
104097
  * @return {p5.Vector} new <a href="#/p5.Vector">p5.Vector</a> object.
104053
104098
  *
104054
104099
  * @example
@@ -108216,6 +108261,7 @@ function loading$1(p5, fn){
108216
108261
  * @method model
108217
108262
  * @param {p5.Geometry} model 3D shape to be drawn.
108218
108263
  *
108264
+ * @param {Number} [count=1] number of instances to draw.
108219
108265
  * @example
108220
108266
  * <div>
108221
108267
  * <code>
@@ -109746,7 +109792,7 @@ function textCore(p5, fn) {
109746
109792
  * createCanvas(300, 300);
109747
109793
  * background(220);
109748
109794
  *
109749
- * textSize(48);
109795
+ * textSize(35);
109750
109796
  * textAlign(LEFT, BASELINE);
109751
109797
  * textFont('Georgia');
109752
109798
  *
@@ -118711,7 +118757,6 @@ const invalidFontError = 'Sorry, only TTF, OTF and WOFF files are supported.'; /
118711
118757
  const fontFaceVariations = ['weight', 'stretch', 'style'];
118712
118758
 
118713
118759
 
118714
- let nextId = 0;
118715
118760
  class Font {
118716
118761
  constructor(p, fontFace, name, path, data) {
118717
118762
  if (!(fontFace instanceof FontFace)) {
@@ -118722,7 +118767,6 @@ class Font {
118722
118767
  this.path = path;
118723
118768
  this.data = data;
118724
118769
  this.face = fontFace;
118725
- this.id = nextId++;
118726
118770
  }
118727
118771
 
118728
118772
  /**
@@ -120156,24 +120200,7 @@ if (typeof p5 !== 'undefined') {
120156
120200
  function text(p5, fn) {
120157
120201
  RendererGL.prototype.maxCachedGlyphs = function() {
120158
120202
  // TODO: use more than vibes to find a good value for this
120159
- return 200
120160
- };
120161
-
120162
- RendererGL.prototype.freeGlyphInfo = function(gi) {
120163
- const datas = [
120164
- gi.strokeImageInfo.imageData,
120165
- gi.rowInfo.cellImageInfo.imageData,
120166
- gi.rowInfo.dimImageInfo.imageData,
120167
- gi.colInfo.cellImageInfo.imageData,
120168
- gi.colInfo.dimImageInfo.imageData,
120169
- ];
120170
- for (const data of datas) {
120171
- const tex = this.textures.get(data);
120172
- if (tex) {
120173
- tex.remove();
120174
- this.textures.delete(data);
120175
- }
120176
- }
120203
+ return 200;
120177
120204
  };
120178
120205
 
120179
120206
  Font.prototype._getFontInfo = function(axs) {
@@ -120941,7 +120968,7 @@ function text(p5, fn) {
120941
120968
  sh.setUniform("uMaterialColor", curFillColor);
120942
120969
  gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
120943
120970
 
120944
- this.fontCache = this.fontCache || new Map();
120971
+ this.glyphDataCache = this.glyphDataCache || new Set();
120945
120972
 
120946
120973
  try {
120947
120974
  // fetch the glyphs in the line of text
@@ -120950,20 +120977,35 @@ function text(p5, fn) {
120950
120977
  for (const glyph of glyphs) {
120951
120978
  const gi = fontInfo.getGlyphInfo(glyph);
120952
120979
  if (gi.uGlyphRect) {
120980
+ const rowInfo = gi.rowInfo;
120981
+ const colInfo = gi.colInfo;
120953
120982
 
120954
- const cacheKey = JSON.stringify({ font: font.id, axs, glyph: glyph.shape.g });
120955
- // Bump this font to the end of the cache list by deleting and re-adding it
120956
- this.fontCache.delete(cacheKey);
120957
- this.fontCache.set(cacheKey, gi);
120958
- if (this.fontCache.size > this.maxCachedGlyphs()) {
120959
- const keyToRemove = this.fontCache.keys().next().value;
120960
- const val = this.fontCache.get(keyToRemove);
120961
- this.fontCache.delete(keyToRemove);
120962
- this.freeGlyphInfo(val);
120983
+ // Bump the resources for this glyph to the end of the cache list by deleting and re-adding
120984
+ const glyphResources = [
120985
+ gi.strokeImageInfo.imageData,
120986
+ rowInfo.cellImageInfo.imageData,
120987
+ rowInfo.dimImageInfo.imageData,
120988
+ colInfo.cellImageInfo.imageData,
120989
+ colInfo.dimImageInfo.imageData
120990
+ ];
120991
+ for (const resource of glyphResources) {
120992
+ this.glyphDataCache.delete(resource);
120993
+ this.glyphDataCache.add(resource);
120994
+ }
120995
+
120996
+ // If we have too many glyph textures, remove the least recently used
120997
+ // ones from GPU memory. The data still exists on the CPU and will be
120998
+ // re-uploaded if it gets actively used again.
120999
+ while (this.glyphDataCache.size > this.maxCachedGlyphs()) {
121000
+ const data = this.glyphDataCache.values().next().value;
121001
+ this.glyphDataCache.delete(data);
121002
+ const tex = this.textures.get(data);
121003
+ if (tex) {
121004
+ tex.remove();
121005
+ this.textures.delete(data);
121006
+ }
120963
121007
  }
120964
121008
 
120965
- const rowInfo = gi.rowInfo;
120966
- const colInfo = gi.colInfo;
120967
121009
  sh.setUniform("uSamplerStrokes", gi.strokeImageInfo.imageData);
120968
121010
  sh.setUniform("uSamplerRowStrokes", rowInfo.cellImageInfo.imageData);
120969
121011
  sh.setUniform("uSamplerRows", rowInfo.dimImageInfo.imageData);