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.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
  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.0';
18
+ const VERSION = '2.0.2';
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>
@@ -52870,7 +52891,7 @@ var p5 = (function () {
52870
52891
 
52871
52892
  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";
52872
52893
 
52873
- 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";
52894
+ 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";
52874
52895
 
52875
52896
  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";
52876
52897
 
@@ -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
  *
@@ -65649,6 +65669,7 @@ var p5 = (function () {
65649
65669
  attributes(p5, p5.Graphics.prototype);
65650
65670
  curves(p5, p5.Graphics.prototype);
65651
65671
  vertex(p5, p5.Graphics.prototype);
65672
+ customShapes(p5, p5.Graphics.prototype);
65652
65673
 
65653
65674
  setting(p5, p5.Graphics.prototype);
65654
65675
  loadingDisplaying(p5, p5.Graphics.prototype);
@@ -65844,6 +65865,7 @@ var p5 = (function () {
65844
65865
  // FramebufferTexture instances wrap raw WebGL textures already, which
65845
65866
  // don't need any extra updating, as they already live on the GPU
65846
65867
  if (this.isFramebufferTexture) {
65868
+ this.src.update();
65847
65869
  return false;
65848
65870
  }
65849
65871
 
@@ -66235,6 +66257,10 @@ var p5 = (function () {
66235
66257
  return this.framebuffer.height * this.framebuffer.density;
66236
66258
  }
66237
66259
 
66260
+ update() {
66261
+ this.framebuffer._update(this.property);
66262
+ }
66263
+
66238
66264
  rawTexture() {
66239
66265
  return this.framebuffer[this.property];
66240
66266
  }
@@ -66247,6 +66273,8 @@ var p5 = (function () {
66247
66273
 
66248
66274
  this._isClipApplied = false;
66249
66275
 
66276
+ this.dirty = { colorTexture: false, depthTexture: false };
66277
+
66250
66278
  this.pixels = [];
66251
66279
 
66252
66280
  this.format = settings.format || UNSIGNED_BYTE;
@@ -67286,6 +67314,49 @@ var p5 = (function () {
67286
67314
  }
67287
67315
  }
67288
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
+
67289
67360
  /**
67290
67361
  * Ensures that the framebuffer is ready to be drawn to
67291
67362
  *
@@ -67307,27 +67378,7 @@ var p5 = (function () {
67307
67378
  */
67308
67379
  _beforeEnd() {
67309
67380
  if (this.antialias) {
67310
- const gl = this.gl;
67311
- gl.bindFramebuffer(gl.READ_FRAMEBUFFER, this.aaFramebuffer);
67312
- gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, this.framebuffer);
67313
- const partsToCopy = [
67314
- [gl.COLOR_BUFFER_BIT, this.colorP5Texture.glMagFilter]
67315
- ];
67316
- if (this.useDepth) {
67317
- partsToCopy.push(
67318
- [gl.DEPTH_BUFFER_BIT, this.depthP5Texture.glMagFilter]
67319
- );
67320
- }
67321
- for (const [flag, filter] of partsToCopy) {
67322
- gl.blitFramebuffer(
67323
- 0, 0,
67324
- this.width * this.density, this.height * this.density,
67325
- 0, 0,
67326
- this.width * this.density, this.height * this.density,
67327
- flag,
67328
- filter
67329
- );
67330
- }
67381
+ this.dirty = { colorTexture: true, depthTexture: true };
67331
67382
  }
67332
67383
  }
67333
67384
 
@@ -67507,6 +67558,7 @@ var p5 = (function () {
67507
67558
  * </div>
67508
67559
  */
67509
67560
  loadPixels() {
67561
+ this._update('colorTexture');
67510
67562
  const gl = this.gl;
67511
67563
  const prevFramebuffer = this.renderer.activeFramebuffer();
67512
67564
  gl.bindFramebuffer(gl.FRAMEBUFFER, this.framebuffer);
@@ -67565,6 +67617,7 @@ var p5 = (function () {
67565
67617
  * @return {Number[]} color of the pixel at `(x, y)` as an array of color values `[R, G, B, A]`.
67566
67618
  */
67567
67619
  get(x, y, w, h) {
67620
+ this._update('colorTexture');
67568
67621
  // p5._validateParameters('p5.Framebuffer.get', arguments);
67569
67622
  const colorFormat = this._glColorFormat();
67570
67623
  if (x === undefined && y === undefined) {
@@ -67731,6 +67784,7 @@ var p5 = (function () {
67731
67784
  this.pixels
67732
67785
  );
67733
67786
  this.colorP5Texture.unbindTexture();
67787
+ this.dirty.colorTexture = false;
67734
67788
 
67735
67789
  const prevFramebuffer = this.renderer.activeFramebuffer();
67736
67790
  if (this.antialias) {
@@ -70089,9 +70143,10 @@ var p5 = (function () {
70089
70143
  * a p5 sketch. It expects an incoming sketch closure and it can also
70090
70144
  * take an optional node parameter for attaching the generated p5 canvas
70091
70145
  * to a node. The sketch closure takes the newly created p5 instance as
70092
- * its sole argument and may optionally set <a href="#/p5/preload">preload()</a>,
70093
- * <a href="#/p5/setup">setup()</a>, and/or
70094
- * <a href="#/p5/draw">draw()</a> properties on it for running a sketch.
70146
+ * its sole argument and may optionally set an asynchronous function
70147
+ * using `async/await`, along with the standard <a href="#/p5/setup">setup()</a>,
70148
+ * and/or <a href="#/p5/setup">setup()</a>, and/or <a href="#/p5/draw">draw()</a>
70149
+ * properties on it for running a sketch.
70095
70150
  *
70096
70151
  * A p5 sketch can run in "global" or "instance" mode:
70097
70152
  * "global" - all properties and methods are attached to the window
@@ -70212,10 +70267,11 @@ var p5 = (function () {
70212
70267
  bindGlobal(p);
70213
70268
  }
70214
70269
 
70270
+ const protectedProperties = ['constructor', 'length'];
70215
70271
  // Attach its properties to the window
70216
70272
  for (const p in this) {
70217
70273
  if (this.hasOwnProperty(p)) {
70218
- if(p[0] === '_') continue;
70274
+ if(p[0] === '_' || protectedProperties.includes(p)) continue;
70219
70275
  bindGlobal(p);
70220
70276
  }
70221
70277
  }
@@ -70537,9 +70593,15 @@ var p5 = (function () {
70537
70593
  * ```
70538
70594
  *
70539
70595
  * Code placed in `setup()` will run once before code placed in
70540
- * <a href="#/p5/draw">draw()</a> begins looping. If the
70541
- * <a href="#/p5/preload">preload()</a> is declared, then `setup()` will
70542
- * run immediately after <a href="#/p5/preload">preload()</a> finishes
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
+
70604
+ *
70543
70605
  * loading assets.
70544
70606
  *
70545
70607
  * Note: `setup()` doesn’t have to be declared, but it’s common practice to do so.
@@ -70610,7 +70672,6 @@ var p5 = (function () {
70610
70672
  * </code>
70611
70673
  * </div>
70612
70674
  */
70613
-
70614
70675
  /**
70615
70676
  * A function that's called repeatedly while the sketch runs.
70616
70677
  *
@@ -70838,6 +70899,11 @@ var p5 = (function () {
70838
70899
  *
70839
70900
  * <div>
70840
70901
  * <code>
70902
+ *
70903
+ * function setup(){
70904
+ * createCanvas(100, 100);
70905
+ * };
70906
+ *
70841
70907
  * function draw() {
70842
70908
  * background(200);
70843
70909
  *
@@ -70859,6 +70925,11 @@ var p5 = (function () {
70859
70925
  *
70860
70926
  * <div>
70861
70927
  * <code>
70928
+ *
70929
+ * function setup(){
70930
+ * createCanvas(100, 100);
70931
+ * }
70932
+ *
70862
70933
  * function draw() {
70863
70934
  * background(200);
70864
70935
  *
@@ -71631,6 +71702,11 @@ var p5 = (function () {
71631
71702
  *
71632
71703
  * <div>
71633
71704
  * <code>
71705
+ *
71706
+ * function setup(){
71707
+ * createCanvas(100, 100);
71708
+ * }
71709
+ *
71634
71710
  * function draw() {
71635
71711
  * // Add the text description.
71636
71712
  * textOutput();
@@ -71651,6 +71727,11 @@ var p5 = (function () {
71651
71727
  *
71652
71728
  * <div>
71653
71729
  * <code>
71730
+ *
71731
+ * function setup(){
71732
+ * createCanvas(100, 100);
71733
+ * }
71734
+ *
71654
71735
  * function draw() {
71655
71736
  * // Add the text description and
71656
71737
  * // display it for debugging.
@@ -71765,6 +71846,11 @@ var p5 = (function () {
71765
71846
  *
71766
71847
  * <div>
71767
71848
  * <code>
71849
+ *
71850
+ * function setup() {
71851
+ * createCanvas(100, 100);
71852
+ * }
71853
+ *
71768
71854
  * function draw() {
71769
71855
  * // Add the grid description.
71770
71856
  * gridOutput();
@@ -71785,6 +71871,11 @@ var p5 = (function () {
71785
71871
  *
71786
71872
  * <div>
71787
71873
  * <code>
71874
+ *
71875
+ * function setup(){
71876
+ * createCanvas(100, 100);
71877
+ * }
71878
+ *
71788
71879
  * function draw() {
71789
71880
  * // Add the grid description and
71790
71881
  * // display it for debugging.
@@ -71805,6 +71896,7 @@ var p5 = (function () {
71805
71896
  * </div>
71806
71897
  */
71807
71898
 
71899
+
71808
71900
  fn.gridOutput = function(display) {
71809
71901
  // p5._validateParameters('gridOutput', arguments);
71810
71902
  //if gridOutput is already true
@@ -76719,7 +76811,7 @@ var p5 = (function () {
76719
76811
  // actual name with correct capitalization doesnt exist in context,
76720
76812
  // and if the user-defined symbol is of the type function
76721
76813
  if (
76722
- fxns[lowercase] &&
76814
+ fxns.hasOwnProperty(lowercase) &&
76723
76815
  !context[fxns[lowercase]] &&
76724
76816
  typeof context[prop] === 'function'
76725
76817
  ) {
@@ -82762,7 +82854,7 @@ var p5 = (function () {
82762
82854
  image: {
82763
82855
  overloads: [
82764
82856
  [
82765
- "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",
82766
82858
  "Number",
82767
82859
  "Number",
82768
82860
  "Number?",
@@ -83260,7 +83352,7 @@ var p5 = (function () {
83260
83352
  createVector: {
83261
83353
  overloads: [
83262
83354
  [
83263
- null
83355
+ "...Number[]"
83264
83356
  ]
83265
83357
  ]
83266
83358
  },
@@ -86868,9 +86960,14 @@ var p5 = (function () {
86868
86960
  const isOptional = param?.endsWith('?');
86869
86961
  param = param?.replace(/\?$/, '');
86870
86962
 
86871
- let schema = generateTypeSchema(param);
86963
+ const isRest = param?.startsWith('...') && param?.endsWith('[]');
86964
+ param = param?.replace(/^\.\.\.(.+)\[\]$/, '$1');
86872
86965
 
86873
- return isOptional ? schema.optional() : schema;
86966
+ let schema = generateTypeSchema(param);
86967
+ if (isOptional) {
86968
+ schema = schema.optional();
86969
+ }
86970
+ return { schema, rest: isRest };
86874
86971
  };
86875
86972
 
86876
86973
  // Note that in Zod, `optional()` only checks for undefined, not the absence
@@ -86904,14 +87001,22 @@ var p5 = (function () {
86904
87001
  const overloadSchemas = overloads.flatMap(overload => {
86905
87002
  const combinations = generateOverloadCombinations(overload);
86906
87003
 
86907
- return combinations.map(combo =>
86908
- tupleType(
86909
- combo
86910
- .map(p => generateParamSchema(p))
86911
- // For now, ignore schemas that cannot be mapped to a defined type
86912
- .filter(schema => schema !== undefined)
86913
- )
86914
- );
87004
+ return combinations.map(combo => {
87005
+ const params = combo
87006
+ .map(p => generateParamSchema(p))
87007
+ .filter(s => s.schema !== undefined);
87008
+
87009
+ let rest;
87010
+ if (params.at(-1)?.rest) {
87011
+ rest = params.pop();
87012
+ }
87013
+
87014
+ let combined = tupleType(params.map(s => s.schema));
87015
+ if (rest) {
87016
+ combined = combined.rest(rest.schema);
87017
+ }
87018
+ return combined;
87019
+ });
86915
87020
  });
86916
87021
 
86917
87022
  return overloadSchemas.length === 1
@@ -87146,7 +87251,7 @@ var p5 = (function () {
87146
87251
  // theoretically allowed to stay undefined and valid, it is likely that the
87147
87252
  // user intended to call the function with non-undefined arguments. Skip
87148
87253
  // regular workflow and return a friendly error message right away.
87149
- if (Array.isArray(args) && args.every(arg => arg === undefined)) {
87254
+ if (Array.isArray(args) && args.length > 0 && args.every(arg => arg === undefined)) {
87150
87255
  const undefinedErrorMessage = `🌸 p5.js says: All arguments for ${func}() are undefined. There is likely an error in the code.`;
87151
87256
 
87152
87257
  return {
@@ -94769,7 +94874,7 @@ var p5 = (function () {
94769
94874
  * let slider;
94770
94875
  *
94771
94876
  * function setup() {
94772
- * createCanvas(100, 100);
94877
+ * createCanvas(200, 200);
94773
94878
  *
94774
94879
  * // Create a paragraph element and place
94775
94880
  * // it at the top of the canvas.
@@ -95010,10 +95115,10 @@ var p5 = (function () {
95010
95115
  * background(200);
95011
95116
  *
95012
95117
  * let img = createImg(
95013
- * 'https://p5js.org/assets/img/asterisk-01.png',
95014
- * 'The p5.js magenta asterisk.'
95118
+ * '/assets/cat.jpg',
95119
+ * 'image of a cat'
95015
95120
  * );
95016
- * img.position(0, -10);
95121
+ * img.position(0, 10);
95017
95122
  *
95018
95123
  * describe('A gray square with a magenta asterisk in its center.');
95019
95124
  * }
@@ -95362,7 +95467,7 @@ var p5 = (function () {
95362
95467
  *
95363
95468
  * // Create a checkbox and place it beneath the canvas.
95364
95469
  * checkbox = createCheckbox();
95365
- * checkbox.position(0, 100);
95470
+ * checkbox.position(0, 70);
95366
95471
  *
95367
95472
  * describe('A black square with a checkbox beneath it. The square turns white when the box is checked.');
95368
95473
  * }
@@ -95388,7 +95493,7 @@ var p5 = (function () {
95388
95493
  * // Create a checkbox and place it beneath the canvas.
95389
95494
  * // Label the checkbox "white".
95390
95495
  * checkbox = createCheckbox(' white');
95391
- * checkbox.position(0, 100);
95496
+ * checkbox.position(0, 70);
95392
95497
  *
95393
95498
  * describe('A black square with a checkbox labeled "white" beneath it. The square turns white when the box is checked.');
95394
95499
  * }
@@ -95414,7 +95519,7 @@ var p5 = (function () {
95414
95519
  * // Create a checkbox and place it beneath the canvas.
95415
95520
  * // Label the checkbox "white" and set its value to true.
95416
95521
  * checkbox = createCheckbox(' white', true);
95417
- * checkbox.position(0, 100);
95522
+ * checkbox.position(0, 70);
95418
95523
  *
95419
95524
  * describe('A white square with a checkbox labeled "white" beneath it. The square turns black when the box is unchecked.');
95420
95525
  * }
@@ -96293,7 +96398,7 @@ var p5 = (function () {
96293
96398
  * let img;
96294
96399
  *
96295
96400
  * function setup() {
96296
- * createCanvas(100, 100);
96401
+ * createCanvas(200, 200);
96297
96402
  *
96298
96403
  * // Create a file input and place it beneath
96299
96404
  * // the canvas.
@@ -96547,18 +96652,18 @@ var p5 = (function () {
96547
96652
  * @example
96548
96653
  * <div>
96549
96654
  * <code>
96655
+ * let rotationX = 0; // Angle in degrees
96656
+ *
96550
96657
  * function setup() {
96551
- * createCanvas(100, 100, WEBGL);
96658
+ * createCanvas(200, 200, WEBGL); // Create 3D canvas
96552
96659
  * }
96553
96660
  *
96554
96661
  * function draw() {
96555
- * background(200);
96556
- * //rotateZ(radians(rotationZ));
96557
- * rotateX(radians(rotationX));
96558
- * //rotateY(radians(rotationY));
96559
- * box(200, 200, 200);
96560
- * describe(`red horizontal line right, green vertical line bottom.
96561
- * black background.`);
96662
+ * background(220); // Set light gray background
96663
+ * rotateX(radians(rotationX)); // Rotate around X-axis
96664
+ * normalMaterial(); // Apply simple shaded material
96665
+ * box(60); // Draw 3D cube (60 units wide)
96666
+ * rotationX = (rotationX + 2) % 360; // Increment rotation (2° per frame)
96562
96667
  * }
96563
96668
  * </code>
96564
96669
  * </div>
@@ -96580,18 +96685,18 @@ var p5 = (function () {
96580
96685
  * @example
96581
96686
  * <div>
96582
96687
  * <code>
96688
+ * let rotationY = 0; // Angle in degrees
96689
+ *
96583
96690
  * function setup() {
96584
- * createCanvas(100, 100, WEBGL);
96691
+ * createCanvas(200, 200, WEBGL); // Create 3D canvas
96585
96692
  * }
96586
96693
  *
96587
96694
  * function draw() {
96588
- * background(200);
96589
- * //rotateZ(radians(rotationZ));
96590
- * //rotateX(radians(rotationX));
96591
- * rotateY(radians(rotationY));
96592
- * box(200, 200, 200);
96593
- * describe(`red horizontal line right, green vertical line bottom.
96594
- * black background.`);
96695
+ * background(220); // Set light gray background
96696
+ * rotateY(radians(rotationY)); // Rotate around Y-axis (vertical)
96697
+ * normalMaterial(); // Apply simple shaded material
96698
+ * box(60); // Draw 3D cube (60 units wide)
96699
+ * rotationY = (rotationY + 2) % 360; // Increment rotation (2° per frame)
96595
96700
  * }
96596
96701
  * </code>
96597
96702
  * </div>
@@ -96614,18 +96719,18 @@ var p5 = (function () {
96614
96719
  * @example
96615
96720
  * <div>
96616
96721
  * <code>
96722
+ * let rotationZ = 0; // Angle in degrees
96723
+ *
96617
96724
  * function setup() {
96618
- * createCanvas(100, 100, WEBGL);
96725
+ * createCanvas(200, 200, WEBGL); // Create 3D canvas
96619
96726
  * }
96620
96727
  *
96621
96728
  * function draw() {
96622
- * background(200);
96623
- * rotateZ(radians(rotationZ));
96624
- * //rotateX(radians(rotationX));
96625
- * //rotateY(radians(rotationY));
96626
- * box(200, 200, 200);
96627
- * describe(`red horizontal line right, green vertical line bottom.
96628
- * black background.`);
96729
+ * background(220);
96730
+ * rotateZ(radians(rotationZ)); // Rotate around Z-axis
96731
+ * normalMaterial(); // Apply simple shaded material
96732
+ * box(60); // Draw 3D cube
96733
+ * rotationZ = (rotationZ + 2) % 360; // Increment rotation angle
96629
96734
  * }
96630
96735
  * </code>
96631
96736
  * </div>
@@ -97787,6 +97892,15 @@ var p5 = (function () {
97787
97892
  * </div>
97788
97893
  */
97789
97894
  fn._onkeyup = function(e) {
97895
+
97896
+ const context = this._isGlobal ? window : this;
97897
+ if (typeof context.keyReleased === 'function') {
97898
+ const executeDefault = context.keyReleased(e);
97899
+ if (executeDefault === false) {
97900
+ e.preventDefault();
97901
+ }
97902
+ }
97903
+
97790
97904
  delete this._downKeyCodes[e.code];
97791
97905
  delete this._downKeys[e.key];
97792
97906
 
@@ -97803,13 +97917,6 @@ var p5 = (function () {
97803
97917
  this.key = lastPressedKey;
97804
97918
  }
97805
97919
 
97806
- const context = this._isGlobal ? window : this;
97807
- if (typeof context.keyReleased === 'function') {
97808
- const executeDefault = context.keyReleased(e);
97809
- if (executeDefault === false) {
97810
- e.preventDefault();
97811
- }
97812
- }
97813
97920
  };
97814
97921
 
97815
97922
  /**
@@ -97943,7 +98050,7 @@ var p5 = (function () {
97943
98050
  * </div>
97944
98051
  */
97945
98052
  fn._onkeypress = function(e) {
97946
- if (e.which === this._lastKeyCodeTyped) {
98053
+ if (e.which === this._lastKeyCodeTyped && e.repeat) {
97947
98054
  // prevent multiple firings
97948
98055
  return;
97949
98056
  }
@@ -99023,25 +99130,25 @@ var p5 = (function () {
99023
99130
 
99024
99131
  fn._updatePointerCoords = function (e) {
99025
99132
  if (this._curElement !== null) {
99026
- const canvas = this._curElement.elt;
99027
- const sx = canvas.scrollWidth / this.width || 1;
99028
- const sy = canvas.scrollHeight / this.height || 1;
99133
+ const canvas = this._curElement.elt;
99134
+ const sx = canvas.scrollWidth / this.width || 1;
99135
+ const sy = canvas.scrollHeight / this.height || 1;
99029
99136
 
99030
- if (e.pointerType == 'touch') {
99137
+ if (e.pointerType == 'touch') {
99031
99138
  const touches = [];
99032
99139
  for (const touch of this._activePointers.values()) {
99033
- touches.push(getTouchInfo(canvas, sx, sy, touch));
99140
+ touches.push(getTouchInfo(canvas, sx, sy, touch));
99034
99141
  }
99035
99142
  this.touches = touches;
99036
- } else {
99037
- const mousePos = getMouseInfo(canvas, sx, sy, e);
99038
- this.movedX = e.movementX || 0;
99039
- this.movedY = e.movementY || 0;
99040
- this.mouseX = mousePos.x;
99041
- this.mouseY = mousePos.y;
99042
- this.winMouseX = mousePos.winX;
99043
- this.winMouseY = mousePos.winY;
99044
- }
99143
+ }
99144
+
99145
+ const mousePos = getMouseInfo(canvas, sx, sy, e);
99146
+ this.movedX = e.movementX || 0;
99147
+ this.movedY = e.movementY || 0;
99148
+ this.mouseX = mousePos.x;
99149
+ this.mouseY = mousePos.y;
99150
+ this.winMouseX = mousePos.winX;
99151
+ this.winMouseY = mousePos.winY;
99045
99152
 
99046
99153
  if (!this._hasMouseInteracted) {
99047
99154
  this._updateMouseCoords();
@@ -101853,8 +101960,8 @@ var p5 = (function () {
101853
101960
  * let table;
101854
101961
  *
101855
101962
  * async function setup() {
101856
- * // Create a 200x100 canvas and set a white background
101857
- * createCanvas(200, 100);
101963
+ * // Create a 300x100 canvas and set a white background
101964
+ * createCanvas(300, 100);
101858
101965
  * background(255);
101859
101966
  *
101860
101967
  * // Load the CSV file with a header row
@@ -103996,7 +104103,7 @@ var p5 = (function () {
103996
104103
  * <a href="#/p5.Vector">p5.Vector</a> class.
103997
104104
  *
103998
104105
  * @method createVector
103999
- * @param {...Number} components Components of the vector.
104106
+ * @param {...Number} x Zero or more numbers, representing each component of the vector.
104000
104107
  * @return {p5.Vector} new <a href="#/p5.Vector">p5.Vector</a> object.
104001
104108
  *
104002
104109
  * @example
@@ -106062,11 +106169,10 @@ var p5 = (function () {
106062
106169
  *
106063
106170
  * If a sketch has a
106064
106171
  * <a href="#/p5/setup">setup()</a> function, then `millis()` begins tracking
106065
- * time before the code in <a href="#/p5/setup">setup()</a> runs. If a
106066
- * sketch includes a <a href="#/p5/preload">preload()</a> function, then
106067
- * `millis()` begins tracking time as soon as the code in
106068
- * <a href="#/p5/preload">preload()</a> starts running.
106069
- *
106172
+ * time before the code in <a href="#/p5/setup">setup()</a> runs. If a
106173
+ * sketch includes asynchronous loading using `async`/`await`, then
106174
+ * `millis()` begins tracking time as soon as the asynchronous code
106175
+ * starts running.
106070
106176
  * @method millis
106071
106177
  * @return {Number} number of milliseconds since starting the sketch.
106072
106178
  *
@@ -109695,7 +109801,7 @@ var p5 = (function () {
109695
109801
  * createCanvas(300, 300);
109696
109802
  * background(220);
109697
109803
  *
109698
- * textSize(48);
109804
+ * textSize(35);
109699
109805
  * textAlign(LEFT, BASELINE);
109700
109806
  * textFont('Georgia');
109701
109807
  *
@@ -118660,7 +118766,6 @@ var p5 = (function () {
118660
118766
  const fontFaceVariations = ['weight', 'stretch', 'style'];
118661
118767
 
118662
118768
 
118663
- let nextId = 0;
118664
118769
  class Font {
118665
118770
  constructor(p, fontFace, name, path, data) {
118666
118771
  if (!(fontFace instanceof FontFace)) {
@@ -118671,7 +118776,6 @@ var p5 = (function () {
118671
118776
  this.path = path;
118672
118777
  this.data = data;
118673
118778
  this.face = fontFace;
118674
- this.id = nextId++;
118675
118779
  }
118676
118780
 
118677
118781
  /**
@@ -120105,24 +120209,7 @@ var p5 = (function () {
120105
120209
  function text(p5, fn) {
120106
120210
  RendererGL.prototype.maxCachedGlyphs = function() {
120107
120211
  // TODO: use more than vibes to find a good value for this
120108
- return 200
120109
- };
120110
-
120111
- RendererGL.prototype.freeGlyphInfo = function(gi) {
120112
- const datas = [
120113
- gi.strokeImageInfo.imageData,
120114
- gi.rowInfo.cellImageInfo.imageData,
120115
- gi.rowInfo.dimImageInfo.imageData,
120116
- gi.colInfo.cellImageInfo.imageData,
120117
- gi.colInfo.dimImageInfo.imageData,
120118
- ];
120119
- for (const data of datas) {
120120
- const tex = this.textures.get(data);
120121
- if (tex) {
120122
- tex.remove();
120123
- this.textures.delete(data);
120124
- }
120125
- }
120212
+ return 200;
120126
120213
  };
120127
120214
 
120128
120215
  Font.prototype._getFontInfo = function(axs) {
@@ -120890,7 +120977,7 @@ var p5 = (function () {
120890
120977
  sh.setUniform("uMaterialColor", curFillColor);
120891
120978
  gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
120892
120979
 
120893
- this.fontCache = this.fontCache || new Map();
120980
+ this.glyphDataCache = this.glyphDataCache || new Set();
120894
120981
 
120895
120982
  try {
120896
120983
  // fetch the glyphs in the line of text
@@ -120899,20 +120986,35 @@ var p5 = (function () {
120899
120986
  for (const glyph of glyphs) {
120900
120987
  const gi = fontInfo.getGlyphInfo(glyph);
120901
120988
  if (gi.uGlyphRect) {
120989
+ const rowInfo = gi.rowInfo;
120990
+ const colInfo = gi.colInfo;
120991
+
120992
+ // Bump the resources for this glyph to the end of the cache list by deleting and re-adding
120993
+ const glyphResources = [
120994
+ gi.strokeImageInfo.imageData,
120995
+ rowInfo.cellImageInfo.imageData,
120996
+ rowInfo.dimImageInfo.imageData,
120997
+ colInfo.cellImageInfo.imageData,
120998
+ colInfo.dimImageInfo.imageData
120999
+ ];
121000
+ for (const resource of glyphResources) {
121001
+ this.glyphDataCache.delete(resource);
121002
+ this.glyphDataCache.add(resource);
121003
+ }
120902
121004
 
120903
- const cacheKey = JSON.stringify({ font: font.id, axs, glyph: glyph.shape.g });
120904
- // Bump this font to the end of the cache list by deleting and re-adding it
120905
- this.fontCache.delete(cacheKey);
120906
- this.fontCache.set(cacheKey, gi);
120907
- if (this.fontCache.size > this.maxCachedGlyphs()) {
120908
- const keyToRemove = this.fontCache.keys().next().value;
120909
- const val = this.fontCache.get(keyToRemove);
120910
- this.fontCache.delete(keyToRemove);
120911
- this.freeGlyphInfo(val);
121005
+ // If we have too many glyph textures, remove the least recently used
121006
+ // ones from GPU memory. The data still exists on the CPU and will be
121007
+ // re-uploaded if it gets actively used again.
121008
+ while (this.glyphDataCache.size > this.maxCachedGlyphs()) {
121009
+ const data = this.glyphDataCache.values().next().value;
121010
+ this.glyphDataCache.delete(data);
121011
+ const tex = this.textures.get(data);
121012
+ if (tex) {
121013
+ tex.remove();
121014
+ this.textures.delete(data);
121015
+ }
120912
121016
  }
120913
121017
 
120914
- const rowInfo = gi.rowInfo;
120915
- const colInfo = gi.colInfo;
120916
121018
  sh.setUniform("uSamplerStrokes", gi.strokeImageInfo.imageData);
120917
121019
  sh.setUniform("uSamplerRowStrokes", rowInfo.cellImageInfo.imageData);
120918
121020
  sh.setUniform("uSamplerRows", rowInfo.dimImageInfo.imageData);