p5 2.0.0 → 2.0.1

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 (188) hide show
  1. package/{src → dist}/accessibility/color_namer.js +48 -3
  2. package/{src → dist}/accessibility/describe.js +2 -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 +2 -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-C-g_eAdC.js} +266 -130
  16. package/{src → dist}/core/States.js +3 -1
  17. package/dist/core/constants.js +1 -0
  18. package/{src → dist}/core/environment.js +7 -6
  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 +5455 -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-D4AAKRbx.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 +11 -5
  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 +2 -2
  50. package/{src → dist}/events/index.js +3 -1
  51. package/{src → dist}/events/keyboard.js +14 -11
  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 +4 -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 +3 -4
  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-s72KWcUy.js} +735 -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 +2 -2
  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-CwAYZOC2.js} +390 -19
  81. package/dist/rendering--aAe5aq3.js +24925 -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 -61
  91. package/{src → dist}/type/textCore.js +34 -57
  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 +51 -9
  117. package/lib/p5.esm.js +102 -48
  118. package/lib/p5.js +102 -48
  119. package/lib/p5.min.js +1 -1
  120. package/package.json +17 -16
  121. package/translations/dev.js +6 -6
  122. package/translations/index.js +1 -1
  123. package/src/README.md +0 -27
  124. package/src/accessibility/index.js +0 -13
  125. package/src/app.js +0 -61
  126. package/src/color/index.js +0 -9
  127. package/src/color/p5.Color.culori.js +0 -66
  128. package/src/color/p5.Color.js +0 -851
  129. package/src/core/README.md +0 -91
  130. package/src/core/friendly_errors/index.js +0 -13
  131. package/src/core/friendly_errors/param_validator.js +0 -561
  132. package/src/core/init.js +0 -58
  133. package/src/core/internationalization.js +0 -195
  134. package/src/core/legacy.js +0 -29
  135. package/src/core/main.js +0 -689
  136. package/src/core/noop.js +0 -1
  137. package/src/core/p5.Graphics.js +0 -696
  138. package/src/core/p5.Renderer.js +0 -408
  139. package/src/core/reference.js +0 -2060
  140. package/src/core/rendering.js +0 -697
  141. package/src/dom/index.js +0 -11
  142. package/src/image/const.js +0 -6
  143. package/src/image/image.js +0 -731
  144. package/src/image/index.js +0 -15
  145. package/src/image/loading_displaying.js +0 -1431
  146. package/src/io/files.js +0 -2210
  147. package/src/io/index.js +0 -11
  148. package/src/math/README.md +0 -40
  149. package/src/type/index.js +0 -9
  150. package/src/webgl/3d_primitives.js +0 -2741
  151. package/src/webgl/index.js +0 -37
  152. package/src/webgl/light.js +0 -1851
  153. package/src/webgl/material.js +0 -3854
  154. package/src/webgl/p5.Camera.js +0 -4010
  155. package/src/webgl/p5.Framebuffer.js +0 -1865
  156. package/src/webgl/p5.RendererGL.js +0 -2867
  157. package/src/webgl/p5.Shader.js +0 -1505
  158. package/src/webgl/p5.Texture.js +0 -541
  159. package/src/webgl/shaders/basic.frag +0 -6
  160. package/src/webgl/shaders/filters/base.frag +0 -22
  161. package/src/webgl/shaders/filters/base.vert +0 -19
  162. package/src/webgl/shaders/filters/blur.frag +0 -60
  163. package/src/webgl/shaders/filters/default.vert +0 -18
  164. package/src/webgl/shaders/filters/dilate.frag +0 -39
  165. package/src/webgl/shaders/filters/erode.frag +0 -39
  166. package/src/webgl/shaders/filters/gray.frag +0 -16
  167. package/src/webgl/shaders/filters/invert.frag +0 -15
  168. package/src/webgl/shaders/filters/opaque.frag +0 -12
  169. package/src/webgl/shaders/filters/posterize.frag +0 -29
  170. package/src/webgl/shaders/filters/threshold.frag +0 -23
  171. package/src/webgl/shaders/font.frag +0 -216
  172. package/src/webgl/shaders/font.vert +0 -44
  173. package/src/webgl/shaders/imageLight.vert +0 -33
  174. package/src/webgl/shaders/imageLightDiffused.frag +0 -82
  175. package/src/webgl/shaders/imageLightSpecular.frag +0 -134
  176. package/src/webgl/shaders/light.vert +0 -37
  177. package/src/webgl/shaders/light_texture.frag +0 -26
  178. package/src/webgl/shaders/lighting.glsl +0 -227
  179. package/src/webgl/shaders/line.frag +0 -74
  180. package/src/webgl/shaders/line.vert +0 -294
  181. package/src/webgl/shaders/normal.frag +0 -6
  182. package/src/webgl/shaders/normal.vert +0 -72
  183. package/src/webgl/shaders/phong.frag +0 -84
  184. package/src/webgl/shaders/phong.vert +0 -87
  185. package/src/webgl/shaders/point.frag +0 -29
  186. package/src/webgl/shaders/point.vert +0 -19
  187. package/src/webgl/shaders/sphereMapping.frag +0 -26
  188. package/src/webgl/shaders/webgl2Compatibility.glsl +0 -34
@@ -1,697 +0,0 @@
1
- /**
2
- * @module Rendering
3
- * @submodule Rendering
4
- * @for p5
5
- */
6
-
7
- import * as constants from './constants';
8
- import { Framebuffer } from '../webgl/p5.Framebuffer';
9
-
10
- let renderers;
11
- function rendering(p5, fn){
12
- // Extend additional renderers object to p5 class, new renderer can be similarly attached
13
- renderers = p5.renderers = {};
14
-
15
- /**
16
- * Creates a canvas element on the web page.
17
- *
18
- * `createCanvas()` creates the main drawing canvas for a sketch. It should
19
- * only be called once at the beginning of <a href="#/p5/setup">setup()</a>.
20
- * Calling `createCanvas()` more than once causes unpredictable behavior.
21
- *
22
- * The first two parameters, `width` and `height`, are optional. They set the
23
- * dimensions of the canvas and the values of the
24
- * <a href="#/p5/width">width</a> and <a href="#/p5/height">height</a> system
25
- * variables. For example, calling `createCanvas(900, 500)` creates a canvas
26
- * that's 900×500 pixels. By default, `width` and `height` are both 100.
27
- *
28
- * The third parameter is also optional. If either of the constants `P2D` or
29
- * `WEBGL` is passed, as in `createCanvas(900, 500, WEBGL)`, then it will set
30
- * the sketch's rendering mode. If an existing
31
- * <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement" target="_blank">HTMLCanvasElement</a>
32
- * is passed, as in `createCanvas(900, 500, myCanvas)`, then it will be used
33
- * by the sketch.
34
- *
35
- * The fourth parameter is also optional. If an existing
36
- * <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement" target="_blank">HTMLCanvasElement</a>
37
- * is passed, as in `createCanvas(900, 500, WEBGL, myCanvas)`, then it will be
38
- * used by the sketch.
39
- *
40
- * Note: In WebGL mode, the canvas will use a WebGL2 context if it's supported
41
- * by the browser. Check the <a href="#/p5/webglVersion">webglVersion</a>
42
- * system variable to check what version is being used, or call
43
- * `setAttributes({ version: 1 })` to create a WebGL1 context.
44
- *
45
- * @method createCanvas
46
- * @param {Number} [width] width of the canvas. Defaults to 100.
47
- * @param {Number} [height] height of the canvas. Defaults to 100.
48
- * @param {(P2D|WEBGL|P2DHDR)} [renderer] either P2D or WEBGL. Defaults to `P2D`.
49
- * @param {HTMLCanvasElement} [canvas] existing canvas element that should be used for the sketch.
50
- * @return {p5.Renderer} new `p5.Renderer` that holds the canvas.
51
- *
52
- * @example
53
- * <div>
54
- * <code>
55
- * function setup() {
56
- * createCanvas(100, 100);
57
- *
58
- * background(200);
59
- *
60
- * // Draw a diagonal line.
61
- * line(0, 0, width, height);
62
- *
63
- * describe('A diagonal line drawn from top-left to bottom-right on a gray background.');
64
- * }
65
- * </code>
66
- * </div>
67
- *
68
- * <div>
69
- * <code>
70
- * function setup() {
71
- * createCanvas(100, 50);
72
- *
73
- * background(200);
74
- *
75
- * // Draw a diagonal line.
76
- * line(0, 0, width, height);
77
- *
78
- * describe('A diagonal line drawn from top-left to bottom-right on a gray background.');
79
- * }
80
- * </code>
81
- * </div>
82
- *
83
- * <div>
84
- * <code>
85
- * // Use WebGL mode.
86
- *
87
- * function setup() {
88
- * createCanvas(100, 100, WEBGL);
89
- *
90
- * background(200);
91
- *
92
- * // Draw a diagonal line.
93
- * line(-width / 2, -height / 2, width / 2, height / 2);
94
- *
95
- * describe('A diagonal line drawn from top-left to bottom-right on a gray background.');
96
- * }
97
- * </code>
98
- * </div>
99
- *
100
- * <div>
101
- * <code>
102
- * function setup() {
103
- * // Create a p5.Render object.
104
- * let cnv = createCanvas(50, 50);
105
- *
106
- * // Position the canvas.
107
- * cnv.position(10, 20);
108
- *
109
- * background(200);
110
- *
111
- * // Draw a diagonal line.
112
- * line(0, 0, width, height);
113
- *
114
- * describe('A diagonal line drawn from top-left to bottom-right on a gray background.');
115
- * }
116
- * </code>
117
- * </div>
118
- */
119
- /**
120
- * @method createCanvas
121
- * @param {Number} [width]
122
- * @param {Number} [height]
123
- * @param {HTMLCanvasElement} [canvas]
124
- * @return {p5.Renderer}
125
- */
126
- fn.createCanvas = function (w, h, renderer, ...args) {
127
- // p5._validateParameters('createCanvas', arguments);
128
- //optional: renderer, otherwise defaults to p2d
129
-
130
- let selectedRenderer = constants.P2D
131
- // Check third argument whether it is renderer constants
132
- if(Reflect.ownKeys(renderers).includes(renderer)){
133
- selectedRenderer = renderer;
134
- }else{
135
- args.unshift(renderer);
136
- }
137
-
138
- // Init our graphics renderer
139
- if(this._renderer) this._renderer.remove();
140
- this._renderer = new renderers[selectedRenderer](this, w, h, true, ...args);
141
- this._defaultGraphicsCreated = true;
142
- this._elements.push(this._renderer);
143
- this._renderer._applyDefaults();
144
-
145
- // Make the renderer own `pixels`
146
- if (!Object.hasOwn(this, 'pixels')) {
147
- Object.defineProperty(this, 'pixels', {
148
- get(){
149
- return this._renderer?.pixels;
150
- }
151
- });
152
- }
153
-
154
- return this._renderer;
155
- };
156
-
157
- /**
158
- * Resizes the canvas to a given width and height.
159
- *
160
- * `resizeCanvas()` immediately clears the canvas and calls
161
- * <a href="#/p5/redraw">redraw()</a>. It's common to call `resizeCanvas()`
162
- * within the body of <a href="#/p5/windowResized">windowResized()</a> like
163
- * so:
164
- *
165
- * ```js
166
- * function windowResized() {
167
- * resizeCanvas(windowWidth, windowHeight);
168
- * }
169
- * ```
170
- *
171
- * The first two parameters, `width` and `height`, set the dimensions of the
172
- * canvas. They also the values of the <a href="#/p5/width">width</a> and
173
- * <a href="#/p5/height">height</a> system variables. For example, calling
174
- * `resizeCanvas(300, 500)` resizes the canvas to 300×500 pixels, then sets
175
- * <a href="#/p5/width">width</a> to 300 and
176
- * <a href="#/p5/height">height</a> 500.
177
- *
178
- * The third parameter, `noRedraw`, is optional. If `true` is passed, as in
179
- * `resizeCanvas(300, 500, true)`, then the canvas will be canvas to 300×500
180
- * pixels but the <a href="#/p5/redraw">redraw()</a> function won't be called
181
- * immediately. By default, <a href="#/p5/redraw">redraw()</a> is called
182
- * immediately when `resizeCanvas()` finishes executing.
183
- *
184
- * @method resizeCanvas
185
- * @param {Number} width width of the canvas.
186
- * @param {Number} height height of the canvas.
187
- * @param {Boolean} [noRedraw] whether to delay calling
188
- * <a href="#/p5/redraw">redraw()</a>. Defaults
189
- * to `false`.
190
- *
191
- * @example
192
- * <div>
193
- * <code>
194
- * // Double-click to resize the canvas.
195
- *
196
- * function setup() {
197
- * createCanvas(100, 100);
198
- *
199
- * describe(
200
- * 'A white circle drawn on a gray background. The canvas shrinks by half the first time the user double-clicks.'
201
- * );
202
- * }
203
- *
204
- * function draw() {
205
- * background(200);
206
- *
207
- * // Draw a circle at the center of the canvas.
208
- * circle(width / 2, height / 2, 20);
209
- * }
210
- *
211
- * // Resize the canvas when the user double-clicks.
212
- * function doubleClicked() {
213
- * resizeCanvas(50, 50);
214
- * }
215
- * </code>
216
- * </div>
217
- *
218
- * <div>
219
- * <code>
220
- * // Resize the web browser to change the canvas size.
221
- *
222
- * function setup() {
223
- * createCanvas(windowWidth, windowHeight);
224
- *
225
- * describe('A white circle drawn on a gray background.');
226
- * }
227
- *
228
- * function draw() {
229
- * background(200);
230
- *
231
- * // Draw a circle at the center of the canvas.
232
- * circle(width / 2, height / 2, 20);
233
- * }
234
- *
235
- * // Always resize the canvas to fill the browser window.
236
- * function windowResized() {
237
- * resizeCanvas(windowWidth, windowHeight);
238
- * }
239
- * </code>
240
- * </div>
241
- */
242
- fn.resizeCanvas = function (w, h, noRedraw) {
243
- // p5._validateParameters('resizeCanvas', arguments);
244
- if (this._renderer) {
245
- // Make sure width and height are updated before the renderer resizes so
246
- // that framebuffers updated from the resize read the correct size
247
- this._renderer.resize(w, h);
248
-
249
- if (!noRedraw) {
250
- this.redraw();
251
- }
252
- }
253
- //accessible Outputs
254
- if (this._addAccsOutput()) {
255
- this._updateAccsOutput();
256
- }
257
- };
258
-
259
- /**
260
- * Removes the default canvas.
261
- *
262
- * By default, a 100×100 pixels canvas is created without needing to call
263
- * <a href="#/p5/createCanvas">createCanvas()</a>. `noCanvas()` removes the
264
- * default canvas for sketches that don't need it.
265
- *
266
- * @method noCanvas
267
- *
268
- * @example
269
- * <div>
270
- * <code>
271
- * function setup() {
272
- * noCanvas();
273
- * }
274
- * </code>
275
- * </div>
276
- */
277
- fn.noCanvas = function () {
278
- if (this.canvas) {
279
- this.canvas.parentNode.removeChild(this.canvas);
280
- }
281
- };
282
-
283
- /**
284
- * Creates a <a href="#/p5.Graphics">p5.Graphics</a> object.
285
- *
286
- * `createGraphics()` creates an offscreen drawing canvas (graphics buffer)
287
- * and returns it as a <a href="#/p5.Graphics">p5.Graphics</a> object. Drawing
288
- * to a separate graphics buffer can be helpful for performance and for
289
- * organizing code.
290
- *
291
- * The first two parameters, `width` and `height`, are optional. They set the
292
- * dimensions of the <a href="#/p5.Graphics">p5.Graphics</a> object. For
293
- * example, calling `createGraphics(900, 500)` creates a graphics buffer
294
- * that's 900×500 pixels.
295
- *
296
- * The third parameter is also optional. If either of the constants `P2D` or
297
- * `WEBGL` is passed, as in `createGraphics(900, 500, WEBGL)`, then it will set
298
- * the <a href="#/p5.Graphics">p5.Graphics</a> object's rendering mode. If an
299
- * existing
300
- * <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement" target="_blank">HTMLCanvasElement</a>
301
- * is passed, as in `createGraphics(900, 500, myCanvas)`, then it will be used
302
- * by the graphics buffer.
303
- *
304
- * The fourth parameter is also optional. If an existing
305
- * <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement" target="_blank">HTMLCanvasElement</a>
306
- * is passed, as in `createGraphics(900, 500, WEBGL, myCanvas)`, then it will be
307
- * used by the graphics buffer.
308
- *
309
- * Note: In WebGL mode, the <a href="#/p5.Graphics">p5.Graphics</a> object
310
- * will use a WebGL2 context if it's supported by the browser. Check the
311
- * <a href="#/p5/webglVersion">webglVersion</a> system variable to check what
312
- * version is being used, or call `setAttributes({ version: 1 })` to create a
313
- * WebGL1 context.
314
- *
315
- * @method createGraphics
316
- * @param {Number} width width of the graphics buffer.
317
- * @param {Number} height height of the graphics buffer.
318
- * @param {(P2D|WEBGL)} [renderer] either P2D or WEBGL. Defaults to P2D.
319
- * @param {HTMLCanvasElement} [canvas] existing canvas element that should be
320
- * used for the graphics buffer..
321
- * @return {p5.Graphics} new graphics buffer.
322
- *
323
- * @example
324
- * <div>
325
- * <code>
326
- * // Double-click to draw the contents of the graphics buffer.
327
- *
328
- * let pg;
329
- *
330
- * function setup() {
331
- * createCanvas(100, 100);
332
- *
333
- * background(200);
334
- *
335
- * // Create the p5.Graphics object.
336
- * pg = createGraphics(50, 50);
337
- *
338
- * // Draw to the graphics buffer.
339
- * pg.background(100);
340
- * pg.circle(pg.width / 2, pg.height / 2, 20);
341
- *
342
- * describe('A gray square. A smaller, darker square with a white circle at its center appears when the user double-clicks.');
343
- * }
344
- *
345
- * // Display the graphics buffer when the user double-clicks.
346
- * function doubleClicked() {
347
- * if (mouseX > 0 && mouseX < 100 && mouseY > 0 && mouseY < 100) {
348
- * image(pg, 25, 25);
349
- * }
350
- * }
351
- * </code>
352
- * </div>
353
- *
354
- * <div>
355
- * <code>
356
- * // Double-click to draw the contents of the graphics buffer.
357
- *
358
- * let pg;
359
- *
360
- * function setup() {
361
- * createCanvas(100, 100);
362
- *
363
- * background(200);
364
- *
365
- * // Create the p5.Graphics object in WebGL mode.
366
- * pg = createGraphics(50, 50, WEBGL);
367
- *
368
- * // Draw to the graphics buffer.
369
- * pg.background(100);
370
- * pg.lights();
371
- * pg.noStroke();
372
- * pg.rotateX(QUARTER_PI);
373
- * pg.rotateY(QUARTER_PI);
374
- * pg.torus(15, 5);
375
- *
376
- * describe('A gray square. A smaller, darker square with a white torus at its center appears when the user double-clicks.');
377
- * }
378
- *
379
- * // Display the graphics buffer when the user double-clicks.
380
- * function doubleClicked() {
381
- * if (mouseX > 0 && mouseX < 100 && mouseY > 0 && mouseY < 100) {
382
- * image(pg, 25, 25);
383
- * }
384
- * }
385
- * </code>
386
- * </div>
387
- */
388
- /**
389
- * @method createGraphics
390
- * @param {Number} width
391
- * @param {Number} height
392
- * @param {HTMLCanvasElement} [canvas]
393
- * @return {p5.Graphics}
394
- */
395
- fn.createGraphics = function (w, h, ...args) {
396
- /**
397
- * args[0] is expected to be renderer
398
- * args[1] is expected to be canvas
399
- */
400
- if (args[0] instanceof HTMLCanvasElement) {
401
- args[1] = args[0];
402
- args[0] = constants.P2D;
403
- }
404
- // p5._validateParameters('createGraphics', arguments);
405
- return new p5.Graphics(w, h, args[0], this, args[1]);
406
- };
407
-
408
- /**
409
- * Creates and a new <a href="#/p5.Framebuffer">p5.Framebuffer</a> object.
410
- *
411
- * <a href="#/p5.Framebuffer">p5.Framebuffer</a> objects are separate drawing
412
- * surfaces that can be used as textures in WebGL mode. They're similar to
413
- * <a href="#/p5.Graphics">p5.Graphics</a> objects and generally run much
414
- * faster when used as textures.
415
- *
416
- * The parameter, `options`, is optional. An object can be passed to configure
417
- * the <a href="#/p5.Framebuffer">p5.Framebuffer</a> object. The available
418
- * properties are:
419
- *
420
- * - `format`: data format of the texture, either `UNSIGNED_BYTE`, `FLOAT`, or `HALF_FLOAT`. Default is `UNSIGNED_BYTE`.
421
- * - `channels`: whether to store `RGB` or `RGBA` color channels. Default is to match the main canvas which is `RGBA`.
422
- * - `depth`: whether to include a depth buffer. Default is `true`.
423
- * - `depthFormat`: data format of depth information, either `UNSIGNED_INT` or `FLOAT`. Default is `FLOAT`.
424
- * - `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`.
425
- * - `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).
426
- * - `width`: width of the <a href="#/p5.Framebuffer">p5.Framebuffer</a> object. Default is to always match the main canvas width.
427
- * - `height`: height of the <a href="#/p5.Framebuffer">p5.Framebuffer</a> object. Default is to always match the main canvas height.
428
- * - `density`: pixel density of the <a href="#/p5.Framebuffer">p5.Framebuffer</a> object. Default is to always match the main canvas pixel density.
429
- * - `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`.
430
- *
431
- * If the `width`, `height`, or `density` attributes are set, they won't automatically match the main canvas and must be changed manually.
432
- *
433
- * Note: `createFramebuffer()` can only be used in WebGL mode.
434
- *
435
- * @method createFramebuffer
436
- * @param {Object} [options] configuration options.
437
- * @return {p5.Framebuffer} new framebuffer.
438
- *
439
- * @example
440
- * <div>
441
- * <code>
442
- * let myBuffer;
443
- *
444
- * function setup() {
445
- * createCanvas(100, 100, WEBGL);
446
- *
447
- * // Create a p5.Framebuffer object.
448
- * myBuffer = createFramebuffer();
449
- *
450
- * describe('A grid of white toruses rotating against a dark gray background.');
451
- * }
452
- *
453
- * function draw() {
454
- * background(50);
455
- *
456
- * // Start drawing to the p5.Framebuffer object.
457
- * myBuffer.begin();
458
- *
459
- * // Clear the drawing surface.
460
- * clear();
461
- *
462
- * // Turn on the lights.
463
- * lights();
464
- *
465
- * // Rotate the coordinate system.
466
- * rotateX(frameCount * 0.01);
467
- * rotateY(frameCount * 0.01);
468
- *
469
- * // Style the torus.
470
- * noStroke();
471
- *
472
- * // Draw the torus.
473
- * torus(20);
474
- *
475
- * // Stop drawing to the p5.Framebuffer object.
476
- * myBuffer.end();
477
- *
478
- * // Iterate from left to right.
479
- * for (let x = -50; x < 50; x += 25) {
480
- * // Iterate from top to bottom.
481
- * for (let y = -50; y < 50; y += 25) {
482
- * // Draw the p5.Framebuffer object to the canvas.
483
- * image(myBuffer, x, y, 25, 25);
484
- * }
485
- * }
486
- * }
487
- * </code>
488
- * </div>
489
- *
490
- * <div>
491
- * <code>
492
- * let myBuffer;
493
- *
494
- * function setup() {
495
- * createCanvas(100, 100, WEBGL);
496
- *
497
- * // Create an options object.
498
- * let options = { width: 25, height: 25 };
499
- *
500
- * // Create a p5.Framebuffer object.
501
- * // Use options for configuration.
502
- * myBuffer = createFramebuffer(options);
503
- *
504
- * describe('A grid of white toruses rotating against a dark gray background.');
505
- * }
506
- *
507
- * function draw() {
508
- * background(50);
509
- *
510
- * // Start drawing to the p5.Framebuffer object.
511
- * myBuffer.begin();
512
- *
513
- * // Clear the drawing surface.
514
- * clear();
515
- *
516
- * // Turn on the lights.
517
- * lights();
518
- *
519
- * // Rotate the coordinate system.
520
- * rotateX(frameCount * 0.01);
521
- * rotateY(frameCount * 0.01);
522
- *
523
- * // Style the torus.
524
- * noStroke();
525
- *
526
- * // Draw the torus.
527
- * torus(5, 2.5);
528
- *
529
- * // Stop drawing to the p5.Framebuffer object.
530
- * myBuffer.end();
531
- *
532
- * // Iterate from left to right.
533
- * for (let x = -50; x < 50; x += 25) {
534
- * // Iterate from top to bottom.
535
- * for (let y = -50; y < 50; y += 25) {
536
- * // Draw the p5.Framebuffer object to the canvas.
537
- * image(myBuffer, x, y);
538
- * }
539
- * }
540
- * }
541
- * </code>
542
- * </div>
543
- */
544
- fn.createFramebuffer = function (options) {
545
- return new Framebuffer(this._renderer, options);
546
- };
547
-
548
- /**
549
- * Clears the depth buffer in WebGL mode.
550
- *
551
- * `clearDepth()` clears information about how far objects are from the camera
552
- * in 3D space. This information is stored in an object called the
553
- * *depth buffer*. Clearing the depth buffer ensures new objects aren't drawn
554
- * behind old ones. Doing so can be useful for feedback effects in which the
555
- * previous frame serves as the background for the current frame.
556
- *
557
- * The parameter, `depth`, is optional. If a number is passed, as in
558
- * `clearDepth(0.5)`, it determines the range of objects to clear from the
559
- * depth buffer. 0 doesn't clear any depth information, 0.5 clears depth
560
- * information halfway between the near and far clipping planes, and 1 clears
561
- * depth information all the way to the far clipping plane. By default,
562
- * `depth` is 1.
563
- *
564
- * Note: `clearDepth()` can only be used in WebGL mode.
565
- *
566
- * @method clearDepth
567
- * @param {Number} [depth] amount of the depth buffer to clear between 0
568
- * (none) and 1 (far clipping plane). Defaults to 1.
569
- *
570
- * @example
571
- * <div>
572
- * <code>
573
- * let previous;
574
- * let current;
575
- *
576
- * function setup() {
577
- * createCanvas(100, 100, WEBGL);
578
- *
579
- * // Create the p5.Framebuffer objects.
580
- * previous = createFramebuffer({ format: FLOAT });
581
- * current = createFramebuffer({ format: FLOAT });
582
- *
583
- * describe(
584
- * 'A multicolor box drifts from side to side on a white background. It leaves a trail that fades over time.'
585
- * );
586
- * }
587
- *
588
- * function draw() {
589
- * // Swap the previous p5.Framebuffer and the
590
- * // current one so it can be used as a texture.
591
- * [previous, current] = [current, previous];
592
- *
593
- * // Start drawing to the current p5.Framebuffer.
594
- * current.begin();
595
- *
596
- * // Paint the background.
597
- * background(255);
598
- *
599
- * // Draw the previous p5.Framebuffer.
600
- * // Clear the depth buffer so the previous
601
- * // frame doesn't block the current one.
602
- * push();
603
- * tint(255, 250);
604
- * image(previous, -50, -50);
605
- * clearDepth();
606
- * pop();
607
- *
608
- * // Draw the box on top of the previous frame.
609
- * push();
610
- * let x = 25 * sin(frameCount * 0.01);
611
- * let y = 25 * sin(frameCount * 0.02);
612
- * translate(x, y, 0);
613
- * rotateX(frameCount * 0.01);
614
- * rotateY(frameCount * 0.01);
615
- * normalMaterial();
616
- * box(12);
617
- * pop();
618
- *
619
- * // Stop drawing to the current p5.Framebuffer.
620
- * current.end();
621
- *
622
- * // Display the current p5.Framebuffer.
623
- * image(current, -50, -50);
624
- * }
625
- * </code>
626
- * </div>
627
- */
628
- fn.clearDepth = function (depth) {
629
- this._assert3d('clearDepth');
630
- this._renderer.clearDepth(depth);
631
- };
632
-
633
- /**
634
- * A system variable that provides direct access to the sketch's
635
- * `&lt;canvas&gt;` element.
636
- *
637
- * The `&lt;canvas&gt;` element provides many specialized features that aren't
638
- * included in the p5.js library. The `drawingContext` system variable
639
- * provides access to these features by exposing the sketch's
640
- * <a href="https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D">CanvasRenderingContext2D</a>
641
- * object.
642
- *
643
- * @property drawingContext
644
- *
645
- * @example
646
- * <div>
647
- * <code>
648
- * function setup() {
649
- * createCanvas(100, 100);
650
- *
651
- * background(200);
652
- *
653
- * // Style the circle using shadows.
654
- * drawingContext.shadowOffsetX = 5;
655
- * drawingContext.shadowOffsetY = -5;
656
- * drawingContext.shadowBlur = 10;
657
- * drawingContext.shadowColor = 'black';
658
- *
659
- * // Draw the circle.
660
- * circle(50, 50, 40);
661
- *
662
- * describe("A white circle on a gray background. The circle's edges are shadowy.");
663
- * }
664
- * </code>
665
- * </div>
666
- *
667
- * <div>
668
- * <code>
669
- * function setup() {
670
- * createCanvas(100, 100);
671
- *
672
- * background('skyblue');
673
- *
674
- * // Style the circle using a color gradient.
675
- * let myGradient = drawingContext.createRadialGradient(50, 50, 3, 50, 50, 40);
676
- * myGradient.addColorStop(0, 'yellow');
677
- * myGradient.addColorStop(0.6, 'orangered');
678
- * myGradient.addColorStop(1, 'yellow');
679
- * drawingContext.fillStyle = myGradient;
680
- * drawingContext.strokeStyle = 'rgba(0, 0, 0, 0)';
681
- *
682
- * // Draw the circle.
683
- * circle(50, 50, 40);
684
- *
685
- * describe('A fiery sun drawn on a light blue background.');
686
- * }
687
- * </code>
688
- * </div>
689
- */
690
- }
691
-
692
- export default rendering;
693
- export { renderers };
694
-
695
- if(typeof p5 !== 'undefined'){
696
- rendering(p5, p5.prototype);
697
- }
package/src/dom/index.js DELETED
@@ -1,11 +0,0 @@
1
- import dom from './dom';
2
- import element from './p5.Element';
3
- import media from './p5.MediaElement';
4
- import file from './p5.File';
5
-
6
- export default function(p5){
7
- p5.registerAddon(dom);
8
- p5.registerAddon(element);
9
- p5.registerAddon(media);
10
- p5.registerAddon(file);
11
- }