p5 2.0.0 → 2.0.2

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 (267) hide show
  1. package/{src → dist}/accessibility/color_namer.js +48 -3
  2. package/{src → dist}/accessibility/describe.js +12 -2
  3. package/{src → dist}/accessibility/gridOutput.js +2 -2
  4. package/dist/accessibility/index.js +60 -0
  5. package/{src → dist}/accessibility/outputs.js +23 -2
  6. package/{src → dist}/accessibility/textOutput.js +2 -2
  7. package/dist/app.js +120 -0
  8. package/{src → dist}/color/color_conversion.js +48 -10
  9. package/{src → dist}/color/color_spaces/hsb.js +3 -1
  10. package/dist/color/creating_reading.js +3 -0
  11. package/dist/color/index.js +13 -0
  12. package/dist/color/p5.Color.culori.js +1 -0
  13. package/dist/color/p5.Color.js +3 -0
  14. package/{src → dist}/color/setting.js +9 -6
  15. package/{src/core/constants.js → dist/constants-tYr0tCl8.js} +284 -132
  16. package/{src → dist}/core/States.js +3 -1
  17. package/dist/core/constants.js +1 -0
  18. package/{src → dist}/core/environment.js +12 -10
  19. package/{src → dist}/core/friendly_errors/browser_errors.js +1 -1
  20. package/{src → dist}/core/friendly_errors/fes_core.js +14 -44
  21. package/{src → dist}/core/friendly_errors/file_errors.js +6 -3
  22. package/dist/core/friendly_errors/index.js +23 -0
  23. package/dist/core/friendly_errors/param_validator.js +5421 -0
  24. package/{src → dist}/core/friendly_errors/sketch_reader.js +50 -4
  25. package/{src → dist}/core/friendly_errors/sketch_verifier.js +6 -6
  26. package/{src → dist}/core/friendly_errors/stacktrace.js +3 -5
  27. package/{src → dist}/core/friendly_errors/validate_params.js +50 -41
  28. package/{src → dist}/core/helpers.js +9 -6
  29. package/dist/core/init.js +105 -0
  30. package/dist/core/internationalization.js +302 -0
  31. package/dist/core/legacy.js +73 -0
  32. package/dist/core/main.js +44 -0
  33. package/dist/core/noop.js +3 -0
  34. package/dist/core/p5.Graphics.js +40 -0
  35. package/dist/core/p5.Renderer.js +11 -0
  36. package/dist/core/p5.Renderer2D.js +44 -0
  37. package/dist/core/reference.js +1 -0
  38. package/dist/core/rendering.js +40 -0
  39. package/{src → dist}/core/structure.js +3 -3
  40. package/{src → dist}/core/transform.js +2 -2
  41. package/{src/color/creating_reading.js → dist/creating_reading-Cr8L2Jnm.js} +841 -13
  42. package/{src → dist}/data/index.js +3 -1
  43. package/{src → dist}/data/local_storage.js +2 -8
  44. package/{src → dist}/dom/dom.js +19 -13
  45. package/dist/dom/index.js +18 -0
  46. package/{src → dist}/dom/p5.Element.js +14 -12
  47. package/{src → dist}/dom/p5.File.js +4 -4
  48. package/{src → dist}/dom/p5.MediaElement.js +10 -4
  49. package/{src → dist}/events/acceleration.js +26 -26
  50. package/{src → dist}/events/index.js +3 -1
  51. package/{src → dist}/events/keyboard.js +14 -12
  52. package/{src → dist}/events/pointer.js +16 -17
  53. package/dist/image/const.js +9 -0
  54. package/{src → dist}/image/filterRenderer2D.js +57 -37
  55. package/{src → dist}/image/filters.js +1 -3
  56. package/dist/image/image.js +40 -0
  57. package/dist/image/index.js +51 -0
  58. package/dist/image/loading_displaying.js +40 -0
  59. package/dist/image/p5.Image.js +11 -0
  60. package/{src → dist}/image/pixels.js +5 -3
  61. package/{src → dist}/io/csv.js +72 -70
  62. package/dist/io/files.js +40 -0
  63. package/dist/io/index.js +51 -0
  64. package/{src → dist}/io/p5.Table.js +6 -6
  65. package/{src → dist}/io/p5.TableRow.js +5 -6
  66. package/{src → dist}/io/p5.XML.js +2 -5
  67. package/{src → dist}/io/utilities.js +1 -1
  68. package/{src/core/p5.Renderer2D.js → dist/main-CAxvgiOV.js} +738 -57
  69. package/{src → dist}/math/Matrices/Matrix.js +10 -8
  70. package/{src → dist}/math/Matrices/MatrixInterface.js +5 -3
  71. package/{src → dist}/math/Matrices/MatrixNumjs.js +12 -26
  72. package/{src → dist}/math/calculation.js +2 -2
  73. package/{src → dist}/math/index.js +6 -3
  74. package/{src → dist}/math/math.js +3 -3
  75. package/{src → dist}/math/noise.js +2 -2
  76. package/{src → dist}/math/p5.Matrix.js +7 -4
  77. package/{src → dist}/math/p5.Vector.js +6 -6
  78. package/{src → dist}/math/random.js +2 -2
  79. package/{src → dist}/math/trigonometry.js +16 -15
  80. package/{src/image/p5.Image.js → dist/p5.Renderer-Swjl9HQO.js} +393 -22
  81. package/dist/rendering-B5TRR7aY.js +24960 -0
  82. package/{src → dist}/shape/2d_primitives.js +18 -17
  83. package/{src → dist}/shape/attributes.js +18 -17
  84. package/{src → dist}/shape/curves.js +2 -2
  85. package/{src → dist}/shape/custom_shapes.js +44 -64
  86. package/{src → dist}/shape/index.js +10 -2
  87. package/{src → dist}/shape/vertex.js +2 -3
  88. package/dist/type/index.js +25 -0
  89. package/{src → dist}/type/lib/Typr.js +76 -94
  90. package/{src → dist}/type/p5.Font.js +37 -63
  91. package/{src → dist}/type/textCore.js +35 -58
  92. package/{src → dist}/type/unicodeRanges.js +3 -1
  93. package/{src → dist}/utilities/conversion.js +2 -2
  94. package/{src → dist}/utilities/index.js +3 -1
  95. package/{src → dist}/utilities/time_date.js +6 -7
  96. package/{src → dist}/utilities/utility_functions.js +2 -2
  97. package/dist/webgl/3d_primitives.js +40 -0
  98. package/{src → dist}/webgl/GeometryBufferCache.js +3 -1
  99. package/{src → dist}/webgl/GeometryBuilder.js +12 -8
  100. package/{src → dist}/webgl/ShaderGenerator.js +79 -82
  101. package/{src → dist}/webgl/ShapeBuilder.js +26 -23
  102. package/dist/webgl/index.js +76 -0
  103. package/{src → dist}/webgl/interaction.js +7 -6
  104. package/dist/webgl/light.js +40 -0
  105. package/{src → dist}/webgl/loading.js +45 -12
  106. package/dist/webgl/material.js +40 -0
  107. package/dist/webgl/p5.Camera.js +40 -0
  108. package/{src → dist}/webgl/p5.DataArray.js +3 -5
  109. package/dist/webgl/p5.Framebuffer.js +40 -0
  110. package/{src → dist}/webgl/p5.Geometry.js +12 -15
  111. package/{src → dist}/webgl/p5.Quat.js +5 -4
  112. package/{src → dist}/webgl/p5.RenderBuffer.js +2 -3
  113. package/dist/webgl/p5.RendererGL.js +40 -0
  114. package/dist/webgl/p5.Shader.js +40 -0
  115. package/dist/webgl/p5.Texture.js +40 -0
  116. package/{src → dist}/webgl/text.js +78 -38
  117. package/lib/p5.esm.js +296 -194
  118. package/lib/p5.js +296 -194
  119. package/lib/p5.min.js +1 -1
  120. package/package.json +17 -17
  121. package/translations/dev.js +6 -6
  122. package/translations/index.js +1 -1
  123. package/types/accessibility/color_namer.d.ts +8 -0
  124. package/types/accessibility/describe.d.ts +184 -0
  125. package/types/accessibility/gridOutput.d.ts +8 -0
  126. package/types/accessibility/outputs.d.ts +235 -0
  127. package/types/accessibility/textOutput.d.ts +8 -0
  128. package/types/color/color_conversion.d.ts +47 -0
  129. package/types/color/creating_reading.d.ts +1348 -0
  130. package/types/color/p5.Color.d.ts +1070 -0
  131. package/types/color/setting.d.ts +2085 -0
  132. package/types/core/constants.d.ts +341 -0
  133. package/types/core/environment.d.ts +668 -0
  134. package/types/core/friendly_errors/fes_core.d.ts +8 -0
  135. package/types/core/friendly_errors/file_errors.d.ts +8 -0
  136. package/types/core/friendly_errors/param_validator.d.ts +30 -0
  137. package/types/core/friendly_errors/sketch_reader.d.ts +8 -0
  138. package/types/core/friendly_errors/stacktrace.d.ts +11 -0
  139. package/types/core/friendly_errors/validate_params.d.ts +8 -0
  140. package/types/core/helpers.d.ts +8 -0
  141. package/types/core/legacy.d.ts +8 -0
  142. package/types/core/main.d.ts +5996 -0
  143. package/types/core/p5.Graphics.d.ts +484 -0
  144. package/types/core/p5.Renderer.d.ts +14 -0
  145. package/types/core/reference.d.ts +8 -0
  146. package/types/core/rendering.d.ts +481 -0
  147. package/types/core/structure.d.ts +492 -0
  148. package/types/core/transform.d.ts +1638 -0
  149. package/types/data/local_storage.d.ts +323 -0
  150. package/types/dom/dom.d.ts +1295 -0
  151. package/types/dom/p5.Element.d.ts +2011 -0
  152. package/types/dom/p5.File.d.ts +13 -0
  153. package/types/dom/p5.MediaElement.d.ts +1249 -0
  154. package/types/events/acceleration.d.ts +193 -0
  155. package/types/events/keyboard.d.ts +499 -0
  156. package/types/events/pointer.d.ts +782 -0
  157. package/types/global.d.ts +5542 -0
  158. package/types/image/filterRenderer2D.d.ts +54 -0
  159. package/types/image/image.d.ts +326 -0
  160. package/types/image/loading_displaying.d.ts +580 -0
  161. package/types/image/p5.Image.d.ts +5882 -0
  162. package/types/image/pixels.d.ts +832 -0
  163. package/types/io/files.d.ts +1447 -0
  164. package/types/io/p5.Table.d.ts +1247 -0
  165. package/types/io/p5.TableRow.d.ts +343 -0
  166. package/types/io/p5.XML.d.ts +1188 -0
  167. package/types/math/Matrices/Matrix.d.ts +1029 -0
  168. package/types/math/Matrices/MatrixNumjs.d.ts +8 -0
  169. package/types/math/calculation.d.ts +923 -0
  170. package/types/math/math.d.ts +90 -0
  171. package/types/math/noise.d.ts +311 -0
  172. package/types/math/p5.Matrix.d.ts +8 -0
  173. package/types/math/p5.Vector.d.ts +3416 -0
  174. package/types/math/random.d.ts +267 -0
  175. package/types/math/trigonometry.d.ts +663 -0
  176. package/types/p5.d.ts +6663 -0
  177. package/types/shape/2d_primitives.d.ts +1033 -0
  178. package/types/shape/attributes.d.ts +466 -0
  179. package/types/shape/curves.d.ts +740 -0
  180. package/types/shape/custom_shapes.d.ts +888 -0
  181. package/types/shape/vertex.d.ts +1141 -0
  182. package/types/type/p5.Font.d.ts +575 -0
  183. package/types/type/textCore.d.ts +1198 -0
  184. package/types/utilities/conversion.d.ts +894 -0
  185. package/types/utilities/time_date.d.ts +295 -0
  186. package/types/utilities/utility_functions.d.ts +587 -0
  187. package/types/webgl/3d_primitives.d.ts +1432 -0
  188. package/types/webgl/ShaderGenerator.d.ts +8 -0
  189. package/types/webgl/interaction.d.ts +371 -0
  190. package/types/webgl/light.d.ts +1184 -0
  191. package/types/webgl/loading.d.ts +481 -0
  192. package/types/webgl/material.d.ts +2656 -0
  193. package/types/webgl/p5.Camera.d.ts +3023 -0
  194. package/types/webgl/p5.DataArray.d.ts +61 -0
  195. package/types/webgl/p5.Framebuffer.d.ts +760 -0
  196. package/types/webgl/p5.Geometry.d.ts +1191 -0
  197. package/types/webgl/p5.Quat.d.ts +45 -0
  198. package/types/webgl/p5.RendererGL.d.ts +234 -0
  199. package/types/webgl/p5.Shader.d.ts +660 -0
  200. package/types/webgl/p5.Texture.d.ts +61 -0
  201. package/types/webgl/text.d.ts +74 -0
  202. package/src/README.md +0 -27
  203. package/src/accessibility/index.js +0 -13
  204. package/src/app.js +0 -61
  205. package/src/color/index.js +0 -9
  206. package/src/color/p5.Color.culori.js +0 -66
  207. package/src/color/p5.Color.js +0 -851
  208. package/src/core/README.md +0 -91
  209. package/src/core/friendly_errors/index.js +0 -13
  210. package/src/core/friendly_errors/param_validator.js +0 -561
  211. package/src/core/init.js +0 -58
  212. package/src/core/internationalization.js +0 -195
  213. package/src/core/legacy.js +0 -29
  214. package/src/core/main.js +0 -689
  215. package/src/core/noop.js +0 -1
  216. package/src/core/p5.Graphics.js +0 -696
  217. package/src/core/p5.Renderer.js +0 -408
  218. package/src/core/reference.js +0 -2060
  219. package/src/core/rendering.js +0 -697
  220. package/src/dom/index.js +0 -11
  221. package/src/image/const.js +0 -6
  222. package/src/image/image.js +0 -731
  223. package/src/image/index.js +0 -15
  224. package/src/image/loading_displaying.js +0 -1431
  225. package/src/io/files.js +0 -2210
  226. package/src/io/index.js +0 -11
  227. package/src/math/README.md +0 -40
  228. package/src/type/index.js +0 -9
  229. package/src/webgl/3d_primitives.js +0 -2741
  230. package/src/webgl/index.js +0 -37
  231. package/src/webgl/light.js +0 -1851
  232. package/src/webgl/material.js +0 -3854
  233. package/src/webgl/p5.Camera.js +0 -4010
  234. package/src/webgl/p5.Framebuffer.js +0 -1865
  235. package/src/webgl/p5.RendererGL.js +0 -2867
  236. package/src/webgl/p5.Shader.js +0 -1505
  237. package/src/webgl/p5.Texture.js +0 -541
  238. package/src/webgl/shaders/basic.frag +0 -6
  239. package/src/webgl/shaders/filters/base.frag +0 -22
  240. package/src/webgl/shaders/filters/base.vert +0 -19
  241. package/src/webgl/shaders/filters/blur.frag +0 -60
  242. package/src/webgl/shaders/filters/default.vert +0 -18
  243. package/src/webgl/shaders/filters/dilate.frag +0 -39
  244. package/src/webgl/shaders/filters/erode.frag +0 -39
  245. package/src/webgl/shaders/filters/gray.frag +0 -16
  246. package/src/webgl/shaders/filters/invert.frag +0 -15
  247. package/src/webgl/shaders/filters/opaque.frag +0 -12
  248. package/src/webgl/shaders/filters/posterize.frag +0 -29
  249. package/src/webgl/shaders/filters/threshold.frag +0 -23
  250. package/src/webgl/shaders/font.frag +0 -216
  251. package/src/webgl/shaders/font.vert +0 -44
  252. package/src/webgl/shaders/imageLight.vert +0 -33
  253. package/src/webgl/shaders/imageLightDiffused.frag +0 -82
  254. package/src/webgl/shaders/imageLightSpecular.frag +0 -134
  255. package/src/webgl/shaders/light.vert +0 -37
  256. package/src/webgl/shaders/light_texture.frag +0 -26
  257. package/src/webgl/shaders/lighting.glsl +0 -227
  258. package/src/webgl/shaders/line.frag +0 -74
  259. package/src/webgl/shaders/line.vert +0 -294
  260. package/src/webgl/shaders/normal.frag +0 -6
  261. package/src/webgl/shaders/normal.vert +0 -72
  262. package/src/webgl/shaders/phong.frag +0 -84
  263. package/src/webgl/shaders/phong.vert +0 -87
  264. package/src/webgl/shaders/point.frag +0 -29
  265. package/src/webgl/shaders/point.vert +0 -19
  266. package/src/webgl/shaders/sphereMapping.frag +0 -26
  267. package/src/webgl/shaders/webgl2Compatibility.glsl +0 -34
package/lib/p5.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! p5.js v2.0.0 April 17, 2025 */
1
+ /*! p5.js v2.0.2 May 14, 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.0';
15
+ const VERSION = '2.0.2';
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>
@@ -52867,7 +52888,7 @@ var lightTextureFrag = "uniform vec4 uTint;\nuniform sampler2D uSampler;\nunifor
52867
52888
 
52868
52889
  var phongVert = "precision highp int;\n\n#define HOOK_DEFINES\n\nIN vec3 aPosition;\nIN vec3 aNormal;\nIN vec2 aTexCoord;\nIN vec4 aVertexColor;\n\nuniform vec3 uAmbientColor[5];\n\n#ifdef AUGMENTED_HOOK_getWorldInputs\nuniform mat4 uModelMatrix;\nuniform mat4 uViewMatrix;\nuniform mat3 uModelNormalMatrix;\nuniform mat3 uCameraNormalMatrix;\n#else\nuniform mat4 uModelViewMatrix;\nuniform mat3 uNormalMatrix;\n#endif\nuniform mat4 uProjectionMatrix;\nuniform int uAmbientLightCount;\n\nuniform bool uUseVertexColor;\nuniform vec4 uMaterialColor;\n\nOUT vec3 vNormal;\nOUT vec2 vTexCoord;\nOUT vec3 vViewPosition;\nOUT vec3 vAmbientColor;\nOUT vec4 vColor;\n\nstruct Vertex {\n vec3 position;\n vec3 normal;\n vec2 texCoord;\n vec4 color;\n};\n\nvoid main(void) {\n HOOK_beforeVertex();\n\n Vertex inputs;\n inputs.position = aPosition;\n inputs.normal = aNormal;\n inputs.texCoord = aTexCoord;\n inputs.color = (uUseVertexColor && aVertexColor.x >= 0.0) ? aVertexColor : uMaterialColor;\n#ifdef AUGMENTED_HOOK_getObjectInputs\n inputs = HOOK_getObjectInputs(inputs);\n#endif\n\n#ifdef AUGMENTED_HOOK_getWorldInputs\n inputs.position = (uModelMatrix * vec4(inputs.position, 1.)).xyz;\n inputs.normal = uModelNormalMatrix * inputs.normal;\n inputs = HOOK_getWorldInputs(inputs);\n#endif\n\n#ifdef AUGMENTED_HOOK_getWorldInputs\n // Already multiplied by the model matrix, just apply view\n inputs.position = (uViewMatrix * vec4(inputs.position, 1.)).xyz;\n inputs.normal = uCameraNormalMatrix * inputs.normal;\n#else\n // Apply both at once\n inputs.position = (uModelViewMatrix * vec4(inputs.position, 1.)).xyz;\n inputs.normal = uNormalMatrix * inputs.normal;\n#endif\n#ifdef AUGMENTED_HOOK_getCameraInputs\n inputs = HOOK_getCameraInputs(inputs);\n#endif\n\n // Pass varyings to fragment shader\n vViewPosition = inputs.position;\n vTexCoord = inputs.texCoord;\n vNormal = inputs.normal;\n vColor = inputs.color;\n\n // TODO: this should be a uniform\n vAmbientColor = vec3(0.0);\n for (int i = 0; i < 5; i++) {\n if (i < uAmbientLightCount) {\n vAmbientColor += uAmbientColor[i];\n }\n }\n\n gl_Position = uProjectionMatrix * vec4(inputs.position, 1.);\n HOOK_afterVertex();\n}\n";
52869
52890
 
52870
- var phongFrag = "// include lighting.glsl\nprecision highp int;\n\nuniform bool uHasSetAmbient;\nuniform vec4 uSpecularMatColor;\nuniform vec4 uAmbientMatColor;\nuniform vec4 uEmissiveMatColor;\n\nuniform vec4 uTint;\nuniform sampler2D uSampler;\nuniform bool isTexture;\n\nIN vec3 vNormal;\nIN vec2 vTexCoord;\nIN vec3 vViewPosition;\nIN vec3 vAmbientColor;\nIN vec4 vColor;\n\nstruct ColorComponents {\n vec3 baseColor;\n float opacity;\n vec3 ambientColor;\n vec3 specularColor;\n vec3 diffuse;\n vec3 ambient;\n vec3 specular;\n vec3 emissive;\n};\n\nstruct Inputs {\n vec3 normal;\n vec2 texCoord;\n vec3 ambientLight;\n vec3 ambientMaterial;\n vec3 specularMaterial;\n vec3 emissiveMaterial;\n vec4 color;\n float shininess;\n float metalness;\n};\n\nvoid main(void) {\n HOOK_beforeFragment();\n\n Inputs inputs;\n inputs.normal = normalize(vNormal);\n inputs.texCoord = vTexCoord;\n inputs.ambientLight = vAmbientColor;\n inputs.color = isTexture\n ? TEXTURE(uSampler, vTexCoord) * uTint/255.\n : vColor;\n if (isTexture && inputs.color.a > 0.0) {\n // Textures come in with premultiplied alpha. Temporarily unpremultiply it\n // so hooks users don't have to think about premultiplied alpha.\n inputs.color.rgb /= inputs.color.a;\n }\n inputs.shininess = uShininess;\n inputs.metalness = uMetallic;\n inputs.ambientMaterial = uHasSetAmbient ? uAmbientMatColor.rgb : inputs.color.rgb;\n inputs.specularMaterial = uSpecularMatColor.rgb;\n inputs.emissiveMaterial = uEmissiveMatColor.rgb;\n inputs = HOOK_getPixelInputs(inputs);\n\n vec3 diffuse;\n vec3 specular;\n totalLight(vViewPosition, inputs.normal, inputs.shininess, inputs.metalness, diffuse, specular);\n\n // Calculating final color as result of all lights (plus emissive term).\n\n vec2 texCoord = inputs.texCoord;\n vec4 baseColor = inputs.color;\n ColorComponents c;\n c.opacity = baseColor.a;\n c.baseColor = baseColor.rgb;\n c.ambientColor = inputs.ambientMaterial;\n c.specularColor = inputs.specularMaterial;\n c.diffuse = diffuse;\n c.ambient = inputs.ambientLight;\n c.specular = specular;\n c.emissive = inputs.emissiveMaterial;\n OUT_COLOR = HOOK_getFinalColor(HOOK_combineColors(c));\n OUT_COLOR.rgb *= OUT_COLOR.a; // Premultiply alpha before rendering\n HOOK_afterFragment();\n}\n";
52891
+ var phongFrag = "// include lighting.glsl\nprecision highp int;\n\nuniform bool uHasSetAmbient;\nuniform vec4 uSpecularMatColor;\nuniform vec4 uAmbientMatColor;\nuniform vec4 uEmissiveMatColor;\n\nuniform vec4 uTint;\nuniform sampler2D uSampler;\nuniform bool isTexture;\n\nIN vec3 vNormal;\nIN vec2 vTexCoord;\nIN vec3 vViewPosition;\nIN vec3 vAmbientColor;\nIN vec4 vColor;\n\nstruct ColorComponents {\n vec3 baseColor;\n float opacity;\n vec3 ambientColor;\n vec3 specularColor;\n vec3 diffuse;\n vec3 ambient;\n vec3 specular;\n vec3 emissive;\n};\n\nstruct Inputs {\n vec3 normal;\n vec2 texCoord;\n vec3 ambientLight;\n vec3 ambientMaterial;\n vec3 specularMaterial;\n vec3 emissiveMaterial;\n vec4 color;\n float shininess;\n float metalness;\n};\n\nvoid main(void) {\n HOOK_beforeFragment();\n\n Inputs inputs;\n inputs.normal = normalize(vNormal);\n inputs.texCoord = vTexCoord;\n inputs.ambientLight = vAmbientColor;\n inputs.color = isTexture\n ? TEXTURE(uSampler, vTexCoord) * (vec4(uTint.rgb/255., 1.) * uTint.a/255.)\n : vColor;\n if (isTexture && inputs.color.a > 0.0) {\n // Textures come in with premultiplied alpha. Temporarily unpremultiply it\n // so hooks users don't have to think about premultiplied alpha.\n inputs.color.rgb /= inputs.color.a;\n }\n inputs.shininess = uShininess;\n inputs.metalness = uMetallic;\n inputs.ambientMaterial = uHasSetAmbient ? uAmbientMatColor.rgb : inputs.color.rgb;\n inputs.specularMaterial = uSpecularMatColor.rgb;\n inputs.emissiveMaterial = uEmissiveMatColor.rgb;\n inputs = HOOK_getPixelInputs(inputs);\n\n vec3 diffuse;\n vec3 specular;\n totalLight(vViewPosition, inputs.normal, inputs.shininess, inputs.metalness, diffuse, specular);\n\n // Calculating final color as result of all lights (plus emissive term).\n\n vec2 texCoord = inputs.texCoord;\n vec4 baseColor = inputs.color;\n ColorComponents c;\n c.opacity = baseColor.a;\n c.baseColor = baseColor.rgb;\n c.ambientColor = inputs.ambientMaterial;\n c.specularColor = inputs.specularMaterial;\n c.diffuse = diffuse;\n c.ambient = inputs.ambientLight;\n c.specular = specular;\n c.emissive = inputs.emissiveMaterial;\n OUT_COLOR = HOOK_getFinalColor(HOOK_combineColors(c));\n OUT_COLOR.rgb *= OUT_COLOR.a; // Premultiply alpha before rendering\n HOOK_afterFragment();\n}\n";
52871
52892
 
52872
52893
  var fontVert = "IN vec3 aPosition;\nIN vec2 aTexCoord;\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\n\nuniform vec4 uGlyphRect;\nuniform float uGlyphOffset;\n\nOUT vec2 vTexCoord;\nOUT float w;\n\nvoid main() {\n vec4 positionVec4 = vec4(aPosition, 1.0);\n\n // scale by the size of the glyph's rectangle\n positionVec4.xy *= uGlyphRect.zw - uGlyphRect.xy;\n\n // Expand glyph bounding boxes by 1px on each side to give a bit of room\n // for antialiasing\n vec3 newOrigin = (uModelViewMatrix * vec4(0., 0., 0., 1.)).xyz;\n vec3 newDX = (uModelViewMatrix * vec4(1., 0., 0., 1.)).xyz;\n vec3 newDY = (uModelViewMatrix * vec4(0., 1., 0., 1.)).xyz;\n vec2 pixelScale = vec2(\n 1. / length(newOrigin - newDX),\n 1. / length(newOrigin - newDY)\n );\n vec2 offset = pixelScale * normalize(aTexCoord - vec2(0.5, 0.5));\n vec2 textureOffset = offset * (1. / vec2(\n uGlyphRect.z - uGlyphRect.x,\n uGlyphRect.w - uGlyphRect.y\n ));\n\n // move to the corner of the glyph\n positionVec4.xy += uGlyphRect.xy;\n\n // move to the letter's line offset\n positionVec4.x += uGlyphOffset;\n\n positionVec4.xy += offset;\n \n gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;\n vTexCoord = aTexCoord + textureOffset;\n w = gl_Position.w;\n}\n";
52873
52894
 
@@ -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
  *
@@ -65646,6 +65666,7 @@ function graphics(p5, fn){
65646
65666
  attributes(p5, p5.Graphics.prototype);
65647
65667
  curves(p5, p5.Graphics.prototype);
65648
65668
  vertex(p5, p5.Graphics.prototype);
65669
+ customShapes(p5, p5.Graphics.prototype);
65649
65670
 
65650
65671
  setting(p5, p5.Graphics.prototype);
65651
65672
  loadingDisplaying(p5, p5.Graphics.prototype);
@@ -65841,6 +65862,7 @@ class Texture {
65841
65862
  // FramebufferTexture instances wrap raw WebGL textures already, which
65842
65863
  // don't need any extra updating, as they already live on the GPU
65843
65864
  if (this.isFramebufferTexture) {
65865
+ this.src.update();
65844
65866
  return false;
65845
65867
  }
65846
65868
 
@@ -66232,6 +66254,10 @@ class FramebufferTexture {
66232
66254
  return this.framebuffer.height * this.framebuffer.density;
66233
66255
  }
66234
66256
 
66257
+ update() {
66258
+ this.framebuffer._update(this.property);
66259
+ }
66260
+
66235
66261
  rawTexture() {
66236
66262
  return this.framebuffer[this.property];
66237
66263
  }
@@ -66244,6 +66270,8 @@ class Framebuffer {
66244
66270
 
66245
66271
  this._isClipApplied = false;
66246
66272
 
66273
+ this.dirty = { colorTexture: false, depthTexture: false };
66274
+
66247
66275
  this.pixels = [];
66248
66276
 
66249
66277
  this.format = settings.format || UNSIGNED_BYTE;
@@ -67283,6 +67311,49 @@ class Framebuffer {
67283
67311
  }
67284
67312
  }
67285
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
+
67286
67357
  /**
67287
67358
  * Ensures that the framebuffer is ready to be drawn to
67288
67359
  *
@@ -67304,27 +67375,7 @@ class Framebuffer {
67304
67375
  */
67305
67376
  _beforeEnd() {
67306
67377
  if (this.antialias) {
67307
- const gl = this.gl;
67308
- gl.bindFramebuffer(gl.READ_FRAMEBUFFER, this.aaFramebuffer);
67309
- gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, this.framebuffer);
67310
- const partsToCopy = [
67311
- [gl.COLOR_BUFFER_BIT, this.colorP5Texture.glMagFilter]
67312
- ];
67313
- if (this.useDepth) {
67314
- partsToCopy.push(
67315
- [gl.DEPTH_BUFFER_BIT, this.depthP5Texture.glMagFilter]
67316
- );
67317
- }
67318
- for (const [flag, filter] of partsToCopy) {
67319
- gl.blitFramebuffer(
67320
- 0, 0,
67321
- this.width * this.density, this.height * this.density,
67322
- 0, 0,
67323
- this.width * this.density, this.height * this.density,
67324
- flag,
67325
- filter
67326
- );
67327
- }
67378
+ this.dirty = { colorTexture: true, depthTexture: true };
67328
67379
  }
67329
67380
  }
67330
67381
 
@@ -67504,6 +67555,7 @@ class Framebuffer {
67504
67555
  * </div>
67505
67556
  */
67506
67557
  loadPixels() {
67558
+ this._update('colorTexture');
67507
67559
  const gl = this.gl;
67508
67560
  const prevFramebuffer = this.renderer.activeFramebuffer();
67509
67561
  gl.bindFramebuffer(gl.FRAMEBUFFER, this.framebuffer);
@@ -67562,6 +67614,7 @@ class Framebuffer {
67562
67614
  * @return {Number[]} color of the pixel at `(x, y)` as an array of color values `[R, G, B, A]`.
67563
67615
  */
67564
67616
  get(x, y, w, h) {
67617
+ this._update('colorTexture');
67565
67618
  // p5._validateParameters('p5.Framebuffer.get', arguments);
67566
67619
  const colorFormat = this._glColorFormat();
67567
67620
  if (x === undefined && y === undefined) {
@@ -67728,6 +67781,7 @@ class Framebuffer {
67728
67781
  this.pixels
67729
67782
  );
67730
67783
  this.colorP5Texture.unbindTexture();
67784
+ this.dirty.colorTexture = false;
67731
67785
 
67732
67786
  const prevFramebuffer = this.renderer.activeFramebuffer();
67733
67787
  if (this.antialias) {
@@ -70086,9 +70140,10 @@ function renderer2D(p5, fn){
70086
70140
  * a p5 sketch. It expects an incoming sketch closure and it can also
70087
70141
  * take an optional node parameter for attaching the generated p5 canvas
70088
70142
  * to a node. The sketch closure takes the newly created p5 instance as
70089
- * its sole argument and may optionally set <a href="#/p5/preload">preload()</a>,
70090
- * <a href="#/p5/setup">setup()</a>, and/or
70091
- * <a href="#/p5/draw">draw()</a> properties on it for running a sketch.
70143
+ * its sole argument and may optionally set an asynchronous function
70144
+ * using `async/await`, along with the standard <a href="#/p5/setup">setup()</a>,
70145
+ * and/or <a href="#/p5/setup">setup()</a>, and/or <a href="#/p5/draw">draw()</a>
70146
+ * properties on it for running a sketch.
70092
70147
  *
70093
70148
  * A p5 sketch can run in "global" or "instance" mode:
70094
70149
  * "global" - all properties and methods are attached to the window
@@ -70209,10 +70264,11 @@ let p5$2 = class p5 {
70209
70264
  bindGlobal(p);
70210
70265
  }
70211
70266
 
70267
+ const protectedProperties = ['constructor', 'length'];
70212
70268
  // Attach its properties to the window
70213
70269
  for (const p in this) {
70214
70270
  if (this.hasOwnProperty(p)) {
70215
- if(p[0] === '_') continue;
70271
+ if(p[0] === '_' || protectedProperties.includes(p)) continue;
70216
70272
  bindGlobal(p);
70217
70273
  }
70218
70274
  }
@@ -70534,9 +70590,15 @@ for (const k in constants) {
70534
70590
  * ```
70535
70591
  *
70536
70592
  * Code placed in `setup()` will run once before code placed in
70537
- * <a href="#/p5/draw">draw()</a> begins looping. If the
70538
- * <a href="#/p5/preload">preload()</a> is declared, then `setup()` will
70539
- * run immediately after <a href="#/p5/preload">preload()</a> finishes
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
+
70601
+ *
70540
70602
  * loading assets.
70541
70603
  *
70542
70604
  * Note: `setup()` doesn’t have to be declared, but it’s common practice to do so.
@@ -70607,7 +70669,6 @@ for (const k in constants) {
70607
70669
  * </code>
70608
70670
  * </div>
70609
70671
  */
70610
-
70611
70672
  /**
70612
70673
  * A function that's called repeatedly while the sketch runs.
70613
70674
  *
@@ -70835,6 +70896,11 @@ function describe(p5, fn){
70835
70896
  *
70836
70897
  * <div>
70837
70898
  * <code>
70899
+ *
70900
+ * function setup(){
70901
+ * createCanvas(100, 100);
70902
+ * };
70903
+ *
70838
70904
  * function draw() {
70839
70905
  * background(200);
70840
70906
  *
@@ -70856,6 +70922,11 @@ function describe(p5, fn){
70856
70922
  *
70857
70923
  * <div>
70858
70924
  * <code>
70925
+ *
70926
+ * function setup(){
70927
+ * createCanvas(100, 100);
70928
+ * }
70929
+ *
70859
70930
  * function draw() {
70860
70931
  * background(200);
70861
70932
  *
@@ -71628,6 +71699,11 @@ function outputs(p5, fn){
71628
71699
  *
71629
71700
  * <div>
71630
71701
  * <code>
71702
+ *
71703
+ * function setup(){
71704
+ * createCanvas(100, 100);
71705
+ * }
71706
+ *
71631
71707
  * function draw() {
71632
71708
  * // Add the text description.
71633
71709
  * textOutput();
@@ -71648,6 +71724,11 @@ function outputs(p5, fn){
71648
71724
  *
71649
71725
  * <div>
71650
71726
  * <code>
71727
+ *
71728
+ * function setup(){
71729
+ * createCanvas(100, 100);
71730
+ * }
71731
+ *
71651
71732
  * function draw() {
71652
71733
  * // Add the text description and
71653
71734
  * // display it for debugging.
@@ -71762,6 +71843,11 @@ function outputs(p5, fn){
71762
71843
  *
71763
71844
  * <div>
71764
71845
  * <code>
71846
+ *
71847
+ * function setup() {
71848
+ * createCanvas(100, 100);
71849
+ * }
71850
+ *
71765
71851
  * function draw() {
71766
71852
  * // Add the grid description.
71767
71853
  * gridOutput();
@@ -71782,6 +71868,11 @@ function outputs(p5, fn){
71782
71868
  *
71783
71869
  * <div>
71784
71870
  * <code>
71871
+ *
71872
+ * function setup(){
71873
+ * createCanvas(100, 100);
71874
+ * }
71875
+ *
71785
71876
  * function draw() {
71786
71877
  * // Add the grid description and
71787
71878
  * // display it for debugging.
@@ -71802,6 +71893,7 @@ function outputs(p5, fn){
71802
71893
  * </div>
71803
71894
  */
71804
71895
 
71896
+
71805
71897
  fn.gridOutput = function(display) {
71806
71898
  // p5._validateParameters('gridOutput', arguments);
71807
71899
  //if gridOutput is already true
@@ -76716,7 +76808,7 @@ function fesCore(p5, fn){
76716
76808
  // actual name with correct capitalization doesnt exist in context,
76717
76809
  // and if the user-defined symbol is of the type function
76718
76810
  if (
76719
- fxns[lowercase] &&
76811
+ fxns.hasOwnProperty(lowercase) &&
76720
76812
  !context[fxns[lowercase]] &&
76721
76813
  typeof context[prop] === 'function'
76722
76814
  ) {
@@ -82759,7 +82851,7 @@ var p5$1 = {
82759
82851
  image: {
82760
82852
  overloads: [
82761
82853
  [
82762
- "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",
82763
82855
  "Number",
82764
82856
  "Number",
82765
82857
  "Number?",
@@ -83257,7 +83349,7 @@ var p5$1 = {
83257
83349
  createVector: {
83258
83350
  overloads: [
83259
83351
  [
83260
- null
83352
+ "...Number[]"
83261
83353
  ]
83262
83354
  ]
83263
83355
  },
@@ -86865,9 +86957,14 @@ function validateParams(p5, fn, lifecycles) {
86865
86957
  const isOptional = param?.endsWith('?');
86866
86958
  param = param?.replace(/\?$/, '');
86867
86959
 
86868
- let schema = generateTypeSchema(param);
86960
+ const isRest = param?.startsWith('...') && param?.endsWith('[]');
86961
+ param = param?.replace(/^\.\.\.(.+)\[\]$/, '$1');
86869
86962
 
86870
- return isOptional ? schema.optional() : schema;
86963
+ let schema = generateTypeSchema(param);
86964
+ if (isOptional) {
86965
+ schema = schema.optional();
86966
+ }
86967
+ return { schema, rest: isRest };
86871
86968
  };
86872
86969
 
86873
86970
  // Note that in Zod, `optional()` only checks for undefined, not the absence
@@ -86901,14 +86998,22 @@ function validateParams(p5, fn, lifecycles) {
86901
86998
  const overloadSchemas = overloads.flatMap(overload => {
86902
86999
  const combinations = generateOverloadCombinations(overload);
86903
87000
 
86904
- return combinations.map(combo =>
86905
- tupleType(
86906
- combo
86907
- .map(p => generateParamSchema(p))
86908
- // For now, ignore schemas that cannot be mapped to a defined type
86909
- .filter(schema => schema !== undefined)
86910
- )
86911
- );
87001
+ return combinations.map(combo => {
87002
+ const params = combo
87003
+ .map(p => generateParamSchema(p))
87004
+ .filter(s => s.schema !== undefined);
87005
+
87006
+ let rest;
87007
+ if (params.at(-1)?.rest) {
87008
+ rest = params.pop();
87009
+ }
87010
+
87011
+ let combined = tupleType(params.map(s => s.schema));
87012
+ if (rest) {
87013
+ combined = combined.rest(rest.schema);
87014
+ }
87015
+ return combined;
87016
+ });
86912
87017
  });
86913
87018
 
86914
87019
  return overloadSchemas.length === 1
@@ -87143,7 +87248,7 @@ function validateParams(p5, fn, lifecycles) {
87143
87248
  // theoretically allowed to stay undefined and valid, it is likely that the
87144
87249
  // user intended to call the function with non-undefined arguments. Skip
87145
87250
  // regular workflow and return a friendly error message right away.
87146
- if (Array.isArray(args) && args.every(arg => arg === undefined)) {
87251
+ if (Array.isArray(args) && args.length > 0 && args.every(arg => arg === undefined)) {
87147
87252
  const undefinedErrorMessage = `🌸 p5.js says: All arguments for ${func}() are undefined. There is likely an error in the code.`;
87148
87253
 
87149
87254
  return {
@@ -94766,7 +94871,7 @@ function dom$1(p5, fn){
94766
94871
  * let slider;
94767
94872
  *
94768
94873
  * function setup() {
94769
- * createCanvas(100, 100);
94874
+ * createCanvas(200, 200);
94770
94875
  *
94771
94876
  * // Create a paragraph element and place
94772
94877
  * // it at the top of the canvas.
@@ -95007,10 +95112,10 @@ function dom$1(p5, fn){
95007
95112
  * background(200);
95008
95113
  *
95009
95114
  * let img = createImg(
95010
- * 'https://p5js.org/assets/img/asterisk-01.png',
95011
- * 'The p5.js magenta asterisk.'
95115
+ * '/assets/cat.jpg',
95116
+ * 'image of a cat'
95012
95117
  * );
95013
- * img.position(0, -10);
95118
+ * img.position(0, 10);
95014
95119
  *
95015
95120
  * describe('A gray square with a magenta asterisk in its center.');
95016
95121
  * }
@@ -95359,7 +95464,7 @@ function dom$1(p5, fn){
95359
95464
  *
95360
95465
  * // Create a checkbox and place it beneath the canvas.
95361
95466
  * checkbox = createCheckbox();
95362
- * checkbox.position(0, 100);
95467
+ * checkbox.position(0, 70);
95363
95468
  *
95364
95469
  * describe('A black square with a checkbox beneath it. The square turns white when the box is checked.');
95365
95470
  * }
@@ -95385,7 +95490,7 @@ function dom$1(p5, fn){
95385
95490
  * // Create a checkbox and place it beneath the canvas.
95386
95491
  * // Label the checkbox "white".
95387
95492
  * checkbox = createCheckbox(' white');
95388
- * checkbox.position(0, 100);
95493
+ * checkbox.position(0, 70);
95389
95494
  *
95390
95495
  * describe('A black square with a checkbox labeled "white" beneath it. The square turns white when the box is checked.');
95391
95496
  * }
@@ -95411,7 +95516,7 @@ function dom$1(p5, fn){
95411
95516
  * // Create a checkbox and place it beneath the canvas.
95412
95517
  * // Label the checkbox "white" and set its value to true.
95413
95518
  * checkbox = createCheckbox(' white', true);
95414
- * checkbox.position(0, 100);
95519
+ * checkbox.position(0, 70);
95415
95520
  *
95416
95521
  * describe('A white square with a checkbox labeled "white" beneath it. The square turns black when the box is unchecked.');
95417
95522
  * }
@@ -96290,7 +96395,7 @@ function dom$1(p5, fn){
96290
96395
  * let img;
96291
96396
  *
96292
96397
  * function setup() {
96293
- * createCanvas(100, 100);
96398
+ * createCanvas(200, 200);
96294
96399
  *
96295
96400
  * // Create a file input and place it beneath
96296
96401
  * // the canvas.
@@ -96544,18 +96649,18 @@ function acceleration(p5, fn){
96544
96649
  * @example
96545
96650
  * <div>
96546
96651
  * <code>
96652
+ * let rotationX = 0; // Angle in degrees
96653
+ *
96547
96654
  * function setup() {
96548
- * createCanvas(100, 100, WEBGL);
96655
+ * createCanvas(200, 200, WEBGL); // Create 3D canvas
96549
96656
  * }
96550
96657
  *
96551
96658
  * function draw() {
96552
- * background(200);
96553
- * //rotateZ(radians(rotationZ));
96554
- * rotateX(radians(rotationX));
96555
- * //rotateY(radians(rotationY));
96556
- * box(200, 200, 200);
96557
- * describe(`red horizontal line right, green vertical line bottom.
96558
- * black background.`);
96659
+ * background(220); // Set light gray background
96660
+ * rotateX(radians(rotationX)); // Rotate around X-axis
96661
+ * normalMaterial(); // Apply simple shaded material
96662
+ * box(60); // Draw 3D cube (60 units wide)
96663
+ * rotationX = (rotationX + 2) % 360; // Increment rotation (2° per frame)
96559
96664
  * }
96560
96665
  * </code>
96561
96666
  * </div>
@@ -96577,18 +96682,18 @@ function acceleration(p5, fn){
96577
96682
  * @example
96578
96683
  * <div>
96579
96684
  * <code>
96685
+ * let rotationY = 0; // Angle in degrees
96686
+ *
96580
96687
  * function setup() {
96581
- * createCanvas(100, 100, WEBGL);
96688
+ * createCanvas(200, 200, WEBGL); // Create 3D canvas
96582
96689
  * }
96583
96690
  *
96584
96691
  * function draw() {
96585
- * background(200);
96586
- * //rotateZ(radians(rotationZ));
96587
- * //rotateX(radians(rotationX));
96588
- * rotateY(radians(rotationY));
96589
- * box(200, 200, 200);
96590
- * describe(`red horizontal line right, green vertical line bottom.
96591
- * black background.`);
96692
+ * background(220); // Set light gray background
96693
+ * rotateY(radians(rotationY)); // Rotate around Y-axis (vertical)
96694
+ * normalMaterial(); // Apply simple shaded material
96695
+ * box(60); // Draw 3D cube (60 units wide)
96696
+ * rotationY = (rotationY + 2) % 360; // Increment rotation (2° per frame)
96592
96697
  * }
96593
96698
  * </code>
96594
96699
  * </div>
@@ -96611,18 +96716,18 @@ function acceleration(p5, fn){
96611
96716
  * @example
96612
96717
  * <div>
96613
96718
  * <code>
96719
+ * let rotationZ = 0; // Angle in degrees
96720
+ *
96614
96721
  * function setup() {
96615
- * createCanvas(100, 100, WEBGL);
96722
+ * createCanvas(200, 200, WEBGL); // Create 3D canvas
96616
96723
  * }
96617
96724
  *
96618
96725
  * function draw() {
96619
- * background(200);
96620
- * rotateZ(radians(rotationZ));
96621
- * //rotateX(radians(rotationX));
96622
- * //rotateY(radians(rotationY));
96623
- * box(200, 200, 200);
96624
- * describe(`red horizontal line right, green vertical line bottom.
96625
- * black background.`);
96726
+ * background(220);
96727
+ * rotateZ(radians(rotationZ)); // Rotate around Z-axis
96728
+ * normalMaterial(); // Apply simple shaded material
96729
+ * box(60); // Draw 3D cube
96730
+ * rotationZ = (rotationZ + 2) % 360; // Increment rotation angle
96626
96731
  * }
96627
96732
  * </code>
96628
96733
  * </div>
@@ -97784,6 +97889,15 @@ function keyboard(p5, fn){
97784
97889
  * </div>
97785
97890
  */
97786
97891
  fn._onkeyup = function(e) {
97892
+
97893
+ const context = this._isGlobal ? window : this;
97894
+ if (typeof context.keyReleased === 'function') {
97895
+ const executeDefault = context.keyReleased(e);
97896
+ if (executeDefault === false) {
97897
+ e.preventDefault();
97898
+ }
97899
+ }
97900
+
97787
97901
  delete this._downKeyCodes[e.code];
97788
97902
  delete this._downKeys[e.key];
97789
97903
 
@@ -97800,13 +97914,6 @@ function keyboard(p5, fn){
97800
97914
  this.key = lastPressedKey;
97801
97915
  }
97802
97916
 
97803
- const context = this._isGlobal ? window : this;
97804
- if (typeof context.keyReleased === 'function') {
97805
- const executeDefault = context.keyReleased(e);
97806
- if (executeDefault === false) {
97807
- e.preventDefault();
97808
- }
97809
- }
97810
97917
  };
97811
97918
 
97812
97919
  /**
@@ -97940,7 +98047,7 @@ function keyboard(p5, fn){
97940
98047
  * </div>
97941
98048
  */
97942
98049
  fn._onkeypress = function(e) {
97943
- if (e.which === this._lastKeyCodeTyped) {
98050
+ if (e.which === this._lastKeyCodeTyped && e.repeat) {
97944
98051
  // prevent multiple firings
97945
98052
  return;
97946
98053
  }
@@ -99020,25 +99127,25 @@ function pointer(p5, fn){
99020
99127
 
99021
99128
  fn._updatePointerCoords = function (e) {
99022
99129
  if (this._curElement !== null) {
99023
- const canvas = this._curElement.elt;
99024
- const sx = canvas.scrollWidth / this.width || 1;
99025
- const sy = canvas.scrollHeight / this.height || 1;
99130
+ const canvas = this._curElement.elt;
99131
+ const sx = canvas.scrollWidth / this.width || 1;
99132
+ const sy = canvas.scrollHeight / this.height || 1;
99026
99133
 
99027
- if (e.pointerType == 'touch') {
99134
+ if (e.pointerType == 'touch') {
99028
99135
  const touches = [];
99029
99136
  for (const touch of this._activePointers.values()) {
99030
- touches.push(getTouchInfo(canvas, sx, sy, touch));
99137
+ touches.push(getTouchInfo(canvas, sx, sy, touch));
99031
99138
  }
99032
99139
  this.touches = touches;
99033
- } else {
99034
- const mousePos = getMouseInfo(canvas, sx, sy, e);
99035
- this.movedX = e.movementX || 0;
99036
- this.movedY = e.movementY || 0;
99037
- this.mouseX = mousePos.x;
99038
- this.mouseY = mousePos.y;
99039
- this.winMouseX = mousePos.winX;
99040
- this.winMouseY = mousePos.winY;
99041
- }
99140
+ }
99141
+
99142
+ const mousePos = getMouseInfo(canvas, sx, sy, e);
99143
+ this.movedX = e.movementX || 0;
99144
+ this.movedY = e.movementY || 0;
99145
+ this.mouseX = mousePos.x;
99146
+ this.mouseY = mousePos.y;
99147
+ this.winMouseX = mousePos.winX;
99148
+ this.winMouseY = mousePos.winY;
99042
99149
 
99043
99150
  if (!this._hasMouseInteracted) {
99044
99151
  this._updateMouseCoords();
@@ -101850,8 +101957,8 @@ class TableRow {
101850
101957
  * let table;
101851
101958
  *
101852
101959
  * async function setup() {
101853
- * // Create a 200x100 canvas and set a white background
101854
- * createCanvas(200, 100);
101960
+ * // Create a 300x100 canvas and set a white background
101961
+ * createCanvas(300, 100);
101855
101962
  * background(255);
101856
101963
  *
101857
101964
  * // Load the CSV file with a header row
@@ -103993,7 +104100,7 @@ function math$1(p5, fn) {
103993
104100
  * <a href="#/p5.Vector">p5.Vector</a> class.
103994
104101
  *
103995
104102
  * @method createVector
103996
- * @param {...Number} components Components of the vector.
104103
+ * @param {...Number} x Zero or more numbers, representing each component of the vector.
103997
104104
  * @return {p5.Vector} new <a href="#/p5.Vector">p5.Vector</a> object.
103998
104105
  *
103999
104106
  * @example
@@ -106059,11 +106166,10 @@ function timeDate(p5, fn){
106059
106166
  *
106060
106167
  * If a sketch has a
106061
106168
  * <a href="#/p5/setup">setup()</a> function, then `millis()` begins tracking
106062
- * time before the code in <a href="#/p5/setup">setup()</a> runs. If a
106063
- * sketch includes a <a href="#/p5/preload">preload()</a> function, then
106064
- * `millis()` begins tracking time as soon as the code in
106065
- * <a href="#/p5/preload">preload()</a> starts running.
106066
- *
106169
+ * time before the code in <a href="#/p5/setup">setup()</a> runs. If a
106170
+ * sketch includes asynchronous loading using `async`/`await`, then
106171
+ * `millis()` begins tracking time as soon as the asynchronous code
106172
+ * starts running.
106067
106173
  * @method millis
106068
106174
  * @return {Number} number of milliseconds since starting the sketch.
106069
106175
  *
@@ -109692,7 +109798,7 @@ function textCore(p5, fn) {
109692
109798
  * createCanvas(300, 300);
109693
109799
  * background(220);
109694
109800
  *
109695
- * textSize(48);
109801
+ * textSize(35);
109696
109802
  * textAlign(LEFT, BASELINE);
109697
109803
  * textFont('Georgia');
109698
109804
  *
@@ -118657,7 +118763,6 @@ const invalidFontError = 'Sorry, only TTF, OTF and WOFF files are supported.'; /
118657
118763
  const fontFaceVariations = ['weight', 'stretch', 'style'];
118658
118764
 
118659
118765
 
118660
- let nextId = 0;
118661
118766
  class Font {
118662
118767
  constructor(p, fontFace, name, path, data) {
118663
118768
  if (!(fontFace instanceof FontFace)) {
@@ -118668,7 +118773,6 @@ class Font {
118668
118773
  this.path = path;
118669
118774
  this.data = data;
118670
118775
  this.face = fontFace;
118671
- this.id = nextId++;
118672
118776
  }
118673
118777
 
118674
118778
  /**
@@ -120102,24 +120206,7 @@ if (typeof p5 !== 'undefined') {
120102
120206
  function text(p5, fn) {
120103
120207
  RendererGL.prototype.maxCachedGlyphs = function() {
120104
120208
  // TODO: use more than vibes to find a good value for this
120105
- return 200
120106
- };
120107
-
120108
- RendererGL.prototype.freeGlyphInfo = function(gi) {
120109
- const datas = [
120110
- gi.strokeImageInfo.imageData,
120111
- gi.rowInfo.cellImageInfo.imageData,
120112
- gi.rowInfo.dimImageInfo.imageData,
120113
- gi.colInfo.cellImageInfo.imageData,
120114
- gi.colInfo.dimImageInfo.imageData,
120115
- ];
120116
- for (const data of datas) {
120117
- const tex = this.textures.get(data);
120118
- if (tex) {
120119
- tex.remove();
120120
- this.textures.delete(data);
120121
- }
120122
- }
120209
+ return 200;
120123
120210
  };
120124
120211
 
120125
120212
  Font.prototype._getFontInfo = function(axs) {
@@ -120887,7 +120974,7 @@ function text(p5, fn) {
120887
120974
  sh.setUniform("uMaterialColor", curFillColor);
120888
120975
  gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
120889
120976
 
120890
- this.fontCache = this.fontCache || new Map();
120977
+ this.glyphDataCache = this.glyphDataCache || new Set();
120891
120978
 
120892
120979
  try {
120893
120980
  // fetch the glyphs in the line of text
@@ -120896,20 +120983,35 @@ function text(p5, fn) {
120896
120983
  for (const glyph of glyphs) {
120897
120984
  const gi = fontInfo.getGlyphInfo(glyph);
120898
120985
  if (gi.uGlyphRect) {
120986
+ const rowInfo = gi.rowInfo;
120987
+ const colInfo = gi.colInfo;
120988
+
120989
+ // Bump the resources for this glyph to the end of the cache list by deleting and re-adding
120990
+ const glyphResources = [
120991
+ gi.strokeImageInfo.imageData,
120992
+ rowInfo.cellImageInfo.imageData,
120993
+ rowInfo.dimImageInfo.imageData,
120994
+ colInfo.cellImageInfo.imageData,
120995
+ colInfo.dimImageInfo.imageData
120996
+ ];
120997
+ for (const resource of glyphResources) {
120998
+ this.glyphDataCache.delete(resource);
120999
+ this.glyphDataCache.add(resource);
121000
+ }
120899
121001
 
120900
- const cacheKey = JSON.stringify({ font: font.id, axs, glyph: glyph.shape.g });
120901
- // Bump this font to the end of the cache list by deleting and re-adding it
120902
- this.fontCache.delete(cacheKey);
120903
- this.fontCache.set(cacheKey, gi);
120904
- if (this.fontCache.size > this.maxCachedGlyphs()) {
120905
- const keyToRemove = this.fontCache.keys().next().value;
120906
- const val = this.fontCache.get(keyToRemove);
120907
- this.fontCache.delete(keyToRemove);
120908
- this.freeGlyphInfo(val);
121002
+ // If we have too many glyph textures, remove the least recently used
121003
+ // ones from GPU memory. The data still exists on the CPU and will be
121004
+ // re-uploaded if it gets actively used again.
121005
+ while (this.glyphDataCache.size > this.maxCachedGlyphs()) {
121006
+ const data = this.glyphDataCache.values().next().value;
121007
+ this.glyphDataCache.delete(data);
121008
+ const tex = this.textures.get(data);
121009
+ if (tex) {
121010
+ tex.remove();
121011
+ this.textures.delete(data);
121012
+ }
120909
121013
  }
120910
121014
 
120911
- const rowInfo = gi.rowInfo;
120912
- const colInfo = gi.colInfo;
120913
121015
  sh.setUniform("uSamplerStrokes", gi.strokeImageInfo.imageData);
120914
121016
  sh.setUniform("uSamplerRowStrokes", rowInfo.cellImageInfo.imageData);
120915
121017
  sh.setUniform("uSamplerRows", rowInfo.dimImageInfo.imageData);