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,1000 +0,0 @@
1
- suite('p5.Color', 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
- var c;
18
-
19
- suite('p5.prototype.color(r,g,b)', function() {
20
- setup(function() {
21
- c = myp5.color(255, 0, 102);
22
- });
23
- test('should create instance of p5.Color', function() {
24
- assert.instanceOf(c, p5.Color);
25
- });
26
-
27
- test('should correctly set RGBA property', function() {
28
- assert.deepEqual(c.levels, [255, 0, 102, 255]);
29
- });
30
-
31
- test("shouldn't set HSBA property before hsb access func is called", function() {
32
- assert.equal(c.hsba, undefined);
33
- });
34
-
35
- test("shouldn't set HSLA property before hsb access func is called", function() {
36
- assert.equal(c.hsla, undefined);
37
- });
38
-
39
- test('color(): missing param #0 + throws error', function() {
40
- expect(function() {
41
- c = myp5.color();
42
- }).to.throw();
43
- });
44
- });
45
-
46
- suite('p5.prototype.color("#rgb")', function() {
47
- setup(function() {
48
- c = myp5.color('#f06');
49
- });
50
- test('should create instance of p5.Color', function() {
51
- assert.instanceOf(c, p5.Color);
52
- });
53
-
54
- test('should correctly set RGBA property', function() {
55
- assert.deepEqual(c.levels, [255, 0, 102, 255]);
56
- });
57
-
58
- suite('spot check', function() {
59
- test('numeric hex values', function() {
60
- c = myp5.color('#000');
61
- assert.deepEqual(c.levels, [0, 0, 0, 255]);
62
- });
63
-
64
- test('alphabetic hex values', function() {
65
- c = myp5.color('#fff');
66
- assert.deepEqual(c.levels, [255, 255, 255, 255]);
67
- });
68
-
69
- test('alphanumeric hex values', function() {
70
- c = myp5.color('#f00');
71
- assert.deepEqual(c.levels, [255, 0, 0, 255]);
72
- c = myp5.color('#f0e');
73
- assert.deepEqual(c.levels, [255, 0, 238, 255]);
74
- });
75
- });
76
-
77
- test('invalid hex values resolve to white', function() {
78
- c = myp5.color('#cat');
79
- assert.deepEqual(c.levels, [255, 255, 255, 255]);
80
- });
81
-
82
- test('should not be able to pass css & alpha', function() {
83
- // TODO: change this to expect p5.ValidationError when
84
- // color() docs are fixed.
85
- assert.throws(function() {
86
- c = myp5.color('#fff', 100);
87
- }, Error);
88
- });
89
- });
90
-
91
- suite('p5.prototype.color("#rgba")', function() {
92
- setup(function() {
93
- c = myp5.color('#f016');
94
- });
95
- test('should create instance of p5.Color', function() {
96
- assert.instanceOf(c, p5.Color);
97
- });
98
-
99
- test('should correctly set RGBA property', function() {
100
- assert.deepEqual(c.levels, [255, 0, 17, 102]);
101
- });
102
-
103
- suite('spot check', function() {
104
- test('numeric hex values', function() {
105
- c = myp5.color('#0000');
106
- assert.deepEqual(c.levels, [0, 0, 0, 0]);
107
- });
108
-
109
- test('alphabetic hex values', function() {
110
- c = myp5.color('#ffff');
111
- assert.deepEqual(c.levels, [255, 255, 255, 255]);
112
- });
113
-
114
- test('alphanumeric hex values', function() {
115
- c = myp5.color('#f007');
116
- assert.deepEqual(c.levels, [255, 0, 0, 119]);
117
- c = myp5.color('#f0e5');
118
- assert.deepEqual(c.levels, [255, 0, 238, 85]);
119
- });
120
- });
121
-
122
- test('invalid hex values resolve to white', function() {
123
- c = myp5.color('#fire');
124
- assert.deepEqual(c.levels, [255, 255, 255, 255]);
125
- });
126
- });
127
-
128
- suite('p5.prototype.color("#rrggbb")', function() {
129
- setup(function() {
130
- c = myp5.color('#ff0066');
131
- });
132
-
133
- test('should create instance of p5.Color', function() {
134
- assert.instanceOf(c, p5.Color);
135
- });
136
-
137
- test('should correctly set RGBA property', function() {
138
- assert.deepEqual(c.levels, [255, 0, 102, 255]);
139
- });
140
-
141
- suite('spot check', function() {
142
- test('numeric hex values', function() {
143
- c = myp5.color('#123456');
144
- assert.deepEqual(c.levels, [18, 52, 86, 255]);
145
- });
146
-
147
- test('alphabetic hex values', function() {
148
- c = myp5.color('#abcdef');
149
- assert.deepEqual(c.levels, [171, 205, 239, 255]);
150
- });
151
-
152
- test('alphanumeric hex values', function() {
153
- c = myp5.color('#a1a1a1');
154
- assert.deepEqual(c.levels, [161, 161, 161, 255]);
155
- c = myp5.color('#14ffa8');
156
- assert.deepEqual(c.levels, [20, 255, 168, 255]);
157
- });
158
- });
159
-
160
- test('invalid hex values resolve to white', function() {
161
- c = myp5.color('#zzztop');
162
- assert.deepEqual(c.levels, [255, 255, 255, 255]);
163
- });
164
- });
165
-
166
- suite('p5.prototype.color("#rrggbbaa")', function() {
167
- setup(function() {
168
- c = myp5.color('#f01dab1e');
169
- });
170
-
171
- test('should create instance of p5.Color', function() {
172
- assert.instanceOf(c, p5.Color);
173
- });
174
-
175
- test('should correctly set RGBA property', function() {
176
- assert.deepEqual(c.levels, [240, 29, 171, 30]);
177
- });
178
-
179
- suite('spot check', function() {
180
- test('numeric hex values', function() {
181
- c = myp5.color('#12345678');
182
- assert.deepEqual(c.levels, [18, 52, 86, 120]);
183
- });
184
-
185
- test('alphabetic hex values', function() {
186
- c = myp5.color('#abcdeffe');
187
- assert.deepEqual(c.levels, [171, 205, 239, 254]);
188
- });
189
-
190
- test('alphanumeric hex values', function() {
191
- c = myp5.color('#a1a1a1a1');
192
- assert.deepEqual(c.levels, [161, 161, 161, 161]);
193
- c = myp5.color('#14ffaca6');
194
- assert.deepEqual(c.levels, [20, 255, 172, 166]);
195
- });
196
- });
197
-
198
- test('invalid hex values resolve to white', function() {
199
- c = myp5.color('#c0vfefed');
200
- assert.deepEqual(c.levels, [255, 255, 255, 255]);
201
- });
202
- });
203
-
204
- suite('p5.prototype.color("rgb(r,g,b)")', function() {
205
- setup(function() {
206
- c = myp5.color('rgb(255,0,102)');
207
- });
208
- test('should create instance of p5.Color', function() {
209
- assert.instanceOf(c, p5.Color);
210
- });
211
-
212
- test('should correctly set RGBA property', function() {
213
- assert.deepEqual(c.levels, [255, 0, 102, 255]);
214
- });
215
-
216
- test('spot check variant spacing', function() {
217
- // Exhaustive testing of spacing variations within RGB format is
218
- // prohibitive: spot check a set of representative values
219
- c = myp5.color('rgb(0,0,0)');
220
- assert.deepEqual(c.levels, [0, 0, 0, 255]);
221
- c = myp5.color('rgb(0,100 ,0)');
222
- assert.deepEqual(c.levels, [0, 100, 0, 255]);
223
- c = myp5.color('rgb( 100,255,137)');
224
- assert.deepEqual(c.levels, [100, 255, 137, 255]);
225
- c = myp5.color('rgb(0, 50,0)');
226
- assert.deepEqual(c.levels, [0, 50, 0, 255]);
227
- c = myp5.color('rgb(0,100, 0)');
228
- assert.deepEqual(c.levels, [0, 100, 0, 255]);
229
- c = myp5.color('rgb( 111, 255, 57)');
230
- assert.deepEqual(c.levels, [111, 255, 57, 255]);
231
- c = myp5.color('rgb(40, 0, 0)');
232
- assert.deepEqual(c.levels, [40, 0, 0, 255]);
233
- c = myp5.color('rgb(0,255, 10 )');
234
- assert.deepEqual(c.levels, [0, 255, 10, 255]);
235
- });
236
-
237
- test('invalid RGB values resolve to white', function() {
238
- c = myp5.color('rgb(100.5, 40, 3)');
239
- assert.deepEqual(c.levels, [255, 255, 255, 255], 'decimal R value');
240
- c = myp5.color('rgb(100, 40.00009, 3)');
241
- assert.deepEqual(c.levels, [255, 255, 255, 255], 'decimal G value');
242
- c = myp5.color('rgb(100, 40, 3.14159265)');
243
- assert.deepEqual(c.levels, [255, 255, 255, 255], 'decimal B value');
244
- c = myp5.color('rgb(.9, 40, 3, 1.0)');
245
- assert.deepEqual(
246
- c.levels,
247
- [255, 255, 255, 255],
248
- 'decimal without leading 0'
249
- );
250
- c = myp5.color('skip a beat');
251
- assert.deepEqual(c.levels, [255, 255, 255, 255], 'non-color strings');
252
- });
253
- });
254
-
255
- suite('p5.prototype.color("rgb(r%,g%,b%)")', function() {
256
- setup(function() {
257
- c = myp5.color('rgb(100%, 0%, 40%)');
258
- });
259
- test('should create instance of p5.Color', function() {
260
- assert.instanceOf(c, p5.Color);
261
- });
262
-
263
- test('should correctly set RGBA property', function() {
264
- assert.deepEqual(c.levels, [255, 0, 102, 255]);
265
- });
266
-
267
- test('spot check variant spacing', function() {
268
- // Exhaustive testing of spacing variations within RGB format is
269
- // prohibitive: spot check a set of representative values
270
- c = myp5.color('rgb(100%,70%,100%)');
271
- assert.deepEqual(c.levels, [255, 179, 255, 255]);
272
- c = myp5.color('rgb(0%,0%,0% )');
273
- assert.deepEqual(c.levels, [0, 0, 0, 255]);
274
- c = myp5.color('rgb(0%,50% , 0%)');
275
- assert.deepEqual(c.levels, [0, 128, 0, 255]);
276
- c = myp5.color('rgb(10%, 50%,0%)');
277
- assert.deepEqual(c.levels, [26, 128, 0, 255]);
278
- c = myp5.color('rgb(0%,48%, 0%)');
279
- assert.deepEqual(c.levels, [0, 122, 0, 255]);
280
- c = myp5.color('rgb(0%, 0%, 40%)');
281
- assert.deepEqual(c.levels, [0, 0, 102, 255]);
282
- c = myp5.color('rgb(0%,87%, 10%)');
283
- assert.deepEqual(c.levels, [0, 222, 26, 255]);
284
- });
285
-
286
- test('spot check decimal percentage values', function() {
287
- // Percentage values in CSS <color> identifiers are floats 0.0%-100.0%
288
- c = myp5.color('rgb( 50%,100% ,.9%)');
289
- assert.deepEqual(c.levels, [128, 255, 2, 255], 'B% without leading 0');
290
- c = myp5.color('rgb( 9.90%, 12%, 50%)');
291
- assert.deepEqual(c.levels, [25, 31, 128, 255], 'decimal R%');
292
- });
293
-
294
- test('invalid percentage values default to white', function() {
295
- c = myp5.color('rgb(50, 100%, 100%');
296
- assert.deepEqual(
297
- c.levels,
298
- [255, 255, 255, 255],
299
- 'mixed percentage and non-percentage input'
300
- );
301
- c = myp5.color('rgb(,0%,0%)');
302
- assert.deepEqual(c.levels, [255, 255, 255, 255], 'missing values');
303
- c = myp5.color('rgb(A%,B%,C%)');
304
- assert.deepEqual(
305
- c.levels,
306
- [255, 255, 255, 255],
307
- 'non-numeric percentages'
308
- );
309
- });
310
- });
311
-
312
- suite('p5.prototype.color("rgba(r,g,b,a)")', function() {
313
- setup(function() {
314
- c = myp5.color('rgba(255,0,102,0.8)');
315
- });
316
-
317
- test('should create instance of p5.Color', function() {
318
- assert.instanceOf(c, p5.Color);
319
- });
320
-
321
- test('should correctly set RGBA property', function() {
322
- assert.deepEqual(c.levels, [255, 0, 102, 204]);
323
- });
324
-
325
- test('spot check variant spacing', function() {
326
- // Exhaustive testing of spacing variations within RGBA format is
327
- // prohibitive: spot check a set of representative values
328
- c = myp5.color('rgba(255,255,255,1)');
329
- assert.deepEqual(c.levels, [255, 255, 255, 255]);
330
- c = myp5.color('rgba(0,0,0,1)');
331
- assert.deepEqual(c.levels, [0, 0, 0, 255]);
332
- c = myp5.color('rgba(0,100,0, 0.5)');
333
- assert.deepEqual(c.levels, [0, 100, 0, 128]);
334
- c = myp5.color('rgba( 100,255 ,255, 0)');
335
- assert.deepEqual(c.levels, [100, 255, 255, 0]);
336
- c = myp5.color('rgba(0, 0,255, 0.1515236)');
337
- assert.deepEqual(c.levels, [0, 0, 255, 39]);
338
- c = myp5.color('rgba(100,101, 0, 0.75)');
339
- assert.deepEqual(c.levels, [100, 101, 0, 191]);
340
- c = myp5.color('rgba( 255, 255, 255, .9)');
341
- assert.deepEqual(c.levels, [255, 255, 255, 230]);
342
- c = myp5.color('rgba(0, 0, 0, 1)');
343
- assert.deepEqual(c.levels, [0, 0, 0, 255]);
344
- c = myp5.color('rgba(255,0, 10 , 0.33)');
345
- assert.deepEqual(c.levels, [255, 0, 10, 84]);
346
- });
347
-
348
- test('invalid RGBA values resolve to white', function() {
349
- c = myp5.color('rgba(100.5, 40, 3, 1.0)');
350
- assert.deepEqual(c.levels, [255, 255, 255, 255], 'decimal R% value');
351
- c = myp5.color('rgba(100, 40.00009, 3, 1.0)');
352
- assert.deepEqual(c.levels, [255, 255, 255, 255], 'decimal G% value');
353
- c = myp5.color('rgba(100, 40, 3.14159265, 1.0)');
354
- assert.deepEqual(c.levels, [255, 255, 255, 255], 'decimal B% value');
355
- c = myp5.color('rgba(.9, 40, 3, 1.0)');
356
- assert.deepEqual(
357
- c.levels,
358
- [255, 255, 255, 255],
359
- 'decimal R% without leading 0'
360
- );
361
- });
362
- });
363
-
364
- suite('p5.prototype.color("rgba(r%,g%,b%,a)")', function() {
365
- setup(function() {
366
- c = myp5.color('rgba(100.0%,0.0%,40%,0.8)');
367
- });
368
-
369
- test('should create instance of p5.Color', function() {
370
- assert.instanceOf(c, p5.Color);
371
- });
372
-
373
- test('should correctly set RGBA property', function() {
374
- assert.deepEqual(c.levels, [255, 0, 102, 204]);
375
- });
376
-
377
- test('spot check variant spacing', function() {
378
- // Exhaustive testing of spacing variations within RGBA format is
379
- // prohibitive: spot check a set of representative values
380
- c = myp5.color('rgba(100%,10.9%,100%,1)');
381
- assert.deepEqual(c.levels, [255, 28, 255, 255]);
382
- c = myp5.color('rgba(37%, 0%,0%,1)');
383
- assert.deepEqual(c.levels, [94, 0, 0, 255]);
384
- c = myp5.color('rgba(0%,50%,0%, 0.5)');
385
- assert.deepEqual(c.levels, [0, 128, 0, 128]);
386
- c = myp5.color('rgba( 50%,.9% ,100%, 0)');
387
- assert.deepEqual(c.levels, [128, 2, 255, 0]);
388
- c = myp5.color('rgba(10%, 50%,0%, 0.2515236)');
389
- assert.deepEqual(c.levels, [26, 128, 0, 64]);
390
- c = myp5.color('rgba(0%,50%, 0%, 0.75)');
391
- assert.deepEqual(c.levels, [0, 128, 0, 191]);
392
- c = myp5.color('rgba( 100%, 12%, 100%, .9)');
393
- assert.deepEqual(c.levels, [255, 31, 255, 230]);
394
- c = myp5.color('rgba(0%, 0%, 0%, 1)');
395
- assert.deepEqual(c.levels, [0, 0, 0, 255]);
396
- c = myp5.color('rgba(0%,87%, 10% , 0.3)');
397
- assert.deepEqual(c.levels, [0, 222, 26, 77]);
398
- });
399
-
400
- test('spot check decimal percentage values', function() {
401
- // Percentage values in CSS <color> identifiers are floats 0.0%-100.0%
402
- c = myp5.color('rgba(90.5%, 40%, 3%, 0.45)');
403
- assert.deepEqual(c.levels, [231, 102, 8, 115], 'Decimal A% value');
404
- c = myp5.color('rgba(90%, 40.00009%, 3%, 0.45)');
405
- assert.deepEqual(c.levels, [230, 102, 8, 115], 'Decimal G% value');
406
- c = myp5.color('rgba(90%, 40%, 3.14159265%, 0.45)');
407
- assert.deepEqual(c.levels, [230, 102, 8, 115], 'Decimal B% value');
408
- c = myp5.color('rgba(90%, 40%, .9%, 0.45)');
409
- assert.deepEqual(
410
- c.levels,
411
- [230, 102, 2, 115],
412
- 'Decimal B% without leading 0'
413
- );
414
- });
415
-
416
- test('invalid RGBA percentage values resolve to white', function() {
417
- c = myp5.color('rgb(50,100%,100%,1');
418
- assert.deepEqual(
419
- c.levels,
420
- [255, 255, 255, 255],
421
- 'mixed percentage and non-percentage input'
422
- );
423
- c = myp5.color('rgb(A%,B%,C%,0.5)');
424
- assert.deepEqual(
425
- c.levels,
426
- [255, 255, 255, 255],
427
- 'non-numeric percentages'
428
- );
429
- c = myp5.color('rgba(,50%,20%,1)');
430
- assert.deepEqual(c.levels, [255, 255, 255, 255], 'missing values');
431
- });
432
- });
433
-
434
- suite('p5.prototype.color("hsl(h, s%, l%)")', function() {
435
- setup(function() {
436
- c = myp5.color('hsl(336, 100%, 50%)');
437
- });
438
- test('should create instance of p5.Color', function() {
439
- assert.instanceOf(c, p5.Color);
440
- });
441
- test('should correctly set RGBA property', function() {
442
- assert.deepEqual(c.levels, [255, 0, 102, 255]);
443
- });
444
- });
445
-
446
- suite('p5.prototype.color("hsla(h, s%, l%, a)")', function() {
447
- setup(function() {
448
- c = myp5.color('hsla(336, 100%, 50%, 0.8)');
449
- });
450
- test('should create instance of p5.Color', function() {
451
- assert.instanceOf(c, p5.Color);
452
- });
453
- test('should correctly set RGBA property', function() {
454
- assert.deepEqual(c.levels, [255, 0, 102, 204]);
455
- });
456
- });
457
-
458
- suite('p5.prototype.color("hsb(h, s%, b%)")', function() {
459
- setup(function() {
460
- c = myp5.color('hsb(336, 100%, 100%)');
461
- });
462
- test('should create instance of p5.Color', function() {
463
- assert.instanceOf(c, p5.Color);
464
- });
465
- test('should correctly set RGBA property', function() {
466
- assert.deepEqual(c.levels, [255, 0, 102, 255]);
467
- });
468
- });
469
-
470
- suite('p5.prototype.color("hsba(h, s%, b%, a)")', function() {
471
- setup(function() {
472
- c = myp5.color('hsba(336, 100%, 100%, 0.8)');
473
- });
474
- test('should create instance of p5.Color', function() {
475
- assert.instanceOf(c, p5.Color);
476
- });
477
- test('should correctly set RGBA property', function() {
478
- assert.deepEqual(c.levels, [255, 0, 102, 204]);
479
- });
480
- });
481
-
482
- suite('p5.prototype.color("svgnamedcolor")', function() {
483
- setup(function() {
484
- c = myp5.color('papayawhip');
485
- });
486
-
487
- test('should create instance of p5.Color', function() {
488
- assert.instanceOf(c, p5.Color);
489
- });
490
-
491
- test('should correctly set RGBA property', function() {
492
- assert.deepEqual(c.levels, [255, 239, 213, 255]);
493
- });
494
-
495
- test('spot check color keywords', function() {
496
- c = myp5.color('red');
497
- assert.deepEqual(c.levels, [255, 0, 0, 255]);
498
- c = myp5.color('magenta');
499
- assert.deepEqual(c.levels, [255, 0, 255, 255]);
500
- c = myp5.color('limegreen');
501
- assert.deepEqual(c.levels, [50, 205, 50, 255]);
502
- });
503
- });
504
-
505
- suite('p5.prototype.color([])', function() {
506
- setup(function() {
507
- c = myp5.color([255, 0, 102]);
508
- });
509
- test('should create instance of p5.Color', function() {
510
- assert.instanceOf(c, p5.Color);
511
- });
512
- test('should correctly set RGBA property', function() {
513
- assert.deepEqual(c.levels, [255, 0, 102, 255]);
514
- });
515
- });
516
-
517
- suite('p5.prototype.color(r,g,b,a)', function() {
518
- setup(function() {
519
- c = myp5.color(255, 0, 102, 204);
520
- });
521
- test('should create instance of p5.Color', function() {
522
- assert.instanceOf(c, p5.Color);
523
- });
524
-
525
- test('should correctly set RGBA property', function() {
526
- assert.deepEqual(c.levels, [255, 0, 102, 204]);
527
- });
528
-
529
- test('should correctly get hue/saturation/brightness/lightness', function() {
530
- assert.approximately(c._getHue(), 336, 0.5);
531
- assert.approximately(c._getSaturation(), 100, 0.5);
532
- assert.approximately(c._getBrightness(), 100, 0.5);
533
- assert.approximately(c._getLightness(), 50, 0.5);
534
- });
535
-
536
- test('should correctly get RGBA values', function() {
537
- assert.approximately(c._getRed(), 255, 0.5);
538
- assert.approximately(c._getGreen(), 0, 0.5);
539
- assert.approximately(c._getBlue(), 102, 0.5);
540
- assert.approximately(c._getAlpha(), 204, 0.5);
541
- });
542
-
543
- test('should correctly render color string', function() {
544
- assert.equal(c.toString(), 'rgba(255,0,102,0.8)');
545
- });
546
- });
547
-
548
- // color level setters
549
- suite('in default mode', function() {
550
- test('can be modified with alpha setter', function() {
551
- var cc = myp5.color(255, 0, 102, 204);
552
- assert.deepEqual(cc.levels, [255, 0, 102, 204]);
553
- cc.setAlpha(98);
554
- assert.deepEqual(cc.levels, [255, 0, 102, 98]);
555
- });
556
- test('can be modified with rgb setters', function() {
557
- var cc = myp5.color(255, 0, 102, 204);
558
- assert.deepEqual(cc.levels, [255, 0, 102, 204]);
559
- cc.setRed(98);
560
- assert.deepEqual(cc.levels, [98, 0, 102, 204]);
561
- cc.setGreen(44);
562
- assert.deepEqual(cc.levels, [98, 44, 102, 204]);
563
- cc.setBlue(244);
564
- assert.deepEqual(cc.levels, [98, 44, 244, 204]);
565
- });
566
- });
567
-
568
- // Color Mode
569
- suite('p5.Color in RGB mode with custom range', function() {
570
- setup(function() {
571
- myp5.colorMode(myp5.RGB, 1);
572
- c = myp5.color(1, 0, 0.4, 0.8);
573
- });
574
-
575
- test('should correctly convert to RGBA', function() {
576
- assert.deepEqual(c.levels, [255, 0, 102, 204]);
577
- });
578
-
579
- test('should correctly get RGBA property', function() {
580
- assert.equal(c._getRed(), 1);
581
- assert.equal(c._getGreen(), 0);
582
- assert.equal(c._getBlue(), 0.4);
583
- assert.approximately(c._getAlpha(), 0.8, 0.05);
584
- });
585
-
586
- test('should correctly render color string', function() {
587
- assert.equal(c.toString(), 'rgba(255,0,102,0.8)');
588
- });
589
-
590
- test('should correctly get RGBA property after overwrite', function() {
591
- myp5.colorMode(myp5.RGB, 255, 255, 255, 255);
592
- assert.equal(c._getRed(), 255);
593
- assert.equal(c._getGreen(), 0);
594
- assert.equal(c._getBlue(), 102);
595
- assert.equal(c._getAlpha(), 204);
596
- });
597
- });
598
-
599
- suite('p5.Color in HSL mode', function() {
600
- setup(function() {
601
- myp5.colorMode(myp5.HSL);
602
- c = myp5.color(336, 100, 50);
603
- });
604
- test('should create instance of p5.Color', function() {
605
- assert.instanceOf(c, p5.Color);
606
- });
607
- test('should correctly set RGBA property', function() {
608
- assert.deepEqual(c.levels, [255, 0, 102, 255]);
609
- });
610
- test('can be modified with alpha setter', function() {
611
- var cc = myp5.color(336, 100, 50);
612
- cc.setAlpha(0.73);
613
- assert.deepEqual(cc.levels, [255, 0, 102, 186]);
614
- });
615
- test('can be modified with rgb setters', function() {
616
- var cc = myp5.color(336, 100, 50);
617
- assert.deepEqual(cc.levels, [255, 0, 102, 255]);
618
- cc.setRed(98);
619
- assert.deepEqual(cc.levels, [98, 0, 102, 255]);
620
- cc.setGreen(44);
621
- assert.deepEqual(cc.levels, [98, 44, 102, 255]);
622
- cc.setBlue(244);
623
- assert.deepEqual(cc.levels, [98, 44, 244, 255]);
624
- });
625
- });
626
-
627
- suite('p5.Color in HSL mode with Alpha', function() {
628
- setup(function() {
629
- myp5.colorMode(myp5.HSL);
630
- c = myp5.color(336, 100, 50, 0.8);
631
- });
632
- test('should create instance of p5.Color', function() {
633
- assert.instanceOf(c, p5.Color);
634
- });
635
- test('should correctly set RGBA property', function() {
636
- assert.deepEqual(c.levels, [255, 0, 102, 204]);
637
- });
638
-
639
- test('should correctly get hue/saturation/lightness/alpha', function() {
640
- assert.approximately(c._getHue(), 336, 0.5);
641
- assert.approximately(c._getSaturation(), 100, 0.5);
642
- assert.approximately(c._getLightness(), 50, 0.5);
643
- assert.approximately(c._getAlpha(), 0.8, 0.05);
644
- });
645
- });
646
-
647
- suite('p5.Color in HSL mode with custom range', function() {
648
- setup(function() {
649
- myp5.colorMode(myp5.HSL, 100, 200, 300, 10);
650
- c = myp5.color(93.33, 200, 150, 8);
651
- });
652
-
653
- test('should correctly get HSLA property', function() {
654
- assert.approximately(c._getHue(), 93, 0.5);
655
- assert.approximately(c._getSaturation(), 200, 0.5);
656
- assert.approximately(c._getLightness(), 150, 0.5);
657
- assert.approximately(c._getAlpha(), 8, 0.5);
658
- });
659
-
660
- test('should correctly convert to RGBA', function() {
661
- assert.deepEqual(c.levels, [255, 0, 102, 204]);
662
- });
663
-
664
- test('should correctly render color string', function() {
665
- assert.equal(c.toString(), 'rgba(255,0,102,0.8)');
666
- });
667
-
668
- test('can be modified with alpha setter', function() {
669
- var cc = myp5.color(93.33, 200, 150, 8);
670
- cc.setAlpha(7.3);
671
- assert.deepEqual(cc.levels, [255, 0, 102, 186]);
672
- });
673
- test('can be modified with rgb setters', function() {
674
- var cc = myp5.color(93.33, 200, 150, 8);
675
- assert.deepEqual(cc.levels, [255, 0, 102, 204]);
676
- cc.setRed(98);
677
- assert.deepEqual(cc.levels, [98, 0, 102, 204]);
678
- cc.setGreen(44);
679
- assert.deepEqual(cc.levels, [98, 44, 102, 204]);
680
- cc.setBlue(244);
681
- assert.deepEqual(cc.levels, [98, 44, 244, 204]);
682
- });
683
- });
684
-
685
- suite('p5.Color in HSL mode with RGB string', function() {
686
- setup(function() {
687
- myp5.colorMode(myp5.HSL, 360, 100, 100, 1);
688
- c = myp5.color('rgba(255, 0, 102, 0.8)');
689
- });
690
-
691
- test('should correctly get HSLA property', function() {
692
- assert.approximately(c._getHue(), 336, 0.5);
693
- assert.approximately(c._getSaturation(), 100, 0.5);
694
- assert.approximately(c._getLightness(), 50, 0.5);
695
- assert.approximately(c._getAlpha(), 0.8, 0.05);
696
- });
697
-
698
- test('should correctly convert to RGBA', function() {
699
- assert.deepEqual(c.levels, [255, 0, 102, 204]);
700
- });
701
-
702
- test('should correctly render color string', function() {
703
- assert.equal(c.toString(), 'rgba(255,0,102,0.8)');
704
- });
705
- });
706
-
707
- suite('p5.Color in HSL mode with HSL string', function() {
708
- setup(function() {
709
- myp5.colorMode(myp5.HSL, 360, 100, 100, 1);
710
- c = myp5.color('hsla(336, 100%, 50%, 0.8)');
711
- });
712
-
713
- test('should correctly get HSLA property', function() {
714
- assert.approximately(c._getHue(), 336, 0.5);
715
- assert.approximately(c._getSaturation(), 100, 0.5);
716
- assert.approximately(c._getLightness(), 50, 0.5);
717
- assert.approximately(c._getAlpha(), 0.8, 0.05);
718
- });
719
-
720
- test('should correctly convert to RGBA', function() {
721
- assert.deepEqual(c.levels, [255, 0, 102, 204]);
722
- });
723
-
724
- test('should correctly render color string', function() {
725
- assert.equal(c.toString(), 'rgba(255,0,102,0.8)');
726
- });
727
- });
728
-
729
- suite('p5.Color in HSL mode with HSB string', function() {
730
- setup(function() {
731
- myp5.colorMode(myp5.HSL, 360, 100, 100, 1);
732
- c = myp5.color('hsba(336, 100%, 100%, 0.8)');
733
- });
734
-
735
- test('should correctly get HSLA property', function() {
736
- assert.approximately(c._getHue(), 336, 0.5);
737
- assert.approximately(c._getSaturation(), 100, 0.5);
738
- assert.approximately(c._getLightness(), 50, 0.5);
739
- assert.approximately(c._getAlpha(), 0.8, 0.05);
740
- });
741
-
742
- test('should correctly convert to RGBA', function() {
743
- assert.deepEqual(c.levels, [255, 0, 102, 204]);
744
- });
745
-
746
- test('should correctly render color string', function() {
747
- assert.equal(c.toString(), 'rgba(255,0,102,0.8)');
748
- });
749
- });
750
-
751
- suite('p5.Color in HSB mode', function() {
752
- setup(function() {
753
- myp5.colorMode(myp5.HSB);
754
- c = myp5.color(336, 100, 100);
755
- });
756
- test('should create instance of p5.Color', function() {
757
- assert.instanceOf(c, p5.Color);
758
- });
759
- test('should correctly set RGBA property', function() {
760
- assert.deepEqual(c.levels, [255, 0, 102, 255]);
761
- });
762
- test('can be modified with alpha setter', function() {
763
- var cc = myp5.color(336, 100, 100);
764
- cc.setAlpha(0.73);
765
- assert.deepEqual(cc.levels, [255, 0, 102, 186]);
766
- });
767
- test('can be modified with rgb setters', function() {
768
- var cc = myp5.color(336, 100, 100);
769
- assert.deepEqual(cc.levels, [255, 0, 102, 255]);
770
- cc.setRed(98);
771
- assert.deepEqual(cc.levels, [98, 0, 102, 255]);
772
- cc.setGreen(44);
773
- assert.deepEqual(cc.levels, [98, 44, 102, 255]);
774
- cc.setBlue(244);
775
- assert.deepEqual(cc.levels, [98, 44, 244, 255]);
776
- });
777
- });
778
-
779
- suite('p5.Color in HSB mode with Alpha', function() {
780
- setup(function() {
781
- myp5.colorMode(myp5.HSB);
782
- c = myp5.color(336, 100, 100, 0.8);
783
- });
784
- test('should create instance of p5.Color', function() {
785
- assert.instanceOf(c, p5.Color);
786
- });
787
- test('should correctly set RGBA property', function() {
788
- assert.deepEqual(c.levels, [255, 0, 102, 204]);
789
- });
790
-
791
- test('should correctly get hue/saturation/brightness/alpha', function() {
792
- assert.approximately(c._getHue(), 336, 0.5);
793
- assert.approximately(c._getSaturation(), 100, 0.5);
794
- assert.approximately(c._getBrightness(), 100, 0.5);
795
- assert.approximately(c._getAlpha(), 0.8, 0.05);
796
- });
797
- });
798
-
799
- suite('p5.Color in HSB mode with custom range', function() {
800
- setup(function() {
801
- myp5.colorMode(myp5.HSB, 100, 200, 300, 10);
802
- c = myp5.color(93.33, 200, 300, 8);
803
- });
804
-
805
- test('should correctly get HSBA property', function() {
806
- assert.approximately(c._getHue(), 93, 0.5);
807
- assert.approximately(c._getSaturation(), 200, 0.5);
808
- assert.approximately(c._getBrightness(), 300, 0.5);
809
- assert.approximately(c._getAlpha(), 8, 0.5);
810
- });
811
-
812
- test('should correctly convert to RGBA', function() {
813
- assert.deepEqual(c.levels, [255, 0, 102, 204]);
814
- });
815
-
816
- test('should correctly render color string', function() {
817
- assert.equal(c.toString(), 'rgba(255,0,102,0.8)');
818
- });
819
- });
820
-
821
- suite('p5.Color in HSB mode with RGB string', function() {
822
- setup(function() {
823
- myp5.colorMode(myp5.HSB, 360, 100, 100, 1);
824
- c = myp5.color('rgba(255, 0, 102, 0.8)');
825
- });
826
-
827
- test('should correctly get HSBA property', function() {
828
- assert.approximately(c._getHue(), 336, 0.5);
829
- assert.approximately(c._getSaturation(), 100, 0.5);
830
- assert.approximately(c._getBrightness(), 100, 0.5);
831
- assert.approximately(c._getAlpha(), 0.8, 0.05);
832
- });
833
-
834
- test('should correctly convert to RGBA', function() {
835
- assert.deepEqual(c.levels, [255, 0, 102, 204]);
836
- });
837
-
838
- test('should correctly render color string', function() {
839
- assert.equal(c.toString(), 'rgba(255,0,102,0.8)');
840
- });
841
- });
842
-
843
- suite('p5.Color in HSB mode with HSB string', function() {
844
- setup(function() {
845
- myp5.colorMode(myp5.HSB, 360, 100, 100, 1);
846
- c = myp5.color('hsba(336, 100%, 100%, 0.8)');
847
- });
848
-
849
- test('should correctly get HSBA property', function() {
850
- assert.approximately(c._getHue(), 336, 0.5);
851
- assert.approximately(c._getSaturation(), 100, 0.5);
852
- assert.approximately(c._getBrightness(), 100, 0.5);
853
- assert.approximately(c._getAlpha(), 0.8, 0.05);
854
- });
855
-
856
- test('should correctly convert to RGBA', function() {
857
- assert.deepEqual(c.levels, [255, 0, 102, 204]);
858
- });
859
-
860
- test('should correctly render color string', function() {
861
- assert.equal(c.toString(), 'rgba(255,0,102,0.8)');
862
- });
863
- });
864
-
865
- suite('p5.Color in HSB mode with HSL string', function() {
866
- setup(function() {
867
- myp5.colorMode(myp5.HSB, 360, 100, 100, 1);
868
- c = myp5.color('hsla(336, 100%, 50%, 0.8)');
869
- });
870
-
871
- test('should correctly get HSBA property', function() {
872
- assert.approximately(c._getHue(), 336, 0.5);
873
- assert.approximately(c._getSaturation(), 100, 0.5);
874
- assert.approximately(c._getBrightness(), 100, 0.5);
875
- assert.approximately(c._getAlpha(), 0.8, 0.05);
876
- });
877
-
878
- test('should correctly convert to RGBA', function() {
879
- assert.deepEqual(c.levels, [255, 0, 102, 204]);
880
- });
881
-
882
- test('should correctly render color string', function() {
883
- assert.equal(c.toString(), 'rgba(255,0,102,0.8)');
884
- });
885
- });
886
-
887
- suite('p5.Color in RGB mode with grayscale value', function() {
888
- setup(function() {
889
- myp5.colorMode(myp5.RGB);
890
- c = myp5.color(100);
891
- });
892
-
893
- test('should create instance of p5.Color', function() {
894
- assert.instanceOf(c, p5.Color);
895
- });
896
-
897
- test('should correctly set RGB levels', function() {
898
- assert.deepEqual(c.levels, [100, 100, 100, 255]);
899
- });
900
- });
901
-
902
- suite('p5.Color in RGB mode with grayscale value and alpha', function() {
903
- setup(function() {
904
- myp5.colorMode(myp5.RGB);
905
- c = myp5.color(100, 70);
906
- });
907
-
908
- test('should create instance of p5.Color', function() {
909
- assert.instanceOf(c, p5.Color);
910
- });
911
-
912
- test('should correctly set RGB levels', function() {
913
- assert.deepEqual(c.levels, [100, 100, 100, 70]);
914
- });
915
- });
916
-
917
- suite('p5.Color in HSB mode with grayscale value', function() {
918
- setup(function() {
919
- myp5.colorMode(myp5.HSB);
920
- c = myp5.color(39.3);
921
- });
922
-
923
- test('should create instance of p5.Color', function() {
924
- assert.instanceOf(c, p5.Color);
925
- });
926
-
927
- test('should correctly set RGB levels', function() {
928
- assert.deepEqual(c.levels, [100, 100, 100, 255]);
929
- });
930
- });
931
-
932
- suite('p5.Color in HSB mode with grayscale value and alpha', function() {
933
- setup(function() {
934
- myp5.colorMode(myp5.HSB);
935
- c = myp5.color(39.3, 0.275);
936
- });
937
-
938
- test('should create instance of p5.Color', function() {
939
- assert.instanceOf(c, p5.Color);
940
- });
941
-
942
- test('should correctly set RGB levels', function() {
943
- assert.deepEqual(c.levels, [100, 100, 100, 70]);
944
- });
945
- });
946
-
947
- suite('p5.Color in HSL mode with grayscale value', function() {
948
- setup(function() {
949
- myp5.colorMode(myp5.HSL);
950
- c = myp5.color(39.3);
951
- });
952
-
953
- test('should create instance of p5.Color', function() {
954
- assert.instanceOf(c, p5.Color);
955
- });
956
-
957
- test('should correctly set RGB levels', function() {
958
- assert.deepEqual(c.levels, [100, 100, 100, 255]);
959
- });
960
- });
961
-
962
- suite('p5.Color in HSL mode with grayscale value and alpha', function() {
963
- setup(function() {
964
- myp5.colorMode(myp5.HSL);
965
- c = myp5.color(39.3, 0.275);
966
- });
967
-
968
- test('should create instance of p5.Color', function() {
969
- assert.instanceOf(c, p5.Color);
970
- });
971
-
972
- test('should correctly set RGB levels', function() {
973
- assert.deepEqual(c.levels, [100, 100, 100, 70]);
974
- });
975
- });
976
-
977
- suite('p5.Color.prototype.toString', function() {
978
- var colorStr;
979
-
980
- setup(function() {
981
- myp5.colorMode(myp5.RGB, 255, 255, 255, 255);
982
- c = myp5.color(128, 0, 128, 128);
983
- colorStr = c.toString();
984
- });
985
-
986
- test('should generate (r,g,b,a) color string with 0-1 normalized alpha', function() {
987
- // Will not exactly equal 0.5 due to math: test "0.5" substr of
988
- // 'rgba(128,0,128,0.5...' instead of checking the entire string
989
- assert.equal(colorStr.slice(15, 18), '0.5');
990
- });
991
-
992
- test('should consistently generate the same output', function() {
993
- assert.equal(colorStr, '' + c);
994
- });
995
-
996
- test('should not mutate color levels', function() {
997
- assert.deepEqual(c.levels, [128, 0, 128, 128]);
998
- });
999
- });
1000
- });