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
package/src/core/main.js DELETED
@@ -1,689 +0,0 @@
1
- /**
2
- * @module Structure
3
- * @submodule Structure
4
- * @for p5
5
- * @requires constants
6
- */
7
-
8
- import * as constants from './constants';
9
-
10
- /**
11
- * This is the p5 instance constructor.
12
- *
13
- * A p5 instance holds all the properties and methods related to
14
- * a p5 sketch. It expects an incoming sketch closure and it can also
15
- * take an optional node parameter for attaching the generated p5 canvas
16
- * to a node. The sketch closure takes the newly created p5 instance as
17
- * its sole argument and may optionally set <a href="#/p5/preload">preload()</a>,
18
- * <a href="#/p5/setup">setup()</a>, and/or
19
- * <a href="#/p5/draw">draw()</a> properties on it for running a sketch.
20
- *
21
- * A p5 sketch can run in "global" or "instance" mode:
22
- * "global" - all properties and methods are attached to the window
23
- * "instance" - all properties and methods are bound to this p5 object
24
- *
25
- * @class p5
26
- * @param {function(p5)} sketch a closure that can set optional <a href="#/p5/preload">preload()</a>,
27
- * <a href="#/p5/setup">setup()</a>, and/or <a href="#/p5/draw">draw()</a> properties on the
28
- * given p5 instance
29
- * @param {HTMLElement} [node] element to attach canvas to
30
- * @return {p5} a p5 instance
31
- */
32
- class p5 {
33
- static VERSION = constants.VERSION;
34
- // This is a pointer to our global mode p5 instance, if we're in
35
- // global mode.
36
- static instance = null;
37
- static lifecycleHooks = {
38
- presetup: [],
39
- postsetup: [],
40
- predraw: [],
41
- postdraw: [],
42
- remove: []
43
- };
44
-
45
- // FES stub
46
- static _checkForUserDefinedFunctions = () => {};
47
- static _friendlyFileLoadError = () => {};
48
-
49
- constructor(sketch, node) {
50
- //////////////////////////////////////////////
51
- // PRIVATE p5 PROPERTIES AND METHODS
52
- //////////////////////////////////////////////
53
-
54
- this.hitCriticalError = false;
55
- this._setupDone = false;
56
- this._userNode = node;
57
- this._curElement = null;
58
- this._elements = [];
59
- this._glAttributes = null;
60
- this._requestAnimId = 0;
61
- this._isGlobal = false;
62
- this._loop = true;
63
- this._startListener = null;
64
- this._initializeInstanceVariables();
65
- this._events = {
66
- // keep track of user-events for unregistering later
67
- pointerdown: null,
68
- pointerup: null,
69
- pointermove: null,
70
- dragend: null,
71
- dragover: null,
72
- click: null,
73
- dblclick: null,
74
- mouseover: null,
75
- mouseout: null,
76
- keydown: null,
77
- keyup: null,
78
- keypress: null,
79
- wheel: null,
80
- resize: null,
81
- blur: null
82
- };
83
- this._millisStart = -1;
84
- this._recording = false;
85
-
86
- // States used in the custom random generators
87
- this._lcg_random_state = null; // NOTE: move to random.js
88
- this._gaussian_previous = false; // NOTE: move to random.js
89
-
90
- if (window.DeviceOrientationEvent) {
91
- this._events.deviceorientation = null;
92
- }
93
- if (window.DeviceMotionEvent && !window._isNodeWebkit) {
94
- this._events.devicemotion = null;
95
- }
96
-
97
- // ensure correct reporting of window dimensions
98
- this._updateWindowSize();
99
-
100
- const bindGlobal = (property) => {
101
- Object.defineProperty(window, property, {
102
- configurable: true,
103
- enumerable: true,
104
- get: () => {
105
- if(typeof this[property] === 'function'){
106
- return this[property].bind(this);
107
- }else{
108
- return this[property];
109
- }
110
- },
111
- set: (newValue) => {
112
- Object.defineProperty(window, property, {
113
- configurable: true,
114
- enumerable: true,
115
- value: newValue,
116
- writable: true
117
- });
118
- if (!p5.disableFriendlyErrors) {
119
- console.log(`You just changed the value of "${property}", which was a p5 global value. This could cause problems later if you're not careful.`);
120
- }
121
- }
122
- })
123
- };
124
- // If the user has created a global setup or draw function,
125
- // assume "global" mode and make everything global (i.e. on the window)
126
- if (!sketch) {
127
- this._isGlobal = true;
128
- if (window.hitCriticalError) {
129
- return;
130
- }
131
- p5.instance = this;
132
-
133
- // Loop through methods on the prototype and attach them to the window
134
- // All methods and properties with name starting with '_' will be skipped
135
- for (const p of Object.getOwnPropertyNames(p5.prototype)) {
136
- if(p[0] === '_') continue;
137
- bindGlobal(p);
138
- }
139
-
140
- // Attach its properties to the window
141
- for (const p in this) {
142
- if (this.hasOwnProperty(p)) {
143
- if(p[0] === '_') continue;
144
- bindGlobal(p);
145
- }
146
- }
147
- } else {
148
- // Else, the user has passed in a sketch closure that may set
149
- // user-provided 'setup', 'draw', etc. properties on this instance of p5
150
- sketch(this);
151
-
152
- // Run a check to see if the user has misspelled 'setup', 'draw', etc
153
- // detects capitalization mistakes only ( Setup, SETUP, MouseClicked, etc)
154
- p5._checkForUserDefinedFunctions(this);
155
- }
156
-
157
- // Bind events to window (not using container div bc key events don't work)
158
- for (const e in this._events) {
159
- const f = this[`_on${e}`];
160
- if (f) {
161
- const m = f.bind(this);
162
- window.addEventListener(e, m, { passive: false });
163
- this._events[e] = m;
164
- }
165
- }
166
-
167
- const focusHandler = () => {
168
- this.focused = true;
169
- };
170
- const blurHandler = () => {
171
- this.focused = false;
172
- };
173
- window.addEventListener('focus', focusHandler);
174
- window.addEventListener('blur', blurHandler);
175
- p5.lifecycleHooks.remove.push(function() {
176
- window.removeEventListener('focus', focusHandler);
177
- window.removeEventListener('blur', blurHandler);
178
- });
179
-
180
- // Initialization complete, start runtime
181
- if (document.readyState === 'complete') {
182
- this.#_start();
183
- } else {
184
- this._startListener = this.#_start.bind(this);
185
- window.addEventListener('load', this._startListener, false);
186
- }
187
- }
188
-
189
- get pixels(){
190
- return this._renderer.pixels;
191
- }
192
-
193
- get drawingContext(){
194
- return this._renderer.drawingContext;
195
- }
196
-
197
- static registerAddon(addon) {
198
- const lifecycles = {};
199
- addon(p5, p5.prototype, lifecycles);
200
-
201
- const validLifecycles = Object.keys(p5.lifecycleHooks);
202
- for(const name of validLifecycles){
203
- if(typeof lifecycles[name] === 'function'){
204
- p5.lifecycleHooks[name].push(lifecycles[name]);
205
- }
206
- }
207
- }
208
-
209
- async #_start() {
210
- if (this.hitCriticalError) return;
211
- // Find node if id given
212
- if (this._userNode) {
213
- if (typeof this._userNode === 'string') {
214
- this._userNode = document.getElementById(this._userNode);
215
- }
216
- }
217
-
218
- await this.#_setup();
219
- if (this.hitCriticalError) return;
220
- if (!this._recording) {
221
- this._draw();
222
- }
223
- }
224
-
225
- async #_setup() {
226
- // Run `presetup` hooks
227
- await this._runLifecycleHook('presetup');
228
- if (this.hitCriticalError) return;
229
-
230
- // Always create a default canvas.
231
- // Later on if the user calls createCanvas, this default one
232
- // will be replaced
233
- this.createCanvas(
234
- 100,
235
- 100,
236
- constants.P2D
237
- );
238
-
239
- // Record the time when sketch starts
240
- this._millisStart = window.performance.now();
241
-
242
- const context = this._isGlobal ? window : this;
243
- if (typeof context.setup === 'function') {
244
- await context.setup();
245
- }
246
- if (this.hitCriticalError) return;
247
-
248
- // unhide any hidden canvases that were created
249
- const canvases = document.getElementsByTagName('canvas');
250
-
251
- // Apply touchAction = 'none' to canvases if pointer events exist
252
- if (Object.keys(this._events).some(event => event.startsWith('pointer'))) {
253
- for (const k of canvases) {
254
- k.style.touchAction = 'none';
255
- }
256
- }
257
-
258
-
259
- for (const k of canvases) {
260
- if (k.dataset.hidden === 'true') {
261
- k.style.visibility = '';
262
- delete k.dataset.hidden;
263
- }
264
- }
265
-
266
- this._lastTargetFrameTime = window.performance.now();
267
- this._lastRealFrameTime = window.performance.now();
268
- this._setupDone = true;
269
- if (this._accessibleOutputs.grid || this._accessibleOutputs.text) {
270
- this._updateAccsOutput();
271
- }
272
-
273
- // Run `postsetup` hooks
274
- await this._runLifecycleHook('postsetup');
275
- }
276
-
277
- // While '#_draw' here is async, it is not awaited as 'requestAnimationFrame'
278
- // does not await its callback. Thus it is not recommended for 'draw()` to be
279
- // async and use await within as the next frame may start rendering before the
280
- // current frame finish awaiting. The same goes for lifecycle hooks 'predraw'
281
- // and 'postdraw'.
282
- async _draw(requestAnimationFrameTimestamp) {
283
- if (this.hitCriticalError) return;
284
- const now = requestAnimationFrameTimestamp || window.performance.now();
285
- const timeSinceLastFrame = now - this._lastTargetFrameTime;
286
- const targetTimeBetweenFrames = 1000 / this._targetFrameRate;
287
-
288
- // only draw if we really need to; don't overextend the browser.
289
- // draw if we're within 5ms of when our next frame should paint
290
- // (this will prevent us from giving up opportunities to draw
291
- // again when it's really about time for us to do so). fixes an
292
- // issue where the frameRate is too low if our refresh loop isn't
293
- // in sync with the browser. note that we have to draw once even
294
- // if looping is off, so we bypass the time delay if that
295
- // is the case.
296
- const epsilon = 5;
297
- if (
298
- !this._loop ||
299
- timeSinceLastFrame >= targetTimeBetweenFrames - epsilon
300
- ) {
301
- //mandatory update values(matrixes and stack)
302
- this.deltaTime = now - this._lastRealFrameTime;
303
- this._frameRate = 1000.0 / this.deltaTime;
304
- await this.redraw();
305
- this._lastTargetFrameTime = Math.max(this._lastTargetFrameTime
306
- + targetTimeBetweenFrames, now);
307
- this._lastRealFrameTime = now;
308
-
309
- // If the user is actually using mouse module, then update
310
- // coordinates, otherwise skip. We can test this by simply
311
- // checking if any of the mouse functions are available or not.
312
- // NOTE : This reflects only in complete build or modular build.
313
- if (typeof this._updateMouseCoords !== 'undefined') {
314
- this._updateMouseCoords();
315
-
316
- //reset delta values so they reset even if there is no mouse event to set them
317
- // for example if the mouse is outside the screen
318
- this.movedX = 0;
319
- this.movedY = 0;
320
- }
321
- }
322
-
323
- // get notified the next time the browser gives us
324
- // an opportunity to draw.
325
- if (this._loop) {
326
- this._requestAnimId = window.requestAnimationFrame(
327
- this._draw.bind(this)
328
- );
329
- }
330
- }
331
-
332
- /**
333
- * Removes the sketch from the web page.
334
- *
335
- * Calling `remove()` stops the draw loop and removes any HTML elements
336
- * created by the sketch, including the canvas. A new sketch can be
337
- * created by using the <a href="#/p5/p5">p5()</a> constructor, as in
338
- * `new p5()`.
339
- *
340
- * @example
341
- * <div>
342
- * <code>
343
- * // Double-click to remove the canvas.
344
- *
345
- * function setup() {
346
- * createCanvas(100, 100);
347
- *
348
- * describe(
349
- * 'A white circle on a gray background. The circle follows the mouse as the user moves. The sketch disappears when the user double-clicks.'
350
- * );
351
- * }
352
- *
353
- * function draw() {
354
- * // Paint the background repeatedly.
355
- * background(200);
356
- *
357
- * // Draw circles repeatedly.
358
- * circle(mouseX, mouseY, 40);
359
- * }
360
- *
361
- * // Remove the sketch when the user double-clicks.
362
- * function doubleClicked() {
363
- * remove();
364
- * }
365
- * </code>
366
- * </div>
367
- */
368
- async remove() {
369
- // Remove start listener to prevent orphan canvas being created
370
- if(this._startListener){
371
- window.removeEventListener('load', this._startListener, false);
372
- }
373
-
374
- if (this._curElement) {
375
- // stop draw
376
- this._loop = false;
377
- if (this._requestAnimId) {
378
- window.cancelAnimationFrame(this._requestAnimId);
379
- }
380
-
381
- // unregister events sketch-wide
382
- for (const ev in this._events) {
383
- window.removeEventListener(ev, this._events[ev]);
384
- }
385
-
386
- // remove DOM elements created by p5, and listeners
387
- for (const e of this._elements) {
388
- if (e.elt && e.elt.parentNode) {
389
- e.elt.parentNode.removeChild(e.elt);
390
- }
391
- for (const elt_ev in e._events) {
392
- e.elt.removeEventListener(elt_ev, e._events[elt_ev]);
393
- }
394
- }
395
-
396
- // Run `remove` hooks
397
- await this._runLifecycleHook('remove');
398
- }
399
-
400
- // remove window bound properties and methods
401
- if (this._isGlobal) {
402
- for (const p in p5.prototype) {
403
- try {
404
- delete window[p];
405
- } catch (x) {
406
- window[p] = undefined;
407
- }
408
- }
409
- for (const p2 in this) {
410
- if (this.hasOwnProperty(p2)) {
411
- try {
412
- delete window[p2];
413
- } catch (x) {
414
- window[p2] = undefined;
415
- }
416
- }
417
- }
418
- p5.instance = null;
419
- }
420
- }
421
-
422
- async _runLifecycleHook(hookName) {
423
- for(const hook of p5.lifecycleHooks[hookName]){
424
- await hook.call(this);
425
- }
426
- }
427
-
428
- _initializeInstanceVariables() {
429
- this._accessibleOutputs = {
430
- text: false,
431
- grid: false,
432
- textLabel: false,
433
- gridLabel: false
434
- };
435
-
436
- this._styles = [];
437
- this._downKeys = {}; //Holds the key codes of currently pressed keys
438
- this._downKeyCodes = {};
439
- }
440
- }
441
-
442
- // Attach constants to p5 prototype
443
- for (const k in constants) {
444
- p5.prototype[k] = constants[k];
445
- }
446
-
447
- //////////////////////////////////////////////
448
- // PUBLIC p5 PROPERTIES AND METHODS
449
- //////////////////////////////////////////////
450
-
451
- /**
452
- * A function that's called once when the sketch begins running.
453
- *
454
- * Declaring the function `setup()` sets a code block to run once
455
- * automatically when the sketch starts running. It's used to perform
456
- * setup tasks such as creating the canvas and initializing variables:
457
- *
458
- * ```js
459
- * function setup() {
460
- * // Code to run once at the start of the sketch.
461
- * }
462
- * ```
463
- *
464
- * Code placed in `setup()` will run once before code placed in
465
- * <a href="#/p5/draw">draw()</a> begins looping. If the
466
- * <a href="#/p5/preload">preload()</a> is declared, then `setup()` will
467
- * run immediately after <a href="#/p5/preload">preload()</a> finishes
468
- * loading assets.
469
- *
470
- * Note: `setup()` doesn’t have to be declared, but it’s common practice to do so.
471
- *
472
- * @method setup
473
- * @for p5
474
- *
475
- * @example
476
- * <div>
477
- * <code>
478
- * function setup() {
479
- * createCanvas(100, 100);
480
- *
481
- * background(200);
482
- *
483
- * // Draw the circle.
484
- * circle(50, 50, 40);
485
- *
486
- * describe('A white circle on a gray background.');
487
- * }
488
- * </code>
489
- * </div>
490
- *
491
- * <div>
492
- * <code>
493
- * function setup() {
494
- * createCanvas(100, 100);
495
- *
496
- * // Paint the background once.
497
- * background(200);
498
- *
499
- * describe(
500
- * 'A white circle on a gray background. The circle follows the mouse as the user moves, leaving a trail.'
501
- * );
502
- * }
503
- *
504
- * function draw() {
505
- * // Draw circles repeatedly.
506
- * circle(mouseX, mouseY, 40);
507
- * }
508
- * </code>
509
- * </div>
510
- *
511
- * <div>
512
- * <code>
513
- * let img;
514
- *
515
- * async function setup() {
516
- * img = await loadImage('assets/bricks.jpg');
517
- *
518
- * createCanvas(100, 100);
519
- *
520
- * // Draw the image.
521
- * image(img, 0, 0);
522
- *
523
- * describe(
524
- * 'A white circle on a brick wall. The circle follows the mouse as the user moves, leaving a trail.'
525
- * );
526
- * }
527
- *
528
- * function draw() {
529
- * // Style the circle.
530
- * noStroke();
531
- *
532
- * // Draw the circle.
533
- * circle(mouseX, mouseY, 10);
534
- * }
535
- * </code>
536
- * </div>
537
- */
538
-
539
- /**
540
- * A function that's called repeatedly while the sketch runs.
541
- *
542
- * Declaring the function `draw()` sets a code block to run repeatedly
543
- * once the sketch starts. It’s used to create animations and respond to
544
- * user inputs:
545
- *
546
- * ```js
547
- * function draw() {
548
- * // Code to run repeatedly.
549
- * }
550
- * ```
551
- *
552
- * This is often called the "draw loop" because p5.js calls the code in
553
- * `draw()` in a loop behind the scenes. By default, `draw()` tries to run
554
- * 60 times per second. The actual rate depends on many factors. The
555
- * drawing rate, called the "frame rate", can be controlled by calling
556
- * <a href="#/p5/frameRate">frameRate()</a>. The number of times `draw()`
557
- * has run is stored in the system variable
558
- * <a href="#/p5/frameCount">frameCount()</a>.
559
- *
560
- * Code placed within `draw()` begins looping after
561
- * <a href="#/p5/setup">setup()</a> runs. `draw()` will run until the user
562
- * closes the sketch. `draw()` can be stopped by calling the
563
- * <a href="#/p5/noLoop">noLoop()</a> function. `draw()` can be resumed by
564
- * calling the <a href="#/p5/loop">loop()</a> function.
565
- *
566
- * @method draw
567
- * @for p5
568
- *
569
- * @example
570
- * <div>
571
- * <code>
572
- * function setup() {
573
- * createCanvas(100, 100);
574
- *
575
- * // Paint the background once.
576
- * background(200);
577
- *
578
- * describe(
579
- * 'A white circle on a gray background. The circle follows the mouse as the user moves, leaving a trail.'
580
- * );
581
- * }
582
- *
583
- * function draw() {
584
- * // Draw circles repeatedly.
585
- * circle(mouseX, mouseY, 40);
586
- * }
587
- * </code>
588
- * </div>
589
- *
590
- * <div>
591
- * <code>
592
- * function setup() {
593
- * createCanvas(100, 100);
594
- *
595
- * describe(
596
- * 'A white circle on a gray background. The circle follows the mouse as the user moves.'
597
- * );
598
- * }
599
- *
600
- * function draw() {
601
- * // Paint the background repeatedly.
602
- * background(200);
603
- *
604
- * // Draw circles repeatedly.
605
- * circle(mouseX, mouseY, 40);
606
- * }
607
- * </code>
608
- * </div>
609
- *
610
- * <div>
611
- * <code>
612
- * // Double-click the canvas to change the circle's color.
613
- *
614
- * function setup() {
615
- * createCanvas(100, 100);
616
- *
617
- * describe(
618
- * 'A white circle on a gray background. The circle follows the mouse as the user moves. The circle changes color to pink when the user double-clicks.'
619
- * );
620
- * }
621
- *
622
- * function draw() {
623
- * // Paint the background repeatedly.
624
- * background(200);
625
- *
626
- * // Draw circles repeatedly.
627
- * circle(mouseX, mouseY, 40);
628
- * }
629
- *
630
- * // Change the fill color when the user double-clicks.
631
- * function doubleClicked() {
632
- * fill('deeppink');
633
- * }
634
- * </code>
635
- * </div>
636
- */
637
-
638
- /**
639
- * Turns off the parts of the Friendly Error System (FES) that impact performance.
640
- *
641
- * The <a href="https://github.com/processing/p5.js/blob/main/contributor_docs/friendly_error_system.md" target="_blank">FES</a>
642
- * can cause sketches to draw slowly because it does extra work behind the
643
- * scenes. For example, the FES checks the arguments passed to functions,
644
- * which takes time to process. Disabling the FES can significantly improve
645
- * performance by turning off these checks.
646
- *
647
- * @property {Boolean} disableFriendlyErrors
648
- *
649
- * @example
650
- * <div>
651
- * <code>
652
- * // Disable the FES.
653
- * p5.disableFriendlyErrors = true;
654
- *
655
- * function setup() {
656
- * createCanvas(100, 100);
657
- *
658
- * background(200);
659
- *
660
- * // The circle() function requires three arguments. The
661
- * // next line would normally display a friendly error that
662
- * // points this out. Instead, nothing happens and it fails
663
- * // silently.
664
- * circle(50, 50);
665
- *
666
- * describe('A gray square.');
667
- * }
668
- * </code>
669
- * </div>
670
- */
671
- p5.disableFriendlyErrors = false;
672
-
673
- import transform from './transform';
674
- import structure from './structure';
675
- import environment from './environment';
676
- import rendering from './rendering';
677
- import renderer from './p5.Renderer';
678
- import renderer2D from './p5.Renderer2D';
679
- import graphics from './p5.Graphics';
680
-
681
- p5.registerAddon(transform);
682
- p5.registerAddon(structure);
683
- p5.registerAddon(environment);
684
- p5.registerAddon(rendering);
685
- p5.registerAddon(renderer);
686
- p5.registerAddon(renderer2D);
687
- p5.registerAddon(graphics);
688
-
689
- export default p5;
package/src/core/noop.js DELETED
@@ -1 +0,0 @@
1
- export default function(){}