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
@@ -1,696 +0,0 @@
1
- /**
2
- * @module Rendering
3
- * @submodule Rendering
4
- * @for p5
5
- */
6
-
7
- import * as constants from './constants';
8
- import { RGB, HSB, HSL } from '../color/creating_reading';
9
- import primitives2D from '../shape/2d_primitives';
10
- import attributes from '../shape/attributes';
11
- import curves from '../shape/curves';
12
- import vertex from '../shape/vertex';
13
- import setting from '../color/setting';
14
- import image from '../image/image';
15
- import loadingDisplaying from '../image/loading_displaying';
16
- import pixels from '../image/pixels';
17
- import transform from './transform';
18
- import { Framebuffer } from '../webgl/p5.Framebuffer';
19
-
20
- import primitives3D from '../webgl/3d_primitives';
21
- import light from '../webgl/light';
22
- import material from '../webgl/material';
23
- import creatingReading from '../color/creating_reading';
24
- import trigonometry from '../math/trigonometry';
25
- import { renderers } from './rendering';
26
-
27
- class Graphics {
28
- constructor(w, h, renderer, pInst, canvas) {
29
- const r = renderer || constants.P2D;
30
-
31
- this._pInst = pInst;
32
- this._renderer = new renderers[r](this._pInst, w, h, false, canvas);
33
-
34
- this._initializeInstanceVariables(this);
35
-
36
- this._renderer._applyDefaults();
37
- return this;
38
- }
39
-
40
- get deltaTime(){
41
- return this._pInst.deltaTime;
42
- }
43
-
44
- get canvas(){
45
- return this._renderer?.canvas;
46
- }
47
-
48
- get drawingContext(){
49
- return this._renderer.drawingContext;
50
- }
51
-
52
- get width(){
53
- return this._renderer?.width;
54
- }
55
-
56
- get height(){
57
- return this._renderer?.height;
58
- }
59
-
60
- get pixels(){
61
- return this._renderer?.pixels;
62
- }
63
-
64
- pixelDensity(val){
65
- let returnValue;
66
- if (typeof val === 'number') {
67
- if (val !== this._renderer._pixelDensity) {
68
- this._renderer._pixelDensity = val;
69
- }
70
- returnValue = this;
71
- this.resizeCanvas(this.width, this.height, true); // as a side effect, it will clear the canvas
72
- } else {
73
- returnValue = this._renderer._pixelDensity;
74
- }
75
- return returnValue;
76
- }
77
-
78
- resizeCanvas(w, h){
79
- this._renderer.resize(w, h);
80
- }
81
-
82
- /**
83
- * Resets the graphics buffer's transformations and lighting.
84
- *
85
- * By default, the main canvas resets certain transformation and lighting
86
- * values each time <a href="#/p5/draw">draw()</a> executes. `p5.Graphics`
87
- * objects must reset these values manually by calling `myGraphics.reset()`.
88
- *
89
- *
90
- * @example
91
- * <div>
92
- * <code>
93
- * let pg;
94
- *
95
- * function setup() {
96
- * createCanvas(100, 100);
97
- *
98
- * // Create a p5.Graphics object.
99
- * pg = createGraphics(60, 60);
100
- *
101
- * describe('A white circle moves downward slowly within a dark square. The circle resets at the top of the dark square when the user presses the mouse.');
102
- * }
103
- *
104
- * function draw() {
105
- * background(200);
106
- *
107
- * // Translate the p5.Graphics object's coordinate system.
108
- * // The translation accumulates; the white circle moves.
109
- * pg.translate(0, 0.1);
110
- *
111
- * // Draw to the p5.Graphics object.
112
- * pg.background(100);
113
- * pg.circle(30, 0, 10);
114
- *
115
- * // Display the p5.Graphics object.
116
- * image(pg, 20, 20);
117
- *
118
- * // Translate the main canvas' coordinate system.
119
- * // The translation doesn't accumulate; the dark
120
- * // square is always in the same place.
121
- * translate(0, 0.1);
122
- *
123
- * // Reset the p5.Graphics object when the
124
- * // user presses the mouse.
125
- * if (mouseIsPressed === true) {
126
- * pg.reset();
127
- * }
128
- * }
129
- * </code>
130
- * </div>
131
- *
132
- * <div>
133
- * <code>
134
- * let pg;
135
- *
136
- * function setup() {
137
- * createCanvas(100, 100);
138
- *
139
- * // Create a p5.Graphics object.
140
- * pg = createGraphics(60, 60);
141
- *
142
- * describe('A white circle at the center of a dark gray square. The image is drawn on a light gray background.');
143
- * }
144
- *
145
- * function draw() {
146
- * background(200);
147
- *
148
- * // Translate the p5.Graphics object's coordinate system.
149
- * pg.translate(30, 30);
150
- *
151
- * // Draw to the p5.Graphics object.
152
- * pg.background(100);
153
- * pg.circle(0, 0, 10);
154
- *
155
- * // Display the p5.Graphics object.
156
- * image(pg, 20, 20);
157
- *
158
- * // Reset the p5.Graphics object automatically.
159
- * pg.reset();
160
- * }
161
- * </code>
162
- * </div>
163
- *
164
- * <div>
165
- * <code>
166
- * let pg;
167
- *
168
- * function setup() {
169
- * createCanvas(100, 100);
170
- *
171
- * // Create a p5.Graphics object using WebGL mode.
172
- * pg = createGraphics(100, 100, WEBGL);
173
- *
174
- * describe("A sphere lit from above with a red light. The sphere's surface becomes glossy while the user clicks and holds the mouse.");
175
- * }
176
- *
177
- * function draw() {
178
- * background(200);
179
- *
180
- * // Add a red point light from the top-right.
181
- * pg.pointLight(255, 0, 0, 50, -100, 50);
182
- *
183
- * // Style the sphere.
184
- * // It should appear glossy when the
185
- * // lighting values are reset.
186
- * pg.noStroke();
187
- * pg.specularMaterial(255);
188
- * pg.shininess(100);
189
- *
190
- * // Draw the sphere.
191
- * pg.sphere(30);
192
- *
193
- * // Display the p5.Graphics object.
194
- * image(pg, -50, -50);
195
- *
196
- * // Reset the p5.Graphics object when
197
- * // the user presses the mouse.
198
- * if (mouseIsPressed === true) {
199
- * pg.reset();
200
- * }
201
- * }
202
- * </code>
203
- * </div>
204
- *
205
- * <div>
206
- * <code>
207
- * let pg;
208
- *
209
- * function setup() {
210
- * createCanvas(100, 100);
211
- *
212
- * // Create a p5.Graphics object using WebGL mode.
213
- * pg = createGraphics(100, 100, WEBGL);
214
- *
215
- * describe('A sphere with a glossy surface is lit from the top-right by a red light.');
216
- * }
217
- *
218
- * function draw() {
219
- * background(200);
220
- *
221
- * // Add a red point light from the top-right.
222
- * pg.pointLight(255, 0, 0, 50, -100, 50);
223
- *
224
- * // Style the sphere.
225
- * pg.noStroke();
226
- * pg.specularMaterial(255);
227
- * pg.shininess(100);
228
- *
229
- * // Draw the sphere.
230
- * pg.sphere(30);
231
- *
232
- * // Display the p5.Graphics object.
233
- * image(pg, 0, 0);
234
- *
235
- * // Reset the p5.Graphics object automatically.
236
- * pg.reset();
237
- * }
238
- * </code>
239
- * </div>
240
- */
241
- reset() {
242
- this._renderer.resetMatrix();
243
- if (this._renderer.isP3D) {
244
- this._renderer._update();
245
- }
246
- }
247
-
248
- /**
249
- * Removes the graphics buffer from the web page.
250
- *
251
- * Calling `myGraphics.remove()` removes the graphics buffer's
252
- * `&lt;canvas&gt;` element from the web page. The graphics buffer also uses
253
- * a bit of memory on the CPU that can be freed like so:
254
- *
255
- * ```js
256
- * // Remove the graphics buffer from the web page.
257
- * myGraphics.remove();
258
- *
259
- * // Delete the graphics buffer from CPU memory.
260
- * myGraphics = undefined;
261
- * ```
262
- *
263
- * Note: All variables that reference the graphics buffer must be assigned
264
- * the value `undefined` to delete the graphics buffer from CPU memory. If any
265
- * variable still refers to the graphics buffer, then it won't be garbage
266
- * collected.
267
- *
268
- * @example
269
- * <div>
270
- * <code>
271
- * // Double-click to remove the p5.Graphics object.
272
- *
273
- * let pg;
274
- *
275
- * function setup() {
276
- * createCanvas(100, 100);
277
- *
278
- * // Create a p5.Graphics object.
279
- * pg = createGraphics(60, 60);
280
- *
281
- * // Draw to the p5.Graphics object.
282
- * pg.background(100);
283
- * pg.circle(30, 30, 20);
284
- *
285
- * describe('A white circle at the center of a dark gray square disappears when the user double-clicks.');
286
- * }
287
- *
288
- * function draw() {
289
- * background(200);
290
- *
291
- * // Display the p5.Graphics object if
292
- * // it's available.
293
- * if (pg) {
294
- * image(pg, 20, 20);
295
- * }
296
- * }
297
- *
298
- * // Remove the p5.Graphics object when the
299
- * // the user double-clicks.
300
- * function doubleClicked() {
301
- * // Remove the p5.Graphics object from the web page.
302
- * pg.remove();
303
- * pg = undefined;
304
- * }
305
- * </code>
306
- * </div>
307
- */
308
- remove() {
309
- this._renderer.remove();
310
- this._renderer = undefined;
311
- }
312
-
313
-
314
- /**
315
- * Creates a new <a href="#/p5.Framebuffer">p5.Framebuffer</a> object with
316
- * the same WebGL context as the graphics buffer.
317
- *
318
- * <a href="#/p5.Framebuffer">p5.Framebuffer</a> objects are separate drawing
319
- * surfaces that can be used as textures in WebGL mode. They're similar to
320
- * <a href="#/p5.Graphics">p5.Graphics</a> objects and generally run much
321
- * faster when used as textures. Creating a
322
- * <a href="#/p5.Framebuffer">p5.Framebuffer</a> object in the same context
323
- * as the graphics buffer makes this speedup possible.
324
- *
325
- * The parameter, `options`, is optional. An object can be passed to configure
326
- * the <a href="#/p5.Framebuffer">p5.Framebuffer</a> object. The available
327
- * properties are:
328
- *
329
- * - `format`: data format of the texture, either `UNSIGNED_BYTE`, `FLOAT`, or `HALF_FLOAT`. Default is `UNSIGNED_BYTE`.
330
- * - `channels`: whether to store `RGB` or `RGBA` color channels. Default is to match the graphics buffer which is `RGBA`.
331
- * - `depth`: whether to include a depth buffer. Default is `true`.
332
- * - `depthFormat`: data format of depth information, either `UNSIGNED_INT` or `FLOAT`. Default is `FLOAT`.
333
- * - `stencil`: whether to include a stencil buffer for masking. `depth` must be `true` for this feature to work. Defaults to the value of `depth` which is `true`.
334
- * - `antialias`: whether to perform anti-aliasing. If set to `true`, as in `{ antialias: true }`, 2 samples will be used by default. The number of samples can also be set, as in `{ antialias: 4 }`. Default is to match <a href="#/p5/setAttributes">setAttributes()</a> which is `false` (`true` in Safari).
335
- * - `width`: width of the <a href="#/p5.Framebuffer">p5.Framebuffer</a> object. Default is to always match the graphics buffer width.
336
- * - `height`: height of the <a href="#/p5.Framebuffer">p5.Framebuffer</a> object. Default is to always match the graphics buffer height.
337
- * - `density`: pixel density of the <a href="#/p5.Framebuffer">p5.Framebuffer</a> object. Default is to always match the graphics buffer pixel density.
338
- * - `textureFiltering`: how to read values from the <a href="#/p5.Framebuffer">p5.Framebuffer</a> object. Either `LINEAR` (nearby pixels will be interpolated) or `NEAREST` (no interpolation). Generally, use `LINEAR` when using the texture as an image and `NEAREST` if reading the texture as data. Default is `LINEAR`.
339
- *
340
- * If the `width`, `height`, or `density` attributes are set, they won't
341
- * automatically match the graphics buffer and must be changed manually.
342
- *
343
- * @param {Object} [options] configuration options.
344
- * @return {p5.Framebuffer} new framebuffer.
345
- *
346
- * @example
347
- * <div>
348
- * <code>
349
- * // Click and hold a mouse button to change shapes.
350
- *
351
- * let pg;
352
- * let torusLayer;
353
- * let boxLayer;
354
- *
355
- * function setup() {
356
- * createCanvas(100, 100);
357
- *
358
- * // Create a p5.Graphics object using WebGL mode.
359
- * pg = createGraphics(100, 100, WEBGL);
360
- *
361
- * // Create the p5.Framebuffer objects.
362
- * torusLayer = pg.createFramebuffer();
363
- * boxLayer = pg.createFramebuffer();
364
- *
365
- * describe('A grid of white toruses rotating against a dark gray background. The shapes become boxes while the user holds a mouse button.');
366
- * }
367
- *
368
- * function draw() {
369
- * // Update and draw the layers offscreen.
370
- * drawTorus();
371
- * drawBox();
372
- *
373
- * // Choose the layer to display.
374
- * let layer;
375
- * if (mouseIsPressed === true) {
376
- * layer = boxLayer;
377
- * } else {
378
- * layer = torusLayer;
379
- * }
380
- *
381
- * // Draw to the p5.Graphics object.
382
- * pg.background(50);
383
- *
384
- * // Iterate from left to right.
385
- * for (let x = -50; x < 50; x += 25) {
386
- * // Iterate from top to bottom.
387
- * for (let y = -50; y < 50; y += 25) {
388
- * // Draw the layer to the p5.Graphics object
389
- * pg.image(layer, x, y, 25, 25);
390
- * }
391
- * }
392
- *
393
- * // Display the p5.Graphics object.
394
- * image(pg, 0, 0);
395
- * }
396
- *
397
- * // Update and draw the torus layer offscreen.
398
- * function drawTorus() {
399
- * // Start drawing to the torus p5.Framebuffer.
400
- * torusLayer.begin();
401
- *
402
- * // Clear the drawing surface.
403
- * pg.clear();
404
- *
405
- * // Turn on the lights.
406
- * pg.lights();
407
- *
408
- * // Rotate the coordinate system.
409
- * pg.rotateX(frameCount * 0.01);
410
- * pg.rotateY(frameCount * 0.01);
411
- *
412
- * // Style the torus.
413
- * pg.noStroke();
414
- *
415
- * // Draw the torus.
416
- * pg.torus(20);
417
- *
418
- * // Start drawing to the torus p5.Framebuffer.
419
- * torusLayer.end();
420
- * }
421
- *
422
- * // Update and draw the box layer offscreen.
423
- * function drawBox() {
424
- * // Start drawing to the box p5.Framebuffer.
425
- * boxLayer.begin();
426
- *
427
- * // Clear the drawing surface.
428
- * pg.clear();
429
- *
430
- * // Turn on the lights.
431
- * pg.lights();
432
- *
433
- * // Rotate the coordinate system.
434
- * pg.rotateX(frameCount * 0.01);
435
- * pg.rotateY(frameCount * 0.01);
436
- *
437
- * // Style the box.
438
- * pg.noStroke();
439
- *
440
- * // Draw the box.
441
- * pg.box(30);
442
- *
443
- * // Start drawing to the box p5.Framebuffer.
444
- * boxLayer.end();
445
- * }
446
- * </code>
447
- * </div>
448
- *
449
- * <div>
450
- * <code>
451
- * // Click and hold a mouse button to change shapes.
452
- *
453
- * let pg;
454
- * let torusLayer;
455
- * let boxLayer;
456
- *
457
- * function setup() {
458
- * createCanvas(100, 100);
459
- *
460
- * // Create an options object.
461
- * let options = { width: 25, height: 25 };
462
- *
463
- * // Create a p5.Graphics object using WebGL mode.
464
- * pg = createGraphics(100, 100, WEBGL);
465
- *
466
- * // Create the p5.Framebuffer objects.
467
- * // Use options for configuration.
468
- * torusLayer = pg.createFramebuffer(options);
469
- * boxLayer = pg.createFramebuffer(options);
470
- *
471
- * describe('A grid of white toruses rotating against a dark gray background. The shapes become boxes while the user holds a mouse button.');
472
- * }
473
- *
474
- * function draw() {
475
- * // Update and draw the layers offscreen.
476
- * drawTorus();
477
- * drawBox();
478
- *
479
- * // Choose the layer to display.
480
- * let layer;
481
- * if (mouseIsPressed === true) {
482
- * layer = boxLayer;
483
- * } else {
484
- * layer = torusLayer;
485
- * }
486
- *
487
- * // Draw to the p5.Graphics object.
488
- * pg.background(50);
489
- *
490
- * // Iterate from left to right.
491
- * for (let x = -50; x < 50; x += 25) {
492
- * // Iterate from top to bottom.
493
- * for (let y = -50; y < 50; y += 25) {
494
- * // Draw the layer to the p5.Graphics object
495
- * pg.image(layer, x, y);
496
- * }
497
- * }
498
- *
499
- * // Display the p5.Graphics object.
500
- * image(pg, 0, 0);
501
- * }
502
- *
503
- * // Update and draw the torus layer offscreen.
504
- * function drawTorus() {
505
- * // Start drawing to the torus p5.Framebuffer.
506
- * torusLayer.begin();
507
- *
508
- * // Clear the drawing surface.
509
- * pg.clear();
510
- *
511
- * // Turn on the lights.
512
- * pg.lights();
513
- *
514
- * // Rotate the coordinate system.
515
- * pg.rotateX(frameCount * 0.01);
516
- * pg.rotateY(frameCount * 0.01);
517
- *
518
- * // Style the torus.
519
- * pg.noStroke();
520
- *
521
- * // Draw the torus.
522
- * pg.torus(5, 2.5);
523
- *
524
- * // Start drawing to the torus p5.Framebuffer.
525
- * torusLayer.end();
526
- * }
527
- *
528
- * // Update and draw the box layer offscreen.
529
- * function drawBox() {
530
- * // Start drawing to the box p5.Framebuffer.
531
- * boxLayer.begin();
532
- *
533
- * // Clear the drawing surface.
534
- * pg.clear();
535
- *
536
- * // Turn on the lights.
537
- * pg.lights();
538
- *
539
- * // Rotate the coordinate system.
540
- * pg.rotateX(frameCount * 0.01);
541
- * pg.rotateY(frameCount * 0.01);
542
- *
543
- * // Style the box.
544
- * pg.noStroke();
545
- *
546
- * // Draw the box.
547
- * pg.box(7.5);
548
- *
549
- * // Start drawing to the box p5.Framebuffer.
550
- * boxLayer.end();
551
- * }
552
- * </code>
553
- * </div>
554
- */
555
- createFramebuffer(options) {
556
- return new Framebuffer(this._renderer, options);
557
- }
558
-
559
- _assert3d(name) {
560
- if (!this._renderer.isP3D)
561
- throw new Error(
562
- `${name}() is only supported in WEBGL mode. If you'd like to use 3D graphics and WebGL, see https://p5js.org/examples/form-3d-primitives.html for more information.`
563
- );
564
- };
565
-
566
- _initializeInstanceVariables() {
567
- this._accessibleOutputs = {
568
- text: false,
569
- grid: false,
570
- textLabel: false,
571
- gridLabel: false
572
- };
573
-
574
- this._styles = [];
575
-
576
- // this._colorMode = RGB;
577
- // this._colorMaxes = {
578
- // rgb: [255, 255, 255, 255],
579
- // hsb: [360, 100, 100, 1],
580
- // hsl: [360, 100, 100, 1]
581
- // };
582
-
583
- this._downKeys = {}; //Holds the key codes of currently pressed keys
584
- }
585
- };
586
-
587
- function graphics(p5, fn){
588
- /**
589
- * A class to describe a drawing surface that's separate from the main canvas.
590
- *
591
- * Each `p5.Graphics` object provides a dedicated drawing surface called a
592
- * *graphics buffer*. Graphics buffers are helpful when drawing should happen
593
- * offscreen. For example, separate scenes can be drawn offscreen and
594
- * displayed only when needed.
595
- *
596
- * `p5.Graphics` objects have nearly all the drawing features of the main
597
- * canvas. For example, calling the method `myGraphics.circle(50, 50, 20)`
598
- * draws to the graphics buffer. The resulting image can be displayed on the
599
- * main canvas by passing the `p5.Graphics` object to the
600
- * <a href="#/p5/image">image()</a> function, as in `image(myGraphics, 0, 0)`.
601
- *
602
- * Note: <a href="#/p5/createGraphics">createGraphics()</a> is the recommended
603
- * way to create an instance of this class.
604
- *
605
- * @class p5.Graphics
606
- * @extends p5.Element
607
- * @param {Number} w width width of the graphics buffer in pixels.
608
- * @param {Number} h height height of the graphics buffer in pixels.
609
- * @param {(P2D|WEBGL|P2DHDR)} renderer the renderer to use, either P2D or WEBGL.
610
- * @param {p5} [pInst] sketch instance.
611
- * @param {HTMLCanvasElement} [canvas] existing `&lt;canvas&gt;` element to use.
612
- *
613
- * @example
614
- * <div>
615
- * <code>
616
- * let pg;
617
- *
618
- * function setup() {
619
- * createCanvas(100, 100);
620
- *
621
- * // Create a p5.Graphics object.
622
- * pg = createGraphics(50, 50);
623
- *
624
- * // Draw to the p5.Graphics object.
625
- * pg.background(100);
626
- * pg.circle(25, 25, 20);
627
- *
628
- * describe('A dark gray square with a white circle at its center drawn on a gray background.');
629
- * }
630
- *
631
- * function draw() {
632
- * background(200);
633
- *
634
- * // Display the p5.Graphics object.
635
- * image(pg, 25, 25);
636
- * }
637
- * </code>
638
- * </div>
639
- *
640
- * <div>
641
- * <code>
642
- * // Click the canvas to display the graphics buffer.
643
- *
644
- * let pg;
645
- *
646
- * function setup() {
647
- * createCanvas(100, 100);
648
- *
649
- * // Create a p5.Graphics object.
650
- * pg = createGraphics(50, 50);
651
- *
652
- * describe('A square appears on a gray background when the user presses the mouse. The square cycles between white and black.');
653
- * }
654
- *
655
- * function draw() {
656
- * background(200);
657
- *
658
- * // Calculate the background color.
659
- * let bg = frameCount % 255;
660
- *
661
- * // Draw to the p5.Graphics object.
662
- * pg.background(bg);
663
- *
664
- * // Display the p5.Graphics object while
665
- * // the user presses the mouse.
666
- * if (mouseIsPressed === true) {
667
- * image(pg, 25, 25);
668
- * }
669
- * }
670
- * </code>
671
- * </div>
672
- */
673
- p5.Graphics = Graphics;
674
-
675
- // Shapes
676
- primitives2D(p5, p5.Graphics.prototype);
677
- attributes(p5, p5.Graphics.prototype);
678
- curves(p5, p5.Graphics.prototype);
679
- vertex(p5, p5.Graphics.prototype);
680
-
681
- setting(p5, p5.Graphics.prototype);
682
- loadingDisplaying(p5, p5.Graphics.prototype);
683
- image(p5, p5.Graphics.prototype);
684
- pixels(p5, p5.Graphics.prototype);
685
-
686
- transform(p5, p5.Graphics.prototype);
687
-
688
- primitives3D(p5, p5.Graphics.prototype);
689
- light(p5, p5.Graphics.prototype);
690
- material(p5, p5.Graphics.prototype);
691
- creatingReading(p5, p5.Graphics.prototype);
692
- trigonometry(p5, p5.Graphics.prototype);
693
- }
694
-
695
- export default graphics;
696
- export { Graphics };