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.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
  var p5 = (function () {
3
3
  'use strict';
4
4
 
@@ -15,17 +15,33 @@ var p5 = (function () {
15
15
  * @property {String} VERSION
16
16
  * @final
17
17
  */
18
- const VERSION = '2.0.1';
18
+ const VERSION = '2.0.3';
19
19
 
20
20
  // GRAPHICS RENDERER
21
21
  /**
22
- * The default, two-dimensional renderer.
23
- * @typedef {unique symbol} P2D
22
+ * The default, two-dimensional renderer in p5.js.
23
+ *
24
+ * Use this when calling <a href="#/p5/createCanvas"> (for example,
25
+ * `createCanvas(400, 400, P2D)`) to specify a 2D context.
26
+ *
27
+ * @typedef {'p2d'} P2D
24
28
  * @property {P2D} P2D
25
29
  * @final
26
30
  */
27
31
  const P2D = 'p2d';
28
32
 
33
+ /**
34
+ * A high-dynamic-range (HDR) variant of the default, two-dimensional renderer.
35
+ *
36
+ * When available, this mode can allow for extended color ranges and more
37
+ * dynamic color representation. Use it similarly to `P2D`:
38
+ * `createCanvas(400, 400, P2DHDR)`.
39
+ *
40
+ * @typedef {'p2d-hdr'} P2DHDR
41
+ * @property {P2DHDR} P2DHDR
42
+ * @final
43
+ */
44
+
29
45
  const P2DHDR = 'p2d-hdr';
30
46
 
31
47
  /**
@@ -8013,8 +8029,8 @@ var p5 = (function () {
8013
8029
  * @method print
8014
8030
  * @param {Any} contents content to print to the console.
8015
8031
  * @example
8016
- * <div>
8017
- * <code class="norender">
8032
+ * <div class="norender">
8033
+ * <code>
8018
8034
  * function setup() {
8019
8035
  * // Prints "hello, world" to the console.
8020
8036
  * print('hello, world');
@@ -8022,8 +8038,8 @@ var p5 = (function () {
8022
8038
  * </code>
8023
8039
  * </div>
8024
8040
  *
8025
- * <div>
8026
- * <code class="norender">
8041
+ * <div class="norender">
8042
+ * <code>
8027
8043
  * function setup() {
8028
8044
  * let name = 'ada';
8029
8045
  * // Prints "hello, ada" to the console.
@@ -8496,6 +8512,7 @@ var p5 = (function () {
8496
8512
  * - `WEBGL2` whose value is `'webgl2'`,
8497
8513
  * - `WEBGL` whose value is `'webgl'`, or
8498
8514
  * - `P2D` whose value is `'p2d'`. This is the default for 2D sketches.
8515
+ * - `P2DHDR` whose value is `'p2d-hdr'` (used for HDR 2D sketches, if available).
8499
8516
  *
8500
8517
  * See <a href="#/p5/setAttributes">setAttributes()</a> for ways to set the
8501
8518
  * WebGL version.
@@ -13843,7 +13860,7 @@ var p5 = (function () {
13843
13860
  * }
13844
13861
  * </code>
13845
13862
  * </div>
13846
- **/
13863
+ */
13847
13864
  setGreen(new_green, max=[0, 1]) {
13848
13865
  if(!Array.isArray(max)){
13849
13866
  max = [0, max];
@@ -13954,7 +13971,7 @@ var p5 = (function () {
13954
13971
  * }
13955
13972
  * </code>
13956
13973
  * </div>
13957
- **/
13974
+ */
13958
13975
  setAlpha(new_alpha, max=[0, 1]) {
13959
13976
  if(!Array.isArray(max)){
13960
13977
  max = [0, max];
@@ -22661,7 +22678,7 @@ var p5 = (function () {
22661
22678
  *
22662
22679
  * async function setup() {
22663
22680
  * // Load the image.
22664
- * gif = await loadImage('assets/arnott-wallace-wink-loop-forever.gif');
22681
+ * gif = await loadImage('assets/arnott-wallace-eye-loop-forever.gif');
22665
22682
  *
22666
22683
  * createCanvas(100, 100);
22667
22684
  *
@@ -22701,7 +22718,7 @@ var p5 = (function () {
22701
22718
  *
22702
22719
  * async function setup() {
22703
22720
  * // Load the image.
22704
- * gif = await loadImage('assets/arnott-wallace-wink-loop-forever.gif');
22721
+ * gif = await loadImage('assets/arnott-wallace-eye-loop-forever.gif');
22705
22722
  *
22706
22723
  * createCanvas(100, 100);
22707
22724
  *
@@ -22757,7 +22774,7 @@ var p5 = (function () {
22757
22774
  *
22758
22775
  * async function setup() {
22759
22776
  * // Load the image.
22760
- * gif = await loadImage('assets/arnott-wallace-wink-loop-forever.gif');
22777
+ * gif = await loadImage('assets/arnott-wallace-eye-loop-forever.gif');
22761
22778
  *
22762
22779
  * createCanvas(100, 100);
22763
22780
  *
@@ -37619,7 +37636,7 @@ var p5 = (function () {
37619
37636
  * }
37620
37637
  *
37621
37638
  * function mousePressed() {
37622
- * httpPost(url, 'json', postData, function(result) {
37639
+ * httpPost(url, postData, 'json', function(result) {
37623
37640
  * strokeWeight(2);
37624
37641
  * text(result.body, mouseX, mouseY);
37625
37642
  * });
@@ -37639,8 +37656,8 @@ var p5 = (function () {
37639
37656
  * function mousePressed() {
37640
37657
  * httpPost(
37641
37658
  * url,
37642
- * 'json',
37643
37659
  * postData,
37660
+ * 'json',
37644
37661
  * function(result) {
37645
37662
  * // ... won't be called
37646
37663
  * },
@@ -37758,20 +37775,29 @@ var p5 = (function () {
37758
37775
  * let eqFeatureIndex = 0;
37759
37776
  *
37760
37777
  * function setup() {
37778
+ * createCanvas(100,100);
37779
+ *
37761
37780
  * let url = 'https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson';
37781
+ *
37782
+ * const req = new Request(url, {
37783
+ * method: 'GET',
37784
+ * headers: {authorization: 'Bearer secretKey'}
37785
+ * });
37786
+ * // httpDo(path, method, datatype, success, error)
37787
+ *
37762
37788
  * httpDo(
37763
- * url,
37764
- * {
37765
- * method: 'GET',
37766
- * // Other Request options, like special headers for apis
37767
- * headers: { authorization: 'Bearer secretKey' }
37789
+ * req,
37790
+ * 'GET',
37791
+ * 'json',
37792
+ * res => {
37793
+ * earthquakes = res;
37768
37794
  * },
37769
- * function(res) {
37770
- * earthquakes = res;
37771
- * }
37772
- * );
37795
+ * err => {
37796
+ * console.error('Error loading data:', err);
37797
+ * }
37798
+ * );
37773
37799
  * }
37774
- *
37800
+ *
37775
37801
  * function draw() {
37776
37802
  * // wait until the data is loaded
37777
37803
  * if (!earthquakes || !earthquakes.features[eqFeatureIndex]) {
@@ -39767,7 +39793,7 @@ var p5 = (function () {
39767
39793
  * are set to `CENTER`.
39768
39794
  *
39769
39795
  * @method image
39770
- * @param {p5.Image|p5.Element|p5.Texture|p5.Framebuffer|p5.FramebufferTexture} img image to display.
39796
+ * @param {p5.Image|p5.Element|p5.Texture|p5.Framebuffer|p5.FramebufferTexture|p5.Renderer|p5.Graphics} img image to display.
39771
39797
  * @param {Number} x x-coordinate of the top-left corner of the image.
39772
39798
  * @param {Number} y y-coordinate of the top-left corner of the image.
39773
39799
  * @param {Number} [width] width to draw the image.
@@ -40334,6 +40360,7 @@ var p5 = (function () {
40334
40360
  * <code>
40335
40361
  * function setup() {
40336
40362
  * createCanvas(100, 100);
40363
+ * background(128);
40337
40364
  *
40338
40365
  * // Load the pixels array.
40339
40366
  * loadPixels();
@@ -46689,7 +46716,7 @@ var p5 = (function () {
46689
46716
  * fill(0);
46690
46717
  *
46691
46718
  * // Display the value of eyeX, rounded to the nearest integer.
46692
- * text(`eyeX: ${round(cam.eyeX)}`, 0, 55);
46719
+ * text(`eyeX: ${round(cam.eyeX)}`, 0, 45);
46693
46720
  * }
46694
46721
  * </code>
46695
46722
  * </div>
@@ -46707,9 +46734,6 @@ var p5 = (function () {
46707
46734
  * // Create a p5.Camera object.
46708
46735
  * cam = createCamera();
46709
46736
  *
46710
- * // Set the camera
46711
- * setCamera(cam);
46712
- *
46713
46737
  * // Place the camera at the top-center.
46714
46738
  * cam.setPosition(0, -400, 800);
46715
46739
  *
@@ -46743,7 +46767,7 @@ var p5 = (function () {
46743
46767
  * cam.setPosition(x, -400, 800);
46744
46768
  *
46745
46769
  * // Display the value of eyeX, rounded to the nearest integer.
46746
- * text(`eyeX: ${round(cam.eyeX)}`, 0, 55);
46770
+ * text(`eyeX: ${round(cam.eyeX)}`, 0, 45);
46747
46771
  * }
46748
46772
  * </code>
46749
46773
  * </div>
@@ -46801,7 +46825,7 @@ var p5 = (function () {
46801
46825
  * fill(0);
46802
46826
  *
46803
46827
  * // Display the value of eyeY, rounded to the nearest integer.
46804
- * text(`eyeY: ${round(cam.eyeY)}`, 0, 55);
46828
+ * text(`eyeY: ${round(cam.eyeY)}`, 0, 45);
46805
46829
  * }
46806
46830
  * </code>
46807
46831
  * </div>
@@ -46855,7 +46879,7 @@ var p5 = (function () {
46855
46879
  * cam.setPosition(0, y, 800);
46856
46880
  *
46857
46881
  * // Display the value of eyeY, rounded to the nearest integer.
46858
- * text(`eyeY: ${round(cam.eyeY)}`, 0, 55);
46882
+ * text(`eyeY: ${round(cam.eyeY)}`, 0, 45);
46859
46883
  * }
46860
46884
  * </code>
46861
46885
  * </div>
@@ -46913,7 +46937,7 @@ var p5 = (function () {
46913
46937
  * fill(0);
46914
46938
  *
46915
46939
  * // Display the value of eyeZ, rounded to the nearest integer.
46916
- * text(`eyeZ: ${round(cam.eyeZ)}`, 0, 55);
46940
+ * text(`eyeZ: ${round(cam.eyeZ)}`, 0, 45);
46917
46941
  * }
46918
46942
  * </code>
46919
46943
  * </div>
@@ -46967,7 +46991,7 @@ var p5 = (function () {
46967
46991
  * cam.setPosition(0, -400, z);
46968
46992
  *
46969
46993
  * // Display the value of eyeZ, rounded to the nearest integer.
46970
- * text(`eyeZ: ${round(cam.eyeZ)}`, 0, 55);
46994
+ * text(`eyeZ: ${round(cam.eyeZ)}`, 0, 45);
46971
46995
  * }
46972
46996
  * </code>
46973
46997
  * </div>
@@ -47026,7 +47050,7 @@ var p5 = (function () {
47026
47050
  * fill(0);
47027
47051
  *
47028
47052
  * // Display the value of centerX, rounded to the nearest integer.
47029
- * text(`centerX: ${round(cam.centerX)}`, 0, 55);
47053
+ * text(`centerX: ${round(cam.centerX)}`, 0, 45);
47030
47054
  * }
47031
47055
  * </code>
47032
47056
  * </div>
@@ -47080,7 +47104,7 @@ var p5 = (function () {
47080
47104
  * cam.lookAt(x, 20, -30);
47081
47105
  *
47082
47106
  * // Display the value of centerX, rounded to the nearest integer.
47083
- * text(`centerX: ${round(cam.centerX)}`, 0, 55);
47107
+ * text(`centerX: ${round(cam.centerX)}`, 0, 45);
47084
47108
  * }
47085
47109
  * </code>
47086
47110
  * </div>
@@ -47139,7 +47163,7 @@ var p5 = (function () {
47139
47163
  * fill(0);
47140
47164
  *
47141
47165
  * // Display the value of centerY, rounded to the nearest integer.
47142
- * text(`centerY: ${round(cam.centerY)}`, 0, 55);
47166
+ * text(`centerY: ${round(cam.centerY)}`, 0, 45);
47143
47167
  * }
47144
47168
  * </code>
47145
47169
  * </div>
@@ -47193,7 +47217,7 @@ var p5 = (function () {
47193
47217
  * cam.lookAt(10, y, -30);
47194
47218
  *
47195
47219
  * // Display the value of centerY, rounded to the nearest integer.
47196
- * text(`centerY: ${round(cam.centerY)}`, 0, 55);
47220
+ * text(`centerY: ${round(cam.centerY)}`, 0, 45);
47197
47221
  * }
47198
47222
  * </code>
47199
47223
  * </div>
@@ -47252,7 +47276,7 @@ var p5 = (function () {
47252
47276
  * fill(0);
47253
47277
  *
47254
47278
  * // Display the value of centerZ, rounded to the nearest integer.
47255
- * text(`centerZ: ${round(cam.centerZ)}`, 0, 55);
47279
+ * text(`centerZ: ${round(cam.centerZ)}`, 0, 45);
47256
47280
  * }
47257
47281
  * </code>
47258
47282
  * </div>
@@ -47270,9 +47294,6 @@ var p5 = (function () {
47270
47294
  * // Create a p5.Camera object.
47271
47295
  * cam = createCamera();
47272
47296
  *
47273
- * // Set the camera
47274
- * setCamera(cam);
47275
- *
47276
47297
  * // Place the camera at the top-right.
47277
47298
  * cam.setPosition(100, -400, 800);
47278
47299
  *
@@ -47306,7 +47327,7 @@ var p5 = (function () {
47306
47327
  * cam.lookAt(10, 20, z);
47307
47328
  *
47308
47329
  * // Display the value of centerZ, rounded to the nearest integer.
47309
- * text(`centerZ: ${round(cam.centerZ)}`, 0, 55);
47330
+ * text(`centerZ: ${round(cam.centerZ)}`, 0, 45);
47310
47331
  * }
47311
47332
  * </code>
47312
47333
  * </div>
@@ -47364,7 +47385,7 @@ var p5 = (function () {
47364
47385
  * fill(0);
47365
47386
  *
47366
47387
  * // Display the value of upX, rounded to the nearest tenth.
47367
- * text(`upX: ${round(cam.upX, 1)}`, 0, 55);
47388
+ * text(`upX: ${round(cam.upX, 1)}`, 0, 45);
47368
47389
  * }
47369
47390
  * </code>
47370
47391
  * </div>
@@ -47417,7 +47438,7 @@ var p5 = (function () {
47417
47438
  * cam.camera(100, -400, 800, 0, 0, 0, x, 1, 0);
47418
47439
  *
47419
47440
  * // Display the value of upX, rounded to the nearest tenth.
47420
- * text(`upX: ${round(cam.upX, 1)}`, 0, 55);
47441
+ * text(`upX: ${round(cam.upX, 1)}`, 0, 45);
47421
47442
  * }
47422
47443
  * </code>
47423
47444
  * </div>
@@ -47475,7 +47496,7 @@ var p5 = (function () {
47475
47496
  * fill(0);
47476
47497
  *
47477
47498
  * // Display the value of upY, rounded to the nearest tenth.
47478
- * text(`upY: ${round(cam.upY, 1)}`, 0, 55);
47499
+ * text(`upY: ${round(cam.upY, 1)}`, 0, 45);
47479
47500
  * }
47480
47501
  * </code>
47481
47502
  * </div>
@@ -47528,7 +47549,7 @@ var p5 = (function () {
47528
47549
  * cam.camera(100, -400, 800, 0, 0, 0, 0, y, 0);
47529
47550
  *
47530
47551
  * // Display the value of upY, rounded to the nearest tenth.
47531
- * text(`upY: ${round(cam.upY, 1)}`, 0, 55);
47552
+ * text(`upY: ${round(cam.upY, 1)}`, 0, 45);
47532
47553
  * }
47533
47554
  * </code>
47534
47555
  * </div>
@@ -47586,7 +47607,7 @@ var p5 = (function () {
47586
47607
  * fill(0);
47587
47608
  *
47588
47609
  * // Display the value of upZ, rounded to the nearest tenth.
47589
- * text(`upZ: ${round(cam.upZ, 1)}`, 0, 55);
47610
+ * text(`upZ: ${round(cam.upZ, 1)}`, 0, 45);
47590
47611
  * }
47591
47612
  * </code>
47592
47613
  * </div>
@@ -47639,7 +47660,7 @@ var p5 = (function () {
47639
47660
  * cam.camera(100, -400, 800, 0, 0, 0, 0, 1, z);
47640
47661
  *
47641
47662
  * // Display the value of upZ, rounded to the nearest tenth.
47642
- * text(`upZ: ${round(cam.upZ, 1)}`, 0, 55);
47663
+ * text(`upZ: ${round(cam.upZ, 1)}`, 0, 45);
47643
47664
  * }
47644
47665
  * </code>
47645
47666
  * </div>
@@ -55474,11 +55495,10 @@ var p5 = (function () {
55474
55495
  * }
55475
55496
  * </code>
55476
55497
  * </div>
55477
- * <br>
55478
- * Now with the antialias attribute set to true.
55479
- * <br>
55498
+ *
55480
55499
  * <div>
55481
55500
  * <code>
55501
+ * // Now with the antialias attribute set to true.
55482
55502
  * function setup() {
55483
55503
  * setAttributes('antialias', true);
55484
55504
  * createCanvas(100, 100, WEBGL);
@@ -58930,7 +58950,7 @@ var p5 = (function () {
58930
58950
  * three parameters, `v1`, `v2`, and `v3`, set the light’s color using the
58931
58951
  * current <a href="#/p5/colorMode">colorMode()</a>. The last parameter,
58932
58952
  * `direction` sets the light’s direction using a
58933
- * <a href="#/p5.Geometry">p5.Geometry</a> object. For example,
58953
+ * <a href="#/p5.Vector">p5.Vector</a> object. For example,
58934
58954
  * `directionalLight(255, 0, 0, lightDir)` creates a red `(255, 0, 0)` light
58935
58955
  * that shines in the direction the `lightDir` vector points.
58936
58956
  *
@@ -58945,7 +58965,7 @@ var p5 = (function () {
58945
58965
  * parameter, `color`, sets the light’s color using a
58946
58966
  * <a href="#/p5.Color">p5.Color</a> object or an array of color values. The
58947
58967
  * second parameter, `direction`, sets the light’s direction using a
58948
- * <a href="#/p5.Color">p5.Color</a> object. For example,
58968
+ * <a href="#/p5.Vector">p5.Vector</a> object. For example,
58949
58969
  * `directionalLight(myColor, lightDir)` creates a light that shines in the
58950
58970
  * direction the `lightDir` vector points with the color value of `myColor`.
58951
58971
  *
@@ -65845,6 +65865,7 @@ var p5 = (function () {
65845
65865
  // FramebufferTexture instances wrap raw WebGL textures already, which
65846
65866
  // don't need any extra updating, as they already live on the GPU
65847
65867
  if (this.isFramebufferTexture) {
65868
+ this.src.update();
65848
65869
  return false;
65849
65870
  }
65850
65871
 
@@ -66236,6 +66257,10 @@ var p5 = (function () {
66236
66257
  return this.framebuffer.height * this.framebuffer.density;
66237
66258
  }
66238
66259
 
66260
+ update() {
66261
+ this.framebuffer._update(this.property);
66262
+ }
66263
+
66239
66264
  rawTexture() {
66240
66265
  return this.framebuffer[this.property];
66241
66266
  }
@@ -66248,6 +66273,8 @@ var p5 = (function () {
66248
66273
 
66249
66274
  this._isClipApplied = false;
66250
66275
 
66276
+ this.dirty = { colorTexture: false, depthTexture: false };
66277
+
66251
66278
  this.pixels = [];
66252
66279
 
66253
66280
  this.format = settings.format || UNSIGNED_BYTE;
@@ -67287,6 +67314,49 @@ var p5 = (function () {
67287
67314
  }
67288
67315
  }
67289
67316
 
67317
+ /**
67318
+ * Ensure all readable textures are up-to-date.
67319
+ * @private
67320
+ * @property {'colorTexutre'|'depthTexture'} property The property to update
67321
+ */
67322
+ _update(property) {
67323
+ if (this.dirty[property] && this.antialias) {
67324
+ const gl = this.gl;
67325
+ gl.bindFramebuffer(gl.READ_FRAMEBUFFER, this.aaFramebuffer);
67326
+ gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, this.framebuffer);
67327
+ const partsToCopy = {
67328
+ colorTexture: [gl.COLOR_BUFFER_BIT, this.colorP5Texture.glMagFilter],
67329
+ };
67330
+ if (this.useDepth) {
67331
+ partsToCopy.depthTexture = [
67332
+ gl.DEPTH_BUFFER_BIT,
67333
+ this.depthP5Texture.glMagFilter
67334
+ ];
67335
+ }
67336
+ const [flag, filter] = partsToCopy[property];
67337
+ gl.blitFramebuffer(
67338
+ 0,
67339
+ 0,
67340
+ this.width * this.density,
67341
+ this.height * this.density,
67342
+ 0,
67343
+ 0,
67344
+ this.width * this.density,
67345
+ this.height * this.density,
67346
+ flag,
67347
+ filter
67348
+ );
67349
+ this.dirty[property] = false;
67350
+
67351
+ const activeFbo = this.renderer.activeFramebuffer();
67352
+ if (activeFbo) {
67353
+ gl.bindFramebuffer(gl.FRAMEBUFFER, activeFbo._framebufferToBind());
67354
+ } else {
67355
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
67356
+ }
67357
+ }
67358
+ }
67359
+
67290
67360
  /**
67291
67361
  * Ensures that the framebuffer is ready to be drawn to
67292
67362
  *
@@ -67308,27 +67378,7 @@ var p5 = (function () {
67308
67378
  */
67309
67379
  _beforeEnd() {
67310
67380
  if (this.antialias) {
67311
- const gl = this.gl;
67312
- gl.bindFramebuffer(gl.READ_FRAMEBUFFER, this.aaFramebuffer);
67313
- gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, this.framebuffer);
67314
- const partsToCopy = [
67315
- [gl.COLOR_BUFFER_BIT, this.colorP5Texture.glMagFilter]
67316
- ];
67317
- if (this.useDepth) {
67318
- partsToCopy.push(
67319
- [gl.DEPTH_BUFFER_BIT, this.depthP5Texture.glMagFilter]
67320
- );
67321
- }
67322
- for (const [flag, filter] of partsToCopy) {
67323
- gl.blitFramebuffer(
67324
- 0, 0,
67325
- this.width * this.density, this.height * this.density,
67326
- 0, 0,
67327
- this.width * this.density, this.height * this.density,
67328
- flag,
67329
- filter
67330
- );
67331
- }
67381
+ this.dirty = { colorTexture: true, depthTexture: true };
67332
67382
  }
67333
67383
  }
67334
67384
 
@@ -67508,6 +67558,7 @@ var p5 = (function () {
67508
67558
  * </div>
67509
67559
  */
67510
67560
  loadPixels() {
67561
+ this._update('colorTexture');
67511
67562
  const gl = this.gl;
67512
67563
  const prevFramebuffer = this.renderer.activeFramebuffer();
67513
67564
  gl.bindFramebuffer(gl.FRAMEBUFFER, this.framebuffer);
@@ -67566,6 +67617,7 @@ var p5 = (function () {
67566
67617
  * @return {Number[]} color of the pixel at `(x, y)` as an array of color values `[R, G, B, A]`.
67567
67618
  */
67568
67619
  get(x, y, w, h) {
67620
+ this._update('colorTexture');
67569
67621
  // p5._validateParameters('p5.Framebuffer.get', arguments);
67570
67622
  const colorFormat = this._glColorFormat();
67571
67623
  if (x === undefined && y === undefined) {
@@ -67732,6 +67784,7 @@ var p5 = (function () {
67732
67784
  this.pixels
67733
67785
  );
67734
67786
  this.colorP5Texture.unbindTexture();
67787
+ this.dirty.colorTexture = false;
67735
67788
 
67736
67789
  const prevFramebuffer = this.renderer.activeFramebuffer();
67737
67790
  if (this.antialias) {
@@ -70540,10 +70593,14 @@ var p5 = (function () {
70540
70593
  * ```
70541
70594
  *
70542
70595
  * Code placed in `setup()` will run once before code placed in
70543
- * <a href="#/p5/draw">draw()</a> begins looping. If the
70544
- * <a href="#/p5/preload">preload()</a> is declared, then `setup()` will
70545
- * run immediately after <a href="#/p5/preload">preload()</a> finishes
70546
- *
70596
+ * <a href="#/p5/draw">draw()</a> begins looping.
70597
+ * If `setup()` is declared `async` (e.g. `async function setup()`),
70598
+ * execution pauses at each `await` until its promise resolves.
70599
+ * For example, `font = await loadFont(...)` waits for the font asset
70600
+ * to load because `loadFont()` function returns a promise, and the await
70601
+ * keyword means the program will wait for the promise to resolve.
70602
+ * This ensures that all assets are fully loaded before the sketch continues.
70603
+
70547
70604
  *
70548
70605
  * loading assets.
70549
70606
  *
@@ -70615,7 +70672,6 @@ var p5 = (function () {
70615
70672
  * </code>
70616
70673
  * </div>
70617
70674
  */
70618
-
70619
70675
  /**
70620
70676
  * A function that's called repeatedly while the sketch runs.
70621
70677
  *
@@ -70843,6 +70899,11 @@ var p5 = (function () {
70843
70899
  *
70844
70900
  * <div>
70845
70901
  * <code>
70902
+ *
70903
+ * function setup(){
70904
+ * createCanvas(100, 100);
70905
+ * };
70906
+ *
70846
70907
  * function draw() {
70847
70908
  * background(200);
70848
70909
  *
@@ -70864,6 +70925,11 @@ var p5 = (function () {
70864
70925
  *
70865
70926
  * <div>
70866
70927
  * <code>
70928
+ *
70929
+ * function setup(){
70930
+ * createCanvas(100, 100);
70931
+ * }
70932
+ *
70867
70933
  * function draw() {
70868
70934
  * background(200);
70869
70935
  *
@@ -71636,6 +71702,11 @@ var p5 = (function () {
71636
71702
  *
71637
71703
  * <div>
71638
71704
  * <code>
71705
+ *
71706
+ * function setup(){
71707
+ * createCanvas(100, 100);
71708
+ * }
71709
+ *
71639
71710
  * function draw() {
71640
71711
  * // Add the text description.
71641
71712
  * textOutput();
@@ -71656,6 +71727,11 @@ var p5 = (function () {
71656
71727
  *
71657
71728
  * <div>
71658
71729
  * <code>
71730
+ *
71731
+ * function setup(){
71732
+ * createCanvas(100, 100);
71733
+ * }
71734
+ *
71659
71735
  * function draw() {
71660
71736
  * // Add the text description and
71661
71737
  * // display it for debugging.
@@ -71770,6 +71846,11 @@ var p5 = (function () {
71770
71846
  *
71771
71847
  * <div>
71772
71848
  * <code>
71849
+ *
71850
+ * function setup() {
71851
+ * createCanvas(100, 100);
71852
+ * }
71853
+ *
71773
71854
  * function draw() {
71774
71855
  * // Add the grid description.
71775
71856
  * gridOutput();
@@ -71790,6 +71871,11 @@ var p5 = (function () {
71790
71871
  *
71791
71872
  * <div>
71792
71873
  * <code>
71874
+ *
71875
+ * function setup(){
71876
+ * createCanvas(100, 100);
71877
+ * }
71878
+ *
71793
71879
  * function draw() {
71794
71880
  * // Add the grid description and
71795
71881
  * // display it for debugging.
@@ -71810,6 +71896,7 @@ var p5 = (function () {
71810
71896
  * </div>
71811
71897
  */
71812
71898
 
71899
+
71813
71900
  fn.gridOutput = function(display) {
71814
71901
  // p5._validateParameters('gridOutput', arguments);
71815
71902
  //if gridOutput is already true
@@ -82767,7 +82854,7 @@ var p5 = (function () {
82767
82854
  image: {
82768
82855
  overloads: [
82769
82856
  [
82770
- "p5.Image|p5.Element|p5.Texture|p5.Framebuffer|p5.FramebufferTexture",
82857
+ "p5.Image|p5.Element|p5.Texture|p5.Framebuffer|p5.FramebufferTexture|p5.Renderer|p5.Graphics",
82771
82858
  "Number",
82772
82859
  "Number",
82773
82860
  "Number?",
@@ -83265,14 +83352,7 @@ var p5 = (function () {
83265
83352
  createVector: {
83266
83353
  overloads: [
83267
83354
  [
83268
- null
83269
- ]
83270
- ]
83271
- },
83272
- createMatrix: {
83273
- overloads: [
83274
- [
83275
- "Number[]"
83355
+ "...Number[]"
83276
83356
  ]
83277
83357
  ]
83278
83358
  },
@@ -83698,14 +83778,23 @@ var p5 = (function () {
83698
83778
  bezierOrder: {
83699
83779
  overloads: [
83700
83780
  [
83781
+ "Number"
83701
83782
  ],
83702
83783
  [
83703
- "Number"
83704
83784
  ]
83705
83785
  ]
83706
83786
  },
83707
83787
  splineVertex: {
83708
83788
  overloads: [
83789
+ [
83790
+ "Number",
83791
+ "Number"
83792
+ ],
83793
+ [
83794
+ "Number",
83795
+ "Number",
83796
+ "Number?"
83797
+ ],
83709
83798
  [
83710
83799
  "Number",
83711
83800
  "Number",
@@ -83723,21 +83812,21 @@ var p5 = (function () {
83723
83812
  },
83724
83813
  splineProperty: {
83725
83814
  overloads: [
83726
- [
83727
- "String"
83728
- ],
83729
83815
  [
83730
83816
  "String",
83731
83817
  null
83818
+ ],
83819
+ [
83820
+ "String"
83732
83821
  ]
83733
83822
  ]
83734
83823
  },
83735
83824
  splineProperties: {
83736
83825
  overloads: [
83737
83826
  [
83827
+ "Object"
83738
83828
  ],
83739
83829
  [
83740
- "Object"
83741
83830
  ]
83742
83831
  ]
83743
83832
  },
@@ -83799,19 +83888,6 @@ var p5 = (function () {
83799
83888
  ]
83800
83889
  ]
83801
83890
  },
83802
- curveVertex: {
83803
- overloads: [
83804
- [
83805
- "Number",
83806
- "Number"
83807
- ],
83808
- [
83809
- "Number",
83810
- "Number",
83811
- "Number?"
83812
- ]
83813
- ]
83814
- },
83815
83891
  endShape: {
83816
83892
  overloads: [
83817
83893
  [
@@ -83846,7 +83922,6 @@ var p5 = (function () {
83846
83922
  "String",
83847
83923
  "String?",
83848
83924
  "Object?",
83849
- "String|String[]?",
83850
83925
  "Function?",
83851
83926
  "Function?"
83852
83927
  ],
@@ -84608,56 +84683,15 @@ var p5 = (function () {
84608
84683
  ],
84609
84684
  [
84610
84685
  "String|Request",
84611
- "Object?",
84612
- "String?",
84613
- "function(p5.Geometry)?",
84614
- "function(Event)?",
84615
- "Boolean?",
84616
- "Boolean?",
84617
- "Boolean?"
84618
- ]
84619
- ]
84620
- },
84621
- parseObj: {
84622
- overloads: [
84623
- [
84624
- ]
84625
- ]
84626
- },
84627
- parseSTL: {
84628
- overloads: [
84629
- [
84630
- ]
84631
- ]
84632
- },
84633
- isBinary: {
84634
- overloads: [
84635
- [
84636
- ]
84637
- ]
84638
- },
84639
- matchDataViewAt: {
84640
- overloads: [
84641
- [
84642
- ]
84643
- ]
84644
- },
84645
- parseBinarySTL: {
84646
- overloads: [
84647
- [
84648
- ]
84649
- ]
84650
- },
84651
- parseASCIISTL: {
84652
- overloads: [
84653
- [
84686
+ "Object?"
84654
84687
  ]
84655
84688
  ]
84656
84689
  },
84657
84690
  model: {
84658
84691
  overloads: [
84659
84692
  [
84660
- "p5.Geometry"
84693
+ "p5.Geometry",
84694
+ "Number?"
84661
84695
  ]
84662
84696
  ]
84663
84697
  },
@@ -84679,12 +84713,7 @@ var p5 = (function () {
84679
84713
  [
84680
84714
  "String",
84681
84715
  "String?",
84682
- "Object?",
84683
- "function(p5.Geometry)?",
84684
- "function(Event)?",
84685
- "boolean?",
84686
- "boolean?",
84687
- "boolean?"
84716
+ "Object?"
84688
84717
  ]
84689
84718
  ]
84690
84719
  },
@@ -86471,9 +86500,7 @@ var p5 = (function () {
86471
86500
  "Number",
86472
86501
  "Number",
86473
86502
  "Number",
86474
- "Object?",
86475
- "Number?",
86476
- "Number?"
86503
+ "Object?"
86477
86504
  ]
86478
86505
  ]
86479
86506
  }
@@ -86920,9 +86947,14 @@ var p5 = (function () {
86920
86947
  const isOptional = param?.endsWith('?');
86921
86948
  param = param?.replace(/\?$/, '');
86922
86949
 
86923
- let schema = generateTypeSchema(param);
86950
+ const isRest = param?.startsWith('...') && param?.endsWith('[]');
86951
+ param = param?.replace(/^\.\.\.(.+)\[\]$/, '$1');
86924
86952
 
86925
- return isOptional ? schema.optional() : schema;
86953
+ let schema = generateTypeSchema(param);
86954
+ if (isOptional) {
86955
+ schema = schema.optional();
86956
+ }
86957
+ return { schema, rest: isRest };
86926
86958
  };
86927
86959
 
86928
86960
  // Note that in Zod, `optional()` only checks for undefined, not the absence
@@ -86956,14 +86988,22 @@ var p5 = (function () {
86956
86988
  const overloadSchemas = overloads.flatMap(overload => {
86957
86989
  const combinations = generateOverloadCombinations(overload);
86958
86990
 
86959
- return combinations.map(combo =>
86960
- tupleType(
86961
- combo
86962
- .map(p => generateParamSchema(p))
86963
- // For now, ignore schemas that cannot be mapped to a defined type
86964
- .filter(schema => schema !== undefined)
86965
- )
86966
- );
86991
+ return combinations.map(combo => {
86992
+ const params = combo
86993
+ .map(p => generateParamSchema(p))
86994
+ .filter(s => s.schema !== undefined);
86995
+
86996
+ let rest;
86997
+ if (params.at(-1)?.rest) {
86998
+ rest = params.pop();
86999
+ }
87000
+
87001
+ let combined = tupleType(params.map(s => s.schema));
87002
+ if (rest) {
87003
+ combined = combined.rest(rest.schema);
87004
+ }
87005
+ return combined;
87006
+ });
86967
87007
  });
86968
87008
 
86969
87009
  return overloadSchemas.length === 1
@@ -87198,7 +87238,7 @@ var p5 = (function () {
87198
87238
  // theoretically allowed to stay undefined and valid, it is likely that the
87199
87239
  // user intended to call the function with non-undefined arguments. Skip
87200
87240
  // regular workflow and return a friendly error message right away.
87201
- if (Array.isArray(args) && args.every(arg => arg === undefined)) {
87241
+ if (Array.isArray(args) && args.length > 0 && args.every(arg => arg === undefined)) {
87202
87242
  const undefinedErrorMessage = `🌸 p5.js says: All arguments for ${func}() are undefined. There is likely an error in the code.`;
87203
87243
 
87204
87244
  return {
@@ -94821,7 +94861,7 @@ var p5 = (function () {
94821
94861
  * let slider;
94822
94862
  *
94823
94863
  * function setup() {
94824
- * createCanvas(100, 100);
94864
+ * createCanvas(200, 200);
94825
94865
  *
94826
94866
  * // Create a paragraph element and place
94827
94867
  * // it at the top of the canvas.
@@ -95062,10 +95102,10 @@ var p5 = (function () {
95062
95102
  * background(200);
95063
95103
  *
95064
95104
  * let img = createImg(
95065
- * 'https://p5js.org/assets/img/asterisk-01.png',
95066
- * 'The p5.js magenta asterisk.'
95105
+ * '/assets/cat.jpg',
95106
+ * 'image of a cat'
95067
95107
  * );
95068
- * img.position(0, -10);
95108
+ * img.position(0, 10);
95069
95109
  *
95070
95110
  * describe('A gray square with a magenta asterisk in its center.');
95071
95111
  * }
@@ -95414,7 +95454,7 @@ var p5 = (function () {
95414
95454
  *
95415
95455
  * // Create a checkbox and place it beneath the canvas.
95416
95456
  * checkbox = createCheckbox();
95417
- * checkbox.position(0, 100);
95457
+ * checkbox.position(0, 70);
95418
95458
  *
95419
95459
  * describe('A black square with a checkbox beneath it. The square turns white when the box is checked.');
95420
95460
  * }
@@ -95440,7 +95480,7 @@ var p5 = (function () {
95440
95480
  * // Create a checkbox and place it beneath the canvas.
95441
95481
  * // Label the checkbox "white".
95442
95482
  * checkbox = createCheckbox(' white');
95443
- * checkbox.position(0, 100);
95483
+ * checkbox.position(0, 70);
95444
95484
  *
95445
95485
  * describe('A black square with a checkbox labeled "white" beneath it. The square turns white when the box is checked.');
95446
95486
  * }
@@ -95466,7 +95506,7 @@ var p5 = (function () {
95466
95506
  * // Create a checkbox and place it beneath the canvas.
95467
95507
  * // Label the checkbox "white" and set its value to true.
95468
95508
  * checkbox = createCheckbox(' white', true);
95469
- * checkbox.position(0, 100);
95509
+ * checkbox.position(0, 70);
95470
95510
  *
95471
95511
  * describe('A white square with a checkbox labeled "white" beneath it. The square turns black when the box is unchecked.');
95472
95512
  * }
@@ -96345,7 +96385,7 @@ var p5 = (function () {
96345
96385
  * let img;
96346
96386
  *
96347
96387
  * function setup() {
96348
- * createCanvas(100, 100);
96388
+ * createCanvas(200, 200);
96349
96389
  *
96350
96390
  * // Create a file input and place it beneath
96351
96391
  * // the canvas.
@@ -96599,18 +96639,18 @@ var p5 = (function () {
96599
96639
  * @example
96600
96640
  * <div>
96601
96641
  * <code>
96642
+ * let rotationX = 0; // Angle in degrees
96643
+ *
96602
96644
  * function setup() {
96603
- * createCanvas(100, 100, WEBGL);
96645
+ * createCanvas(200, 200, WEBGL); // Create 3D canvas
96604
96646
  * }
96605
96647
  *
96606
96648
  * function draw() {
96607
- * background(200);
96608
- * //rotateZ(radians(rotationZ));
96609
- * rotateX(radians(rotationX));
96610
- * //rotateY(radians(rotationY));
96611
- * box(200, 200, 200);
96612
- * describe(`red horizontal line right, green vertical line bottom.
96613
- * black background.`);
96649
+ * background(220); // Set light gray background
96650
+ * rotateX(radians(rotationX)); // Rotate around X-axis
96651
+ * normalMaterial(); // Apply simple shaded material
96652
+ * box(60); // Draw 3D cube (60 units wide)
96653
+ * rotationX = (rotationX + 2) % 360; // Increment rotation (2° per frame)
96614
96654
  * }
96615
96655
  * </code>
96616
96656
  * </div>
@@ -96632,18 +96672,18 @@ var p5 = (function () {
96632
96672
  * @example
96633
96673
  * <div>
96634
96674
  * <code>
96675
+ * let rotationY = 0; // Angle in degrees
96676
+ *
96635
96677
  * function setup() {
96636
- * createCanvas(100, 100, WEBGL);
96678
+ * createCanvas(200, 200, WEBGL); // Create 3D canvas
96637
96679
  * }
96638
96680
  *
96639
96681
  * function draw() {
96640
- * background(200);
96641
- * //rotateZ(radians(rotationZ));
96642
- * //rotateX(radians(rotationX));
96643
- * rotateY(radians(rotationY));
96644
- * box(200, 200, 200);
96645
- * describe(`red horizontal line right, green vertical line bottom.
96646
- * black background.`);
96682
+ * background(220); // Set light gray background
96683
+ * rotateY(radians(rotationY)); // Rotate around Y-axis (vertical)
96684
+ * normalMaterial(); // Apply simple shaded material
96685
+ * box(60); // Draw 3D cube (60 units wide)
96686
+ * rotationY = (rotationY + 2) % 360; // Increment rotation (2° per frame)
96647
96687
  * }
96648
96688
  * </code>
96649
96689
  * </div>
@@ -96666,18 +96706,18 @@ var p5 = (function () {
96666
96706
  * @example
96667
96707
  * <div>
96668
96708
  * <code>
96709
+ * let rotationZ = 0; // Angle in degrees
96710
+ *
96669
96711
  * function setup() {
96670
- * createCanvas(100, 100, WEBGL);
96712
+ * createCanvas(200, 200, WEBGL); // Create 3D canvas
96671
96713
  * }
96672
96714
  *
96673
96715
  * function draw() {
96674
- * background(200);
96675
- * rotateZ(radians(rotationZ));
96676
- * //rotateX(radians(rotationX));
96677
- * //rotateY(radians(rotationY));
96678
- * box(200, 200, 200);
96679
- * describe(`red horizontal line right, green vertical line bottom.
96680
- * black background.`);
96716
+ * background(220);
96717
+ * rotateZ(radians(rotationZ)); // Rotate around Z-axis
96718
+ * normalMaterial(); // Apply simple shaded material
96719
+ * box(60); // Draw 3D cube
96720
+ * rotationZ = (rotationZ + 2) % 360; // Increment rotation angle
96681
96721
  * }
96682
96722
  * </code>
96683
96723
  * </div>
@@ -97866,7 +97906,6 @@ var p5 = (function () {
97866
97906
 
97867
97907
  };
97868
97908
 
97869
-
97870
97909
  /**
97871
97910
  * A function that's called once when keys with printable characters are pressed.
97872
97911
  *
@@ -97998,7 +98037,7 @@ var p5 = (function () {
97998
98037
  * </div>
97999
98038
  */
98000
98039
  fn._onkeypress = function(e) {
98001
- if (e.which === this._lastKeyCodeTyped) {
98040
+ if (e.which === this._lastKeyCodeTyped && e.repeat) {
98002
98041
  // prevent multiple firings
98003
98042
  return;
98004
98043
  }
@@ -98036,10 +98075,16 @@ var p5 = (function () {
98036
98075
  * }
98037
98076
  * ```
98038
98077
  *
98039
- * `keyIsDown()` can check for key presses using
98040
- * <a href="#/p5/keyCode">keyCode</a> values, as in `keyIsDown(37)` or
98041
- * `keyIsDown(LEFT_ARROW)`. Key codes can be found on websites such as
98042
- * <a href="https://keycode.info" target="_blank">keycode.info</a>.
98078
+ * `keyIsDown()` can check for key presses using strings based on
98079
+ * <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key" target="_blank">KeyboardEvent.key</a>
98080
+ * or <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code" target="_blank">KeyboardEvent.code</a> values,
98081
+ * such as `keyIsDown('x')` or `keyIsDown('ArrowLeft')`.
98082
+ *
98083
+ * Note: In p5.js 2.0 and newer, numeric keycodes (such as 88 for 'X') are no longer supported.
98084
+ * This is a breaking change from previous versions.
98085
+ *
98086
+ * You can still use the p5 constants like `LEFT_ARROW` which now map to string values
98087
+ * internally rather than numeric codes.
98043
98088
  *
98044
98089
  * @method keyIsDown
98045
98090
  * @param {Number|String} code key to check.
@@ -101908,8 +101953,8 @@ var p5 = (function () {
101908
101953
  * let table;
101909
101954
  *
101910
101955
  * async function setup() {
101911
- * // Create a 200x100 canvas and set a white background
101912
- * createCanvas(200, 100);
101956
+ * // Create a 300x100 canvas and set a white background
101957
+ * createCanvas(300, 100);
101913
101958
  * background(255);
101914
101959
  *
101915
101960
  * // Load the CSV file with a header row
@@ -104051,7 +104096,7 @@ var p5 = (function () {
104051
104096
  * <a href="#/p5.Vector">p5.Vector</a> class.
104052
104097
  *
104053
104098
  * @method createVector
104054
- * @param {...Number} components Components of the vector.
104099
+ * @param {...Number} x Zero or more numbers, representing each component of the vector.
104055
104100
  * @return {p5.Vector} new <a href="#/p5.Vector">p5.Vector</a> object.
104056
104101
  *
104057
104102
  * @example
@@ -108219,6 +108264,7 @@ var p5 = (function () {
108219
108264
  * @method model
108220
108265
  * @param {p5.Geometry} model 3D shape to be drawn.
108221
108266
  *
108267
+ * @param {Number} [count=1] number of instances to draw.
108222
108268
  * @example
108223
108269
  * <div>
108224
108270
  * <code>
@@ -109749,7 +109795,7 @@ var p5 = (function () {
109749
109795
  * createCanvas(300, 300);
109750
109796
  * background(220);
109751
109797
  *
109752
- * textSize(48);
109798
+ * textSize(35);
109753
109799
  * textAlign(LEFT, BASELINE);
109754
109800
  * textFont('Georgia');
109755
109801
  *
@@ -118714,7 +118760,6 @@ var p5 = (function () {
118714
118760
  const fontFaceVariations = ['weight', 'stretch', 'style'];
118715
118761
 
118716
118762
 
118717
- let nextId = 0;
118718
118763
  class Font {
118719
118764
  constructor(p, fontFace, name, path, data) {
118720
118765
  if (!(fontFace instanceof FontFace)) {
@@ -118725,7 +118770,6 @@ var p5 = (function () {
118725
118770
  this.path = path;
118726
118771
  this.data = data;
118727
118772
  this.face = fontFace;
118728
- this.id = nextId++;
118729
118773
  }
118730
118774
 
118731
118775
  /**
@@ -120159,24 +120203,7 @@ var p5 = (function () {
120159
120203
  function text(p5, fn) {
120160
120204
  RendererGL.prototype.maxCachedGlyphs = function() {
120161
120205
  // TODO: use more than vibes to find a good value for this
120162
- return 200
120163
- };
120164
-
120165
- RendererGL.prototype.freeGlyphInfo = function(gi) {
120166
- const datas = [
120167
- gi.strokeImageInfo.imageData,
120168
- gi.rowInfo.cellImageInfo.imageData,
120169
- gi.rowInfo.dimImageInfo.imageData,
120170
- gi.colInfo.cellImageInfo.imageData,
120171
- gi.colInfo.dimImageInfo.imageData,
120172
- ];
120173
- for (const data of datas) {
120174
- const tex = this.textures.get(data);
120175
- if (tex) {
120176
- tex.remove();
120177
- this.textures.delete(data);
120178
- }
120179
- }
120206
+ return 200;
120180
120207
  };
120181
120208
 
120182
120209
  Font.prototype._getFontInfo = function(axs) {
@@ -120944,7 +120971,7 @@ var p5 = (function () {
120944
120971
  sh.setUniform("uMaterialColor", curFillColor);
120945
120972
  gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
120946
120973
 
120947
- this.fontCache = this.fontCache || new Map();
120974
+ this.glyphDataCache = this.glyphDataCache || new Set();
120948
120975
 
120949
120976
  try {
120950
120977
  // fetch the glyphs in the line of text
@@ -120953,20 +120980,35 @@ var p5 = (function () {
120953
120980
  for (const glyph of glyphs) {
120954
120981
  const gi = fontInfo.getGlyphInfo(glyph);
120955
120982
  if (gi.uGlyphRect) {
120983
+ const rowInfo = gi.rowInfo;
120984
+ const colInfo = gi.colInfo;
120956
120985
 
120957
- const cacheKey = JSON.stringify({ font: font.id, axs, glyph: glyph.shape.g });
120958
- // Bump this font to the end of the cache list by deleting and re-adding it
120959
- this.fontCache.delete(cacheKey);
120960
- this.fontCache.set(cacheKey, gi);
120961
- if (this.fontCache.size > this.maxCachedGlyphs()) {
120962
- const keyToRemove = this.fontCache.keys().next().value;
120963
- const val = this.fontCache.get(keyToRemove);
120964
- this.fontCache.delete(keyToRemove);
120965
- this.freeGlyphInfo(val);
120986
+ // Bump the resources for this glyph to the end of the cache list by deleting and re-adding
120987
+ const glyphResources = [
120988
+ gi.strokeImageInfo.imageData,
120989
+ rowInfo.cellImageInfo.imageData,
120990
+ rowInfo.dimImageInfo.imageData,
120991
+ colInfo.cellImageInfo.imageData,
120992
+ colInfo.dimImageInfo.imageData
120993
+ ];
120994
+ for (const resource of glyphResources) {
120995
+ this.glyphDataCache.delete(resource);
120996
+ this.glyphDataCache.add(resource);
120997
+ }
120998
+
120999
+ // If we have too many glyph textures, remove the least recently used
121000
+ // ones from GPU memory. The data still exists on the CPU and will be
121001
+ // re-uploaded if it gets actively used again.
121002
+ while (this.glyphDataCache.size > this.maxCachedGlyphs()) {
121003
+ const data = this.glyphDataCache.values().next().value;
121004
+ this.glyphDataCache.delete(data);
121005
+ const tex = this.textures.get(data);
121006
+ if (tex) {
121007
+ tex.remove();
121008
+ this.textures.delete(data);
121009
+ }
120966
121010
  }
120967
121011
 
120968
- const rowInfo = gi.rowInfo;
120969
- const colInfo = gi.colInfo;
120970
121012
  sh.setUniform("uSamplerStrokes", gi.strokeImageInfo.imageData);
120971
121013
  sh.setUniform("uSamplerRowStrokes", rowInfo.cellImageInfo.imageData);
120972
121014
  sh.setUniform("uSamplerRows", rowInfo.dimImageInfo.imageData);