q5 2.10.7 → 2.11.0

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 (72) hide show
  1. package/README.md +8 -1
  2. package/deno.json +36 -0
  3. package/package.json +3 -6
  4. package/q5-deno-server.js +45 -0
  5. package/q5-server.js +6 -7
  6. package/q5.js +19 -13
  7. package/q5.min.js +2 -2
  8. package/src/q5-2d-image.js +1 -1
  9. package/src/q5-canvas.js +16 -10
  10. package/src/q5-core.js +2 -2
  11. package/test/core.test.js +30 -0
  12. package/test/readme.md +5 -0
  13. package/.vscode/launch.json +0 -26
  14. package/.vscode/settings.json +0 -3
  15. package/bun.lockb +0 -0
  16. package/p5-tests/js/chai_helpers.js +0 -20
  17. package/p5-tests/js/mocha_setup.js +0 -2
  18. package/p5-tests/js/modernizr.js +0 -5
  19. package/p5-tests/js/p5_helpers.js +0 -135
  20. package/p5-tests/js/sinon.js +0 -5949
  21. package/p5-tests/mocha.css +0 -289
  22. package/p5-tests/test.html +0 -71
  23. package/p5-tests/unit/color/color_conversion.js +0 -68
  24. package/p5-tests/unit/color/creating_reading.js +0 -217
  25. package/p5-tests/unit/color/p5.Color.js +0 -1000
  26. package/p5-tests/unit/color/setting.js +0 -289
  27. package/p5-tests/unit/core/2d_primitives.js +0 -490
  28. package/p5-tests/unit/core/attributes.js +0 -115
  29. package/p5-tests/unit/core/curves.js +0 -139
  30. package/p5-tests/unit/core/environment.js +0 -248
  31. package/p5-tests/unit/core/error_helpers.js +0 -1158
  32. package/p5-tests/unit/core/main.js +0 -340
  33. package/p5-tests/unit/core/p5.Element.js +0 -773
  34. package/p5-tests/unit/core/p5.Graphics.js +0 -179
  35. package/p5-tests/unit/core/preload.js +0 -285
  36. package/p5-tests/unit/core/rendering.js +0 -116
  37. package/p5-tests/unit/core/structure.js +0 -293
  38. package/p5-tests/unit/core/transform.js +0 -144
  39. package/p5-tests/unit/core/version.js +0 -28
  40. package/p5-tests/unit/core/vertex.js +0 -137
  41. package/p5-tests/unit/dom/dom.js +0 -2146
  42. package/p5-tests/unit/events/acceleration.js +0 -213
  43. package/p5-tests/unit/events/keyboard.js +0 -179
  44. package/p5-tests/unit/events/mouse.js +0 -487
  45. package/p5-tests/unit/events/touch.js +0 -180
  46. package/p5-tests/unit/image/downloading.js +0 -379
  47. package/p5-tests/unit/image/filters.js +0 -92
  48. package/p5-tests/unit/image/loading.js +0 -413
  49. package/p5-tests/unit/image/p5.Image.js +0 -201
  50. package/p5-tests/unit/image/pixels.js +0 -234
  51. package/p5-tests/unit/io/files.js +0 -378
  52. package/p5-tests/unit/io/loadBytes.js +0 -149
  53. package/p5-tests/unit/io/loadImage.js +0 -123
  54. package/p5-tests/unit/io/loadJSON.js +0 -185
  55. package/p5-tests/unit/io/loadModel.js +0 -215
  56. package/p5-tests/unit/io/loadShader.js +0 -176
  57. package/p5-tests/unit/io/loadStrings.js +0 -140
  58. package/p5-tests/unit/io/loadTable.js +0 -183
  59. package/p5-tests/unit/io/loadXML.js +0 -127
  60. package/p5-tests/unit/io/saveModel.js +0 -113
  61. package/p5-tests/unit/io/saveTable.js +0 -142
  62. package/p5-tests/unit/math/calculation.js +0 -452
  63. package/p5-tests/unit/math/noise.js +0 -66
  64. package/p5-tests/unit/math/p5.Vector.js +0 -1886
  65. package/p5-tests/unit/math/random.js +0 -177
  66. package/p5-tests/unit/math/trigonometry.js +0 -144
  67. package/p5-tests/unit/spec.js +0 -50
  68. package/p5-tests/unit/typography/attributes.js +0 -120
  69. package/p5-tests/unit/typography/loadFont.js +0 -162
  70. package/p5-tests/unit/typography/p5.Font.js +0 -63
  71. package/p5-tests/unit/utilities/conversion.js +0 -329
  72. package/p5-tests/unit/utilities/time_date.js +0 -133
@@ -1,379 +0,0 @@
1
- suite('downloading animated gifs', function() {
2
- let myp5;
3
- let myGif;
4
-
5
- setup(function(done) {
6
- new p5(function(p) {
7
- p.setup = function() {
8
- myp5 = p;
9
- done();
10
- };
11
- });
12
- });
13
-
14
- teardown(function() {
15
- myp5.remove();
16
- });
17
-
18
- let imagePath = 'unit/assets/nyan_cat.gif';
19
-
20
- setup(function disableFileLoadError() {
21
- sinon.stub(p5, '_friendlyFileLoadError');
22
- });
23
-
24
- teardown(function restoreFileLoadError() {
25
- p5._friendlyFileLoadError.restore();
26
- });
27
-
28
- setup(function loadMyGif(done) {
29
- myp5.loadImage(imagePath, function(pImg) {
30
- myGif = pImg;
31
- done();
32
- });
33
- });
34
-
35
- suite('p5.prototype.encodeAndDownloadGif', function() {
36
- test('should be a function', function() {
37
- assert.ok(myp5.encodeAndDownloadGif);
38
- assert.typeOf(myp5.encodeAndDownloadGif, 'function');
39
- });
40
- test('should not throw an error', function() {
41
- myp5.encodeAndDownloadGif(myGif);
42
- });
43
- testWithDownload('should download a gif', function(blobContainer) {
44
- myp5.encodeAndDownloadGif(myGif);
45
- let gifBlob = blobContainer.blob;
46
- assert.strictEqual(gifBlob.type, 'image/gif');
47
- });
48
- });
49
- });
50
-
51
- suite('p5.prototype.saveCanvas', function() {
52
- let myp5;
53
- let myCanvas;
54
-
55
- let waitForBlob = async function(blc) {
56
- let sleep = function(ms) {
57
- return new Promise(r => setTimeout(r, ms));
58
- };
59
- while (!blc.blob) {
60
- await sleep(5);
61
- }
62
- };
63
- setup(function(done) {
64
- new p5(function(p) {
65
- p.setup = function() {
66
- myp5 = p;
67
- myCanvas = p.createCanvas(20, 20);
68
- p.background(255, 0, 0);
69
- done();
70
- };
71
- });
72
- });
73
-
74
- teardown(function() {
75
- myp5.remove();
76
- });
77
-
78
- test('should be a function', function() {
79
- assert.ok(myp5.saveCanvas);
80
- assert.typeOf(myp5.saveCanvas, 'function');
81
- });
82
-
83
- // Why use testWithDownload for 'no friendly-err' tests here?
84
- // saveCanvas uses htmlcanvas.toBlob which uses a callback
85
- // mechanism and the download is triggered in its callback.
86
- // It may happen that the test get out of sync and the only way
87
- // to know if the callback has been called is if the blob has
88
- // been made available to us
89
- testWithDownload(
90
- 'no friendly-err-msg I',
91
- async function(blc) {
92
- assert.doesNotThrow(
93
- function() {
94
- myp5.saveCanvas();
95
- },
96
- Error,
97
- 'got unwanted exception'
98
- );
99
- await waitForBlob(blc);
100
- },
101
- true
102
- );
103
- testWithDownload(
104
- 'no friendly-err-msg II',
105
- async function(blc) {
106
- assert.doesNotThrow(
107
- function() {
108
- myp5.saveCanvas('filename');
109
- },
110
- Error,
111
- 'got unwanted exception'
112
- );
113
- await waitForBlob(blc);
114
- },
115
- true
116
- );
117
- testWithDownload(
118
- 'no friendly-err-msg III',
119
- async function(blc) {
120
- assert.doesNotThrow(
121
- function() {
122
- myp5.saveCanvas('filename', 'png');
123
- },
124
- Error,
125
- 'got unwanted exception'
126
- );
127
- await waitForBlob(blc);
128
- },
129
- true
130
- );
131
- testWithDownload(
132
- 'no friendly-err-msg IV',
133
- async function(blc) {
134
- assert.doesNotThrow(
135
- function() {
136
- myp5.saveCanvas(myCanvas, 'filename');
137
- },
138
- Error,
139
- 'got unwanted exception'
140
- );
141
- await waitForBlob(blc);
142
- },
143
- true
144
- );
145
- testWithDownload(
146
- 'no friendly-err-msg V',
147
- async function(blc) {
148
- assert.doesNotThrow(
149
- function() {
150
- myp5.saveCanvas(myCanvas, 'filename', 'png');
151
- },
152
- Error,
153
- 'got unwanted exception'
154
- );
155
- },
156
- true
157
- );
158
- testWithDownload(
159
- 'no friendly-err-msg VI',
160
- async function(blc) {
161
- assert.doesNotThrow(
162
- function() {
163
- myp5.saveCanvas(myCanvas, 'filename', 'png');
164
- },
165
- Error,
166
- 'got unwanted exception'
167
- );
168
- await waitForBlob(blc);
169
- },
170
- true
171
- );
172
-
173
- testUnMinified('wrong param type #0', function() {
174
- assert.validationError(function() {
175
- myp5.saveCanvas(5);
176
- });
177
- });
178
-
179
- testUnMinified('wrong param type #1', function() {
180
- assert.validationError(function() {
181
- myp5.saveCanvas(myCanvas, 5);
182
- });
183
- });
184
-
185
- testUnMinified('wrong param type #2', function() {
186
- assert.validationError(function() {
187
- myp5.saveCanvas(myCanvas, 'filename', 5);
188
- });
189
- });
190
-
191
- testWithDownload(
192
- 'should download a png file',
193
- async function(blobContainer) {
194
- myp5.saveCanvas();
195
- // since a function with callback is used in saveCanvas
196
- // until the blob is made available to us.
197
- await waitForBlob(blobContainer);
198
- let myBlob = blobContainer.blob;
199
- assert.strictEqual(myBlob.type, 'image/png');
200
- },
201
- true
202
- );
203
-
204
- testWithDownload(
205
- 'should download a jpg file I',
206
- async function(blobContainer) {
207
- myp5.saveCanvas('filename.jpg');
208
- await waitForBlob(blobContainer);
209
- let myBlob = blobContainer.blob;
210
- assert.strictEqual(myBlob.type, 'image/jpeg');
211
- },
212
- true
213
- );
214
-
215
- testWithDownload(
216
- 'should download a jpg file II',
217
- async function(blobContainer) {
218
- myp5.saveCanvas('filename', 'jpg');
219
- await waitForBlob(blobContainer);
220
- let myBlob = blobContainer.blob;
221
- assert.strictEqual(myBlob.type, 'image/jpeg');
222
- },
223
- true
224
- );
225
- });
226
-
227
- suite('p5.prototype.saveFrames', function() {
228
- setup(function(done) {
229
- new p5(function(p) {
230
- p.setup = function() {
231
- myp5 = p;
232
- p.createCanvas(10, 10);
233
- done();
234
- };
235
- });
236
- });
237
-
238
- teardown(function() {
239
- myp5.remove();
240
- });
241
-
242
- test('should be a function', function() {
243
- assert.ok(myp5.saveFrames);
244
- assert.typeOf(myp5.saveFrames, 'function');
245
- });
246
-
247
- test('no friendly-err-msg I', function() {
248
- assert.doesNotThrow(
249
- function() {
250
- myp5.saveFrames('out', 'png', 0.1, 25);
251
- },
252
- Error,
253
- 'got unwanted exception'
254
- );
255
- });
256
- test('no friendly-err-msg II', function(done) {
257
- assert.doesNotThrow(
258
- function() {
259
- myp5.saveFrames('out', 'png', 0.1, 25, () => {
260
- done();
261
- });
262
- },
263
- Error,
264
- 'got unwanted exception'
265
- );
266
- });
267
-
268
- testUnMinified('missing param #2 #3', function() {
269
- assert.validationError(function() {
270
- myp5.saveFrames('out', 'png');
271
- });
272
- });
273
- testUnMinified('wrong param type #0', function() {
274
- assert.validationError(function() {
275
- myp5.saveFrames(0, 'png', 0.1, 25);
276
- });
277
- });
278
- testUnMinified('wrong param type #1', function() {
279
- assert.validationError(function() {
280
- myp5.saveFrames('out', 1, 0.1, 25);
281
- });
282
- });
283
- testUnMinified('wrong param type #2', function() {
284
- assert.validationError(function() {
285
- myp5.saveFrames('out', 'png', 'a', 25);
286
- });
287
- });
288
- testUnMinified('wrong param type #3', function() {
289
- assert.validationError(function() {
290
- myp5.saveFrames('out', 'png', 0.1, 'b');
291
- });
292
- });
293
- testUnMinified('wrong param type #4', function() {
294
- assert.validationError(function() {
295
- myp5.saveFrames('out', 'png', 0.1, 25, 5);
296
- });
297
- });
298
-
299
- test('should get frames in callback (png)', function(done) {
300
- myp5.saveFrames('aaa', 'png', 0.5, 25, function cb1(arr) {
301
- assert.typeOf(arr, 'array', 'we got an array');
302
- for (let i = 0; i < arr.length; i++) {
303
- assert.ok(arr[i].imageData);
304
- assert.strictEqual(arr[i].ext, 'png');
305
- assert.strictEqual(arr[i].filename, `aaa${i}`);
306
- }
307
- done();
308
- });
309
- });
310
-
311
- test('should get frames in callback (jpg)', function(done) {
312
- myp5.saveFrames('bbb', 'jpg', 0.5, 25, function cb2(arr2) {
313
- assert.typeOf(arr2, 'array', 'we got an array');
314
- for (let i = 0; i < arr2.length; i++) {
315
- assert.ok(arr2[i].imageData);
316
- assert.strictEqual(arr2[i].ext, 'jpg');
317
- assert.strictEqual(arr2[i].filename, `bbb${i}`);
318
- }
319
- done();
320
- });
321
- });
322
- });
323
-
324
- suite('p5.prototype.saveGif', function() {
325
- setup(function(done) {
326
- new p5(function(p) {
327
- p.setup = function() {
328
- myp5 = p;
329
- p.createCanvas(10, 10);
330
- done();
331
- };
332
- });
333
- });
334
-
335
- teardown(function() {
336
- myp5.remove();
337
- });
338
-
339
- test('should be a function', function() {
340
- assert.ok(myp5.saveGif);
341
- assert.typeOf(myp5.saveGif, 'function');
342
- });
343
-
344
- test('should not throw an error', function() {
345
- myp5.saveGif('myGif', 3);
346
- });
347
-
348
- test('should not throw an error', function() {
349
- myp5.saveGif('myGif', 3, { delay: 2, frames: 'seconds' });
350
- });
351
-
352
- test('wrong parameter type #0', function(done) {
353
- assert.validationError(function() {
354
- myp5.saveGif(2, 2);
355
- done();
356
- });
357
- });
358
-
359
- test('wrong parameter type #1', function(done) {
360
- assert.validationError(function() {
361
- myp5.saveGif('mySketch', '2');
362
- done();
363
- });
364
- });
365
-
366
- test('wrong parameter type #2', function(done) {
367
- assert.validationError(function() {
368
- myp5.saveGif('mySketch', 2, 'delay');
369
- done();
370
- });
371
- });
372
-
373
- testWithDownload('should download a GIF', async function(blobContainer) {
374
- myp5.saveGif(myGif, 3, 2);
375
- await waitForBlob(blobContainer);
376
- let gifBlob = blobContainer.blob;
377
- assert.strictEqual(gifBlob.type, 'image/gif');
378
- });
379
- });
@@ -1,92 +0,0 @@
1
- suite('Filters', function() {
2
- var myp5;
3
- let img;
4
- setup(function(done) {
5
- new p5(function(p) {
6
- p.setup = function() {
7
- myp5 = p;
8
- myp5.createCanvas(10, 10);
9
- img = myp5.createImage(10, 10);
10
- myp5.pixelDensity(1);
11
- img.loadPixels();
12
- for (let i = 0; i < img.width; i++) {
13
- for (let j = 0; j < img.height; j++) {
14
- img.set(i, j, myp5.color(120, 20, 40));
15
- }
16
- }
17
- img.updatePixels();
18
- done();
19
- };
20
- });
21
- });
22
-
23
- teardown(function() {
24
- myp5.remove();
25
- });
26
-
27
- test('threshold filter. less than threshold', function() {
28
- img.filter(myp5.THRESHOLD);
29
- myp5.image(img, 0, 0);
30
- myp5.loadPixels();
31
- for (let i = 0; i < img.width * img.height; i += 4) {
32
- assert.strictEqual(myp5.pixels[i], 0);
33
- assert.strictEqual(myp5.pixels[i + 1], 0);
34
- assert.strictEqual(myp5.pixels[i + 2], 0);
35
- }
36
- });
37
-
38
- test('threshold filter. greater than threshold', function() {
39
- img.loadPixels();
40
- for (let i = 0; i < img.width; i++) {
41
- for (let j = 0; j < img.height; j++) {
42
- img.set(i, j, myp5.color(211, 228, 250));
43
- }
44
- }
45
- img.updatePixels();
46
- img.filter(myp5.THRESHOLD);
47
- myp5.image(img, 0, 0);
48
- myp5.loadPixels();
49
- for (let i = 0; i < img.width * img.height; i += 4) {
50
- assert.strictEqual(myp5.pixels[i], 255);
51
- assert.strictEqual(myp5.pixels[i + 1], 255);
52
- assert.strictEqual(myp5.pixels[i + 2], 255);
53
- }
54
- });
55
-
56
- test('gray filter', function() {
57
- img.filter(myp5.GRAY);
58
- myp5.image(img, 0, 0);
59
- myp5.loadPixels();
60
- for (let i = 0; i < img.width * img.height; i += 4) {
61
- assert.strictEqual(myp5.pixels[i], myp5.pixels[i + 1]); // r, g, b values should be equal for gray
62
- assert.strictEqual(myp5.pixels[i + 1], myp5.pixels[i + 2]);
63
- }
64
- });
65
-
66
- test('opaque filter', function() {
67
- img.loadPixels();
68
- for (let i = 0; i < img.width; i++) {
69
- for (let j = 0; j < img.height; j++) {
70
- img.set(i, j, myp5.color(120, 20, 40, 10));
71
- }
72
- }
73
- img.updatePixels();
74
- img.filter(myp5.OPAQUE);
75
- myp5.image(img, 0, 0);
76
- myp5.loadPixels();
77
- for (let i = 0; i < img.width * img.height; i += 4) {
78
- assert.strictEqual(myp5.pixels[i + 3], 255); // 'a' value should be 255 after OPAQUE filter
79
- }
80
- });
81
-
82
- test('invert filter', function() {
83
- img.filter(myp5.INVERT);
84
- myp5.image(img, 0, 0);
85
- myp5.loadPixels();
86
- for (let i = 0; i < img.width * img.height; i += 4) {
87
- assert.strictEqual(myp5.pixels[i], 135);
88
- assert.strictEqual(myp5.pixels[i + 1], 235);
89
- assert.strictEqual(myp5.pixels[i + 2], 215);
90
- }
91
- });
92
- });