q5 2.10.7 → 2.10.8

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 (69) hide show
  1. package/deno.json +35 -0
  2. package/package.json +3 -6
  3. package/q5-deno-server.js +38 -0
  4. package/q5-server.js +3 -3
  5. package/q5.js +14 -8
  6. package/q5.min.js +1 -1
  7. package/src/q5-canvas.js +14 -8
  8. package/test/core.test.js +33 -0
  9. package/test/readme.md +5 -0
  10. package/.vscode/launch.json +0 -26
  11. package/.vscode/settings.json +0 -3
  12. package/bun.lockb +0 -0
  13. package/p5-tests/js/chai_helpers.js +0 -20
  14. package/p5-tests/js/mocha_setup.js +0 -2
  15. package/p5-tests/js/modernizr.js +0 -5
  16. package/p5-tests/js/p5_helpers.js +0 -135
  17. package/p5-tests/js/sinon.js +0 -5949
  18. package/p5-tests/mocha.css +0 -289
  19. package/p5-tests/test.html +0 -71
  20. package/p5-tests/unit/color/color_conversion.js +0 -68
  21. package/p5-tests/unit/color/creating_reading.js +0 -217
  22. package/p5-tests/unit/color/p5.Color.js +0 -1000
  23. package/p5-tests/unit/color/setting.js +0 -289
  24. package/p5-tests/unit/core/2d_primitives.js +0 -490
  25. package/p5-tests/unit/core/attributes.js +0 -115
  26. package/p5-tests/unit/core/curves.js +0 -139
  27. package/p5-tests/unit/core/environment.js +0 -248
  28. package/p5-tests/unit/core/error_helpers.js +0 -1158
  29. package/p5-tests/unit/core/main.js +0 -340
  30. package/p5-tests/unit/core/p5.Element.js +0 -773
  31. package/p5-tests/unit/core/p5.Graphics.js +0 -179
  32. package/p5-tests/unit/core/preload.js +0 -285
  33. package/p5-tests/unit/core/rendering.js +0 -116
  34. package/p5-tests/unit/core/structure.js +0 -293
  35. package/p5-tests/unit/core/transform.js +0 -144
  36. package/p5-tests/unit/core/version.js +0 -28
  37. package/p5-tests/unit/core/vertex.js +0 -137
  38. package/p5-tests/unit/dom/dom.js +0 -2146
  39. package/p5-tests/unit/events/acceleration.js +0 -213
  40. package/p5-tests/unit/events/keyboard.js +0 -179
  41. package/p5-tests/unit/events/mouse.js +0 -487
  42. package/p5-tests/unit/events/touch.js +0 -180
  43. package/p5-tests/unit/image/downloading.js +0 -379
  44. package/p5-tests/unit/image/filters.js +0 -92
  45. package/p5-tests/unit/image/loading.js +0 -413
  46. package/p5-tests/unit/image/p5.Image.js +0 -201
  47. package/p5-tests/unit/image/pixels.js +0 -234
  48. package/p5-tests/unit/io/files.js +0 -378
  49. package/p5-tests/unit/io/loadBytes.js +0 -149
  50. package/p5-tests/unit/io/loadImage.js +0 -123
  51. package/p5-tests/unit/io/loadJSON.js +0 -185
  52. package/p5-tests/unit/io/loadModel.js +0 -215
  53. package/p5-tests/unit/io/loadShader.js +0 -176
  54. package/p5-tests/unit/io/loadStrings.js +0 -140
  55. package/p5-tests/unit/io/loadTable.js +0 -183
  56. package/p5-tests/unit/io/loadXML.js +0 -127
  57. package/p5-tests/unit/io/saveModel.js +0 -113
  58. package/p5-tests/unit/io/saveTable.js +0 -142
  59. package/p5-tests/unit/math/calculation.js +0 -452
  60. package/p5-tests/unit/math/noise.js +0 -66
  61. package/p5-tests/unit/math/p5.Vector.js +0 -1886
  62. package/p5-tests/unit/math/random.js +0 -177
  63. package/p5-tests/unit/math/trigonometry.js +0 -144
  64. package/p5-tests/unit/spec.js +0 -50
  65. package/p5-tests/unit/typography/attributes.js +0 -120
  66. package/p5-tests/unit/typography/loadFont.js +0 -162
  67. package/p5-tests/unit/typography/p5.Font.js +0 -63
  68. package/p5-tests/unit/utilities/conversion.js +0 -329
  69. package/p5-tests/unit/utilities/time_date.js +0 -133
@@ -1,413 +0,0 @@
1
- /**
2
- * Expects an image file and a p5 instance with an image file loaded and drawn
3
- * and checks that they are exactly the same. Sends result to the callback.
4
- */
5
- var testImageRender = function(file, sketch) {
6
- sketch.loadPixels();
7
- var p = sketch.pixels;
8
- var ctx = sketch;
9
-
10
- sketch.clear();
11
-
12
- return new Promise(function(resolve, reject) {
13
- sketch.loadImage(file, resolve, reject);
14
- }).then(function(img) {
15
- ctx.image(img, 0, 0);
16
-
17
- ctx.loadPixels();
18
- var n = 0;
19
- for (var i = 0; i < p.length; i++) {
20
- var diff = Math.abs(p[i] - ctx.pixels[i]);
21
- n += diff;
22
- }
23
- var same = n === 0 && ctx.pixels.length === p.length;
24
- return same;
25
- });
26
- };
27
-
28
- suite('loading images', function() {
29
- var myp5;
30
-
31
- setup(function(done) {
32
- new p5(function(p) {
33
- p.setup = function() {
34
- myp5 = p;
35
- done();
36
- };
37
-
38
- // Make sure draw() exists so timing functions still run each frame
39
- // and we can test gif animation
40
- p.draw = function() {};
41
- });
42
- });
43
-
44
- teardown(function() {
45
- myp5.remove();
46
- });
47
-
48
- var imagePath = 'unit/assets/cat.jpg';
49
-
50
- setup(function disableFileLoadError() {
51
- sinon.stub(p5, '_friendlyFileLoadError');
52
- });
53
-
54
- teardown(function restoreFileLoadError() {
55
- p5._friendlyFileLoadError.restore();
56
- });
57
-
58
- test('should call successCallback when image loads', function() {
59
- return new Promise(function(resolve, reject) {
60
- myp5.loadImage(imagePath, resolve, reject);
61
- }).then(function(pImg) {
62
- assert.ok(pImg, 'cat.jpg loaded');
63
- assert.isTrue(pImg instanceof p5.Image);
64
- });
65
- });
66
-
67
- test('should call failureCallback when unable to load image', function() {
68
- return new Promise(function(resolve, reject) {
69
- myp5.loadImage(
70
- 'invalid path',
71
- function(pImg) {
72
- reject('Entered success callback.');
73
- },
74
- resolve
75
- );
76
- }).then(function(event) {
77
- assert.equal(event.type, 'error');
78
- assert.isTrue(p5._friendlyFileLoadError.called);
79
- });
80
- });
81
-
82
- test('should draw image with defaults', function() {
83
- return new Promise(function(resolve, reject) {
84
- myp5.loadImage('unit/assets/cat.jpg', resolve, reject);
85
- }).then(function(img) {
86
- myp5.image(img, 0, 0);
87
- return testImageRender('unit/assets/cat.jpg', myp5).then(function(res) {
88
- assert.isTrue(res);
89
- });
90
- });
91
- });
92
-
93
- test('static image should not have gifProperties', function() {
94
- return new Promise(function(resolve, reject) {
95
- myp5.loadImage('unit/assets/cat.jpg', resolve, reject);
96
- }).then(function(img) {
97
- assert.isTrue(img.gifProperties === null);
98
- });
99
- });
100
-
101
- test('single frame GIF should not have gifProperties', function() {
102
- return new Promise(function(resolve, reject) {
103
- myp5.loadImage('unit/assets/target_small.gif', resolve, reject);
104
- }).then(function(img) {
105
- assert.isTrue(img.gifProperties === null);
106
- });
107
- });
108
-
109
- test('first frame of GIF should be painted after load', function() {
110
- return new Promise(function(resolve, reject) {
111
- myp5.loadImage('unit/assets/white_black.gif', resolve, reject);
112
- }).then(function(img) {
113
- assert.deepEqual(img.get(0, 0), [255, 255, 255, 255]);
114
- });
115
- });
116
-
117
- test('animated gifs animate correctly', function() {
118
- const wait = function(ms) {
119
- return new Promise(function(resolve) {
120
- setTimeout(resolve, ms);
121
- });
122
- };
123
- let img;
124
- return new Promise(function(resolve, reject) {
125
- img = myp5.loadImage('unit/assets/nyan_cat.gif', resolve, reject);
126
- }).then(function() {
127
- assert.equal(img.gifProperties.displayIndex, 0);
128
- myp5.image(img, 0, 0);
129
-
130
- // This gif has frames that are around for 100ms each.
131
- // After 100ms has elapsed, the display index should
132
- // increment when we draw the image.
133
- return wait(100);
134
- }).then(function() {
135
- return new Promise(function(resolve) {
136
- window.requestAnimationFrame(resolve);
137
- });
138
- }).then(function() {
139
- myp5.image(img, 0, 0);
140
- assert.equal(img.gifProperties.displayIndex, 1);
141
- });
142
- });
143
-
144
- var backgroundColor = [135, 206, 235, 255];
145
- var blue = [0, 0, 255, 255];
146
- var transparent = [0, 0, 0, 0];
147
- test('animated gifs work with no disposal', function() {
148
- return new Promise(function(resolve, reject) {
149
- myp5.loadImage('unit/assets/dispose_none.gif', resolve, reject);
150
- }).then(function(img) {
151
- // Frame 0 shows the background
152
- assert.deepEqual(img.get(7, 12), backgroundColor);
153
- // Frame 1 draws on top of the background
154
- img.setFrame(1);
155
- assert.deepEqual(img.get(7, 12), blue);
156
- // Frame 2 does not erase untouched parts of frame 2
157
- img.setFrame(2);
158
- assert.deepEqual(img.get(7, 12), blue);
159
- });
160
- });
161
-
162
- test('animated gifs work with background disposal', function() {
163
- return new Promise(function(resolve, reject) {
164
- myp5.loadImage('unit/assets/dispose_background.gif', resolve, reject);
165
- }).then(function(img) {
166
- // Frame 0 shows the background
167
- assert.deepEqual(img.get(7, 12), backgroundColor);
168
- // Frame 1 draws on top of the background
169
- img.setFrame(1);
170
- assert.deepEqual(img.get(7, 12), blue);
171
- // Frame 2 erases the content added in frame 2
172
- img.setFrame(2);
173
- assert.deepEqual(img.get(7, 12), transparent);
174
- });
175
- });
176
-
177
- test('animated gifs work with previous disposal', function() {
178
- return new Promise(function(resolve, reject) {
179
- myp5.loadImage('unit/assets/dispose_previous.gif', resolve, reject);
180
- }).then(function(img) {
181
- // Frame 0 shows the background
182
- assert.deepEqual(img.get(7, 12), backgroundColor);
183
- // Frame 1 draws on top of the background
184
- img.setFrame(1);
185
- assert.deepEqual(img.get(7, 12), blue);
186
- // Frame 2 returns the content added in frame 2 to its previous value
187
- img.setFrame(2);
188
- assert.deepEqual(img.get(7, 12), backgroundColor);
189
- });
190
- });
191
-
192
- /* TODO: make this resilient to platform differences in image resizing.
193
- test('should draw cropped image', function() {
194
- return new Promise(function(resolve, reject) {
195
- myp5.loadImage('unit/assets/target.gif', resolve, reject);
196
- }).then(function(img) {
197
- myp5.image(img, 0, 0, 6, 6, 5, 5, 6, 6);
198
- return testImageRender('unit/assets/target_small.gif', myp5).then(
199
- function(res) {
200
- assert.isTrue(res);
201
- }
202
- );
203
- });
204
- });
205
- */
206
-
207
- // Test loading image in preload() with success callback
208
- test('Test in preload() with success callback');
209
- test('Test in setup() after preload()');
210
- // These tests don't work correctly (You can't use suite and test like that)
211
- // they simply get added at the root level.
212
- var mySketch = function(this_p5) {
213
- var myImage;
214
- this_p5.preload = function() {
215
- suite('Test in preload() with success callback', function() {
216
- test('Load asynchronously and use success callback', function(done) {
217
- myImage = this_p5.loadImage('unit/assets/cat.jpg', function() {
218
- assert.ok(myImage);
219
- done();
220
- });
221
- });
222
- });
223
- };
224
-
225
- this_p5.setup = function() {
226
- suite('setup() after preload() with success callback', function() {
227
- test('should be loaded if preload() finished', function(done) {
228
- assert.isTrue(myImage instanceof p5.Image);
229
- assert.isTrue(myImage.width > 0 && myImage.height > 0);
230
- done();
231
- });
232
- });
233
- };
234
- };
235
- new p5(mySketch, null, false);
236
-
237
- // Test loading image in preload() without success callback
238
- mySketch = function(this_p5) {
239
- var myImage;
240
- this_p5.preload = function() {
241
- myImage = this_p5.loadImage('unit/assets/cat.jpg');
242
- };
243
-
244
- this_p5.setup = function() {
245
- suite('setup() after preload() without success callback', function() {
246
- test('should be loaded now preload() finished', function(done) {
247
- assert.isTrue(myImage instanceof p5.Image);
248
- assert.isTrue(myImage.width > 0 && myImage.height > 0);
249
- done();
250
- });
251
- });
252
- };
253
- };
254
- new p5(mySketch, null, false);
255
- });
256
-
257
- suite('displaying images', function() {
258
- var myp5;
259
- var pImg;
260
- var imagePath = 'unit/assets/cat-with-hole.png';
261
- var chanNames = ['red', 'green', 'blue', 'alpha'];
262
-
263
- setup(function(done) {
264
- new p5(function(p) {
265
- p.setup = function() {
266
- myp5 = p;
267
- myp5.pixelDensity(1);
268
- myp5.loadImage(
269
- imagePath,
270
- function(img) {
271
- pImg = img;
272
- myp5.resizeCanvas(pImg.width, pImg.height);
273
- done();
274
- },
275
- function() {
276
- throw new Error('Error loading image');
277
- }
278
- );
279
- };
280
- });
281
- });
282
-
283
- teardown(function() {
284
- myp5.remove();
285
- });
286
-
287
- function checkTint(tintColor) {
288
- myp5.loadPixels();
289
- pImg.loadPixels();
290
- for (var i = 0; i < myp5.pixels.length; i += 4) {
291
- var x = (i / 4) % myp5.width;
292
- var y = Math.floor(i / 4 / myp5.width);
293
- for (var chan = 0; chan < tintColor.length; chan++) {
294
- var inAlpha = 1;
295
- var outAlpha = 1;
296
- if (chan < 3) {
297
- // The background of the canvas is black, so after applying the
298
- // image's own alpha + the tint alpha to its color channels, we
299
- // should arrive at the same color that we see on the canvas.
300
- inAlpha = tintColor[3] / 255;
301
- outAlpha = pImg.pixels[i + 3] / 255;
302
-
303
- // Applying the tint involves un-multiplying the alpha of the source
304
- // image, which causes a bit of loss of precision. I'm allowing a
305
- // loss of 10 / 255 in this test.
306
- assert.approximately(
307
- myp5.pixels[i + chan],
308
- pImg.pixels[i + chan] *
309
- (tintColor[chan] / 255) *
310
- outAlpha *
311
- inAlpha,
312
- 10,
313
- 'Tint output for the ' +
314
- chanNames[chan] +
315
- ' channel of pixel (' +
316
- x +
317
- ', ' +
318
- y +
319
- ') should be equivalent to multiplying the image value by tint fraction'
320
- );
321
- }
322
- }
323
- }
324
- }
325
-
326
- test('tint() with color', function() {
327
- assert.ok(pImg, 'image loaded');
328
- var tintColor = [150, 100, 50, 255];
329
- myp5.clear();
330
- myp5.background(0);
331
- myp5.tint(tintColor[0], tintColor[1], tintColor[2], tintColor[3]);
332
- myp5.image(pImg, 0, 0);
333
-
334
- checkTint(tintColor);
335
- });
336
-
337
- test('tint() with alpha', function() {
338
- assert.ok(pImg, 'image loaded');
339
- var tintColor = [255, 255, 255, 100];
340
- myp5.clear();
341
- myp5.background(0);
342
- myp5.tint(tintColor[0], tintColor[1], tintColor[2], tintColor[3]);
343
- myp5.image(pImg, 0, 0);
344
-
345
- checkTint(tintColor);
346
- });
347
-
348
- test('tint() with color and alpha', function() {
349
- assert.ok(pImg, 'image loaded');
350
- var tintColor = [255, 100, 50, 100];
351
- myp5.clear();
352
- myp5.background(0);
353
- myp5.tint(tintColor[0], tintColor[1], tintColor[2], tintColor[3]);
354
- myp5.image(pImg, 0, 0);
355
-
356
- checkTint(tintColor);
357
- });
358
- });
359
-
360
- suite('displaying images that use fit mode', function() {
361
- var myp5;
362
-
363
- setup(function(done) {
364
- new p5(function(p) {
365
- p.setup = function() {
366
- myp5 = p;
367
- done();
368
- };
369
- });
370
- });
371
-
372
- teardown(function() {
373
- myp5.remove();
374
- });
375
-
376
- test('CONTAIN when source image is larger than destination', function() {
377
- let src = myp5.createImage(400, 1000);
378
- sinon.spy(myp5._renderer, 'image');
379
- myp5.image(src, 0, 0, 300, 400, 0, 0, 400, 1000, myp5.CONTAIN);
380
- assert(myp5._renderer.image.calledOnce);
381
- assert.equal(myp5._renderer.image.getCall(0).args[7], 400 / (1000 / 400)); // dw
382
- assert.equal(myp5._renderer.image.getCall(0).args[8], 1000 / (1000 / 400)); // dh
383
- });
384
-
385
- test('CONTAIN when source image is smaller than destination', function() {
386
- let src = myp5.createImage(40, 90);
387
- sinon.spy(myp5._renderer, 'image');
388
- myp5.image(src, 0, 0, 300, 500, 0, 0, 400, 1000, myp5.CONTAIN);
389
- assert(myp5._renderer.image.calledOnce);
390
- assert.equal(myp5._renderer.image.getCall(0).args[7], 40 / (90 / 500)); // dw
391
- assert.equal(myp5._renderer.image.getCall(0).args[8], 90 / (90 / 500)); // dh
392
- });
393
-
394
- test('COVER when source image is larger than destination', function() {
395
- let src = myp5.createImage(400, 1000);
396
- sinon.spy(myp5._renderer, 'image');
397
- myp5.image(src, 0, 0, 300, 400, 0, 0, 400, 1000, myp5.COVER);
398
- const r = Math.max(300 / 400, 400 / 1000);
399
- assert(myp5._renderer.image.calledOnce);
400
- assert.equal(myp5._renderer.image.getCall(0).args[3], 300 / r); // sw
401
- assert.equal(myp5._renderer.image.getCall(0).args[4], 400 / r); // sh
402
- });
403
-
404
- test('COVER when source image is smaller than destination', function() {
405
- let src = myp5.createImage(20, 100);
406
- sinon.spy(myp5._renderer, 'image');
407
- myp5.image(src, 0, 0, 300, 400, 0, 0, 20, 100, myp5.COVER);
408
- const r = Math.max(300 / 20, 400 / 100);
409
- assert(myp5._renderer.image.calledOnce);
410
- assert.equal(myp5._renderer.image.getCall(0).args[3], 300 / r); // sw
411
- assert.equal(myp5._renderer.image.getCall(0).args[4], 400 / r); // sh
412
- });
413
- });
@@ -1,201 +0,0 @@
1
- suite('p5.Image', function() {
2
- var myp5;
3
-
4
- setup(function(done) {
5
- new p5(function(p) {
6
- p.setup = function() {
7
- myp5 = p;
8
- done();
9
- };
10
- });
11
- });
12
-
13
- teardown(function() {
14
- myp5.remove();
15
- });
16
-
17
- suite('p5.prototype.createImage', function() {
18
- test('it creates an image', function() {
19
- let img = myp5.createImage(10, 17);
20
- assert.isObject(img);
21
- });
22
- });
23
-
24
- suite('p5.Image', function() {
25
- test('it has necessary properties', function() {
26
- let img = new p5.Image(100, 100);
27
- assert.property(img, 'width');
28
- assert.property(img, 'height');
29
- assert.property(img, 'canvas');
30
- assert.property(img, 'loadPixels');
31
- assert.property(img, 'pixels');
32
- assert.property(img, 'updatePixels');
33
- });
34
-
35
- test('height and width are correct', function() {
36
- let img = new p5.Image(100, 100);
37
- myp5.pixelDensity(1);
38
- assert.strictEqual(img.width, 100);
39
- assert.strictEqual(img.height, 100);
40
- });
41
- });
42
-
43
- suite('p5.Image.prototype.resize', function() {
44
- test('it should resize the image', function() {
45
- let img = myp5.createImage(10, 17);
46
- myp5.pixelDensity(1);
47
- img.resize(10, 30);
48
- assert.strictEqual(img.width, 10);
49
- assert.strictEqual(img.height, 30);
50
- });
51
- });
52
-
53
- suite('p5.Image.prototype.mask', function() {
54
- for (const density of [1, 2]) {
55
- test(`it should mask the image at pixel density ${density}`, function() {
56
- let img = myp5.createImage(10, 10);
57
- img.pixelDensity(density);
58
- img.loadPixels();
59
- for (let i = 0; i < img.height; i++) {
60
- for (let j = 0; j < img.width; j++) {
61
- let alpha = i < 5 ? 255 : 0;
62
- img.set(i, j, myp5.color(0, 0, 0, alpha));
63
- }
64
- }
65
- img.updatePixels();
66
-
67
- let mask = myp5.createImage(10, 10);
68
- mask.pixelDensity(density);
69
- mask.loadPixels();
70
- for (let i = 0; i < mask.width; i++) {
71
- for (let j = 0; j < mask.height; j++) {
72
- let alpha = j < 5 ? 255 : 0;
73
- mask.set(i, j, myp5.color(0, 0, 0, alpha));
74
- }
75
- }
76
- mask.updatePixels();
77
-
78
- img.mask(mask);
79
- img.loadPixels();
80
- for (let i = 0; i < img.width; i++) {
81
- for (let j = 0; j < img.height; j++) {
82
- let alpha = i < 5 && j < 5 ? 255 : 0;
83
- assert.strictEqual(img.get(i, j)[3], alpha);
84
- }
85
- }
86
- });
87
- }
88
-
89
- test('it should mask images of different density', function() {
90
- let img = myp5.createImage(10, 10);
91
- img.pixelDensity(1);
92
- img.loadPixels();
93
- for (let i = 0; i < img.height; i++) {
94
- for (let j = 0; j < img.width; j++) {
95
- let alpha = i < 5 ? 255 : 0;
96
- img.set(i, j, myp5.color(0, 0, 0, alpha));
97
- }
98
- }
99
- img.updatePixels();
100
-
101
- let mask = myp5.createImage(20, 20);
102
- mask.loadPixels();
103
- for (let i = 0; i < mask.width; i++) {
104
- for (let j = 0; j < mask.height; j++) {
105
- let alpha = j < 10 ? 255 : 0;
106
- mask.set(i, j, myp5.color(0, 0, 0, alpha));
107
- }
108
- }
109
- mask.updatePixels();
110
- mask.pixelDensity(2);
111
-
112
- img.mask(mask);
113
- img.loadPixels();
114
- for (let i = 0; i < img.width; i++) {
115
- for (let j = 0; j < img.height; j++) {
116
- let alpha = i < 5 && j < 5 ? 255 : 0;
117
- assert.strictEqual(img.get(i, j)[3], alpha);
118
- }
119
- }
120
- });
121
-
122
- test('it should mask images from createGraphics', function() {
123
- myp5.createCanvas(10,10);
124
- myp5.pixelDensity(2);
125
- let img = myp5.createGraphics(10,10);
126
- img.noStroke();
127
- img.rect(0,0,10,10);
128
- let mask = myp5.createGraphics(10,10);
129
- mask.noStroke();
130
- mask.rect(0,0,5,5);
131
- let masked = img.get();
132
- masked.mask(mask.get());
133
-
134
- for (let i = 0; i < masked.width; i++) {
135
- for (let j = 0; j < masked.height; j++) {
136
- let alpha = i < 5 && j < 5 ? 255 : 0;
137
- assert.strictEqual(masked.get(i, j)[3], alpha);
138
- }
139
- }
140
- });
141
-
142
- test('it should mask the animated gif image', function() {
143
- const imagePath = 'unit/assets/nyan_cat.gif';
144
- return new Promise(function(resolve, reject) {
145
- myp5.loadImage(imagePath, resolve, reject);
146
- }).then(function(img) {
147
- let mask = myp5.createImage(img.width, img.height);
148
- mask.loadPixels();
149
- for (let i = 0; i < mask.width; i++) {
150
- for (let j = 0; j < mask.height; j++) {
151
- const alpha = j < img.height / 2 ? 255 : 0;
152
- mask.set(i, j, myp5.color(0, 0, 0, alpha));
153
- }
154
- }
155
- mask.updatePixels();
156
-
157
- img.mask(mask);
158
- img.loadPixels();
159
- for (let i = 0; i < img.width; i++) {
160
- for (let j = 0; j < img.height; j++) {
161
- const alpha = j < img.height / 2 ? 255 : 0;
162
- assert.strictEqual(img.get(i, j)[3], alpha);
163
- }
164
- }
165
- for (
166
- frameIndex = 0;
167
- frameIndex < img.gifProperties.numFrames;
168
- frameIndex++
169
- ) {
170
- const frameData = img.gifProperties.frames[frameIndex].image.data;
171
- for (let i = 0; i < img.width; i++) {
172
- for (let j = 0; j < img.height; j++) {
173
- const index = 4 * (i + j * img.width) + 3;
174
- const alpha = j < img.height / 2 ? 255 : 0;
175
- assert.strictEqual(frameData[index], alpha);
176
- }
177
- }
178
- }
179
- });
180
- });
181
- });
182
-
183
- suite('p5.Graphics.get()', function() {
184
- for (const density of [1, 2]) {
185
- test(`width and height match at pixel density ${density}`, function() {
186
- const g = myp5.createGraphics(10, 10);
187
- g.pixelDensity(density);
188
- g.rect(2, 2, 5, 5);
189
-
190
- const img = g.get();
191
- assert.equal(g.width, img.width);
192
- assert.equal(g.height, img.height);
193
- assert.equal(g.pixelDensity(), img.pixelDensity());
194
-
195
- g.loadPixels();
196
- img.loadPixels();
197
- assert.deepEqual([...g.pixels], [...img.pixels]);
198
- });
199
- }
200
- });
201
- });