q5 2.9.22 → 2.9.23

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/.vscode/launch.json +26 -0
  2. package/bun.lockb +0 -0
  3. package/p5-tests/js/chai_helpers.js +20 -0
  4. package/p5-tests/js/mocha_setup.js +2 -0
  5. package/p5-tests/js/modernizr.js +5 -0
  6. package/p5-tests/js/p5_helpers.js +135 -0
  7. package/p5-tests/js/sinon.js +5949 -0
  8. package/p5-tests/mocha.css +289 -0
  9. package/p5-tests/test.html +71 -0
  10. package/p5-tests/unit/color/color_conversion.js +68 -0
  11. package/p5-tests/unit/color/creating_reading.js +217 -0
  12. package/p5-tests/unit/color/p5.Color.js +1000 -0
  13. package/p5-tests/unit/color/setting.js +289 -0
  14. package/p5-tests/unit/core/2d_primitives.js +490 -0
  15. package/p5-tests/unit/core/attributes.js +115 -0
  16. package/p5-tests/unit/core/curves.js +139 -0
  17. package/p5-tests/unit/core/environment.js +248 -0
  18. package/p5-tests/unit/core/error_helpers.js +1158 -0
  19. package/p5-tests/unit/core/main.js +340 -0
  20. package/p5-tests/unit/core/p5.Element.js +773 -0
  21. package/p5-tests/unit/core/p5.Graphics.js +179 -0
  22. package/p5-tests/unit/core/preload.js +285 -0
  23. package/p5-tests/unit/core/rendering.js +116 -0
  24. package/p5-tests/unit/core/structure.js +293 -0
  25. package/p5-tests/unit/core/transform.js +144 -0
  26. package/p5-tests/unit/core/version.js +28 -0
  27. package/p5-tests/unit/core/vertex.js +137 -0
  28. package/p5-tests/unit/dom/dom.js +2146 -0
  29. package/p5-tests/unit/events/acceleration.js +213 -0
  30. package/p5-tests/unit/events/keyboard.js +179 -0
  31. package/p5-tests/unit/events/mouse.js +487 -0
  32. package/p5-tests/unit/events/touch.js +180 -0
  33. package/p5-tests/unit/image/downloading.js +379 -0
  34. package/p5-tests/unit/image/filters.js +92 -0
  35. package/p5-tests/unit/image/loading.js +413 -0
  36. package/p5-tests/unit/image/p5.Image.js +201 -0
  37. package/p5-tests/unit/image/pixels.js +234 -0
  38. package/p5-tests/unit/io/files.js +378 -0
  39. package/p5-tests/unit/io/loadBytes.js +149 -0
  40. package/p5-tests/unit/io/loadImage.js +123 -0
  41. package/p5-tests/unit/io/loadJSON.js +185 -0
  42. package/p5-tests/unit/io/loadModel.js +215 -0
  43. package/p5-tests/unit/io/loadShader.js +176 -0
  44. package/p5-tests/unit/io/loadStrings.js +140 -0
  45. package/p5-tests/unit/io/loadTable.js +183 -0
  46. package/p5-tests/unit/io/loadXML.js +127 -0
  47. package/p5-tests/unit/io/saveModel.js +113 -0
  48. package/p5-tests/unit/io/saveTable.js +142 -0
  49. package/p5-tests/unit/math/calculation.js +452 -0
  50. package/p5-tests/unit/math/noise.js +66 -0
  51. package/p5-tests/unit/math/p5.Vector.js +1886 -0
  52. package/p5-tests/unit/math/random.js +177 -0
  53. package/p5-tests/unit/math/trigonometry.js +144 -0
  54. package/p5-tests/unit/spec.js +50 -0
  55. package/p5-tests/unit/typography/attributes.js +120 -0
  56. package/p5-tests/unit/typography/loadFont.js +162 -0
  57. package/p5-tests/unit/typography/p5.Font.js +63 -0
  58. package/p5-tests/unit/utilities/conversion.js +329 -0
  59. package/p5-tests/unit/utilities/time_date.js +133 -0
  60. package/package.json +1 -1
  61. package/q5.js +48 -37
  62. package/q5.min.js +1 -1
  63. package/src/q5-2d-image.js +3 -1
  64. package/src/q5-core.js +3 -1
  65. package/src/q5-math.js +1 -0
  66. package/src/q5-webgpu-canvas.js +8 -7
  67. package/src/q5-webgpu-drawing.js +15 -12
  68. package/src/q5-webgpu-image.js +1 -1
  69. package/src/q5-webgpu-text.js +17 -15
@@ -0,0 +1,289 @@
1
+ suite('color/Setting', function() {
2
+ let myp5; // sketch without WEBGL Mode
3
+ let my3D; // sketch with WEBGL mode
4
+ setup(function(done) {
5
+ new p5(function(p) {
6
+ p.setup = function() {
7
+ myp5 = p;
8
+ };
9
+ });
10
+ new p5(function(p) {
11
+ p.setup = function() {
12
+ p.createCanvas(100, 100, p.WEBGL);
13
+ my3D = p;
14
+ };
15
+ });
16
+ done();
17
+ });
18
+
19
+ teardown(function() {
20
+ myp5.remove();
21
+ my3D.remove();
22
+ });
23
+
24
+ suite('p5.prototype.erase', function() {
25
+ test('should be a function', function() {
26
+ assert.ok(myp5.erase);
27
+ });
28
+
29
+ test('should set renderer to erasing state', function() {
30
+ myp5.erase();
31
+ assert.isTrue(myp5._renderer._isErasing);
32
+ });
33
+
34
+ test('should cache renderer fill', function() {
35
+ myp5.fill(255, 0, 0);
36
+ const fillStyle = myp5.drawingContext.fillStyle;
37
+ myp5.erase();
38
+ assert.deepEqual(myp5._renderer._cachedFillStyle, fillStyle);
39
+ });
40
+
41
+ test('should cache renderer stroke', function() {
42
+ myp5.stroke(255, 0, 0);
43
+ const strokeStyle = myp5.drawingContext.strokeStyle;
44
+ myp5.erase();
45
+ assert.deepEqual(myp5._renderer._cachedStrokeStyle, strokeStyle);
46
+ });
47
+
48
+ test('should cache renderer blend', function() {
49
+ myp5.blendMode(myp5.SCREEN);
50
+ myp5.erase();
51
+ assert.deepEqual(myp5._renderer._cachedBlendMode, myp5.SCREEN);
52
+ });
53
+
54
+ test('should set fill strength', function() {
55
+ myp5.erase(125);
56
+ assert.equal(
57
+ myp5.color(myp5.drawingContext.fillStyle).array,
58
+ myp5.color(255, 125).array
59
+ );
60
+ });
61
+
62
+ test('should set stroke strength', function() {
63
+ myp5.erase(255, 50);
64
+ assert.equal(
65
+ myp5.color(myp5.drawingContext.strokeStyle).array,
66
+ myp5.color(255, 50).array
67
+ );
68
+ });
69
+ });
70
+
71
+ suite('p5.RendererGL.prototype.erase', function() {
72
+ test('should set renderer to erasing state', function() {
73
+ my3D.erase();
74
+ assert.isTrue(my3D._renderer._isErasing);
75
+ });
76
+
77
+ test('should cache renderer fill', function() {
78
+ my3D.fill(255, 0, 0);
79
+ const curFillColor = my3D._renderer.curFillColor;
80
+ my3D.erase();
81
+ assert.deepEqual(my3D._renderer._cachedFillStyle, curFillColor);
82
+ });
83
+
84
+ test('should cache renderer stroke', function() {
85
+ my3D.stroke(255, 0, 0);
86
+ const strokeStyle = my3D._renderer.curStrokeColor;
87
+ my3D.erase();
88
+ assert.deepEqual(my3D._renderer._cachedStrokeStyle, strokeStyle);
89
+ });
90
+
91
+ test('should cache renderer blend', function() {
92
+ my3D.blendMode(my3D.SCREEN);
93
+ my3D.erase();
94
+ assert.deepEqual(my3D._renderer.preEraseBlend, my3D.SCREEN);
95
+ });
96
+
97
+ test('should set fill strength', function() {
98
+ my3D.erase(125);
99
+ assert.deepEqual(my3D._renderer.curFillColor, [1, 1, 1, 125 / 255]);
100
+ });
101
+
102
+ test('should set stroke strength', function() {
103
+ my3D.erase(255, 50);
104
+ assert.deepEqual(my3D._renderer.curStrokeColor, [1, 1, 1, 50 / 255]);
105
+ });
106
+
107
+ test('should set default values when no arguments', function() {
108
+ my3D.erase();
109
+ assert.deepEqual(my3D._renderer.curFillColor, [1, 1, 1, 1]);
110
+ assert.deepEqual(my3D._renderer.curStrokeColor, [1, 1, 1, 1]);
111
+ });
112
+ });
113
+
114
+ suite('p5.prototype.noErase', function() {
115
+ test('should be a function', function() {
116
+ assert.ok(myp5.noErase);
117
+ });
118
+
119
+ test('should turn off renderer erasing state', function() {
120
+ myp5.erase();
121
+ myp5.noErase();
122
+ assert.isFalse(myp5._renderer._isErasing);
123
+ });
124
+
125
+ test('should restore cached renderer fill', function() {
126
+ myp5.fill(255, 0, 0);
127
+ const fillStyle = myp5.drawingContext.fillStyle;
128
+ myp5.erase();
129
+ myp5.noErase();
130
+ assert.deepEqual(myp5.drawingContext.fillStyle, fillStyle);
131
+ });
132
+
133
+ test('should restore cached renderer stroke', function() {
134
+ myp5.stroke(255, 0, 0);
135
+ const strokeStyle = myp5.drawingContext.strokeStyle;
136
+ myp5.erase();
137
+ myp5.noErase();
138
+ assert.deepEqual(myp5.drawingContext.strokeStyle, strokeStyle);
139
+ });
140
+ });
141
+
142
+ suite('p5.RendererGL.prototype.noErase', function() {
143
+ test('should turn off renderer erasing state', function() {
144
+ my3D.erase();
145
+ my3D.noErase();
146
+ assert.isFalse(my3D._renderer._isErasing);
147
+ });
148
+
149
+ test('should restore cached renderer fill', function() {
150
+ my3D.fill(255, 0, 0);
151
+ const fillStyle = my3D._renderer.curFillColor.slice();
152
+ my3D.erase();
153
+ my3D.noErase();
154
+ assert.deepEqual([1, 0, 0, 1], fillStyle);
155
+ });
156
+
157
+ test('should restore cached renderer stroke', function() {
158
+ my3D.stroke(255, 0, 0);
159
+ const strokeStyle = my3D._renderer.curStrokeColor.slice();
160
+ my3D.erase();
161
+ my3D.noErase();
162
+ assert.deepEqual([1, 0, 0, 1], strokeStyle);
163
+ });
164
+ });
165
+
166
+ suite('p5.prototype.colorMode', function() {
167
+ test('should be a function', function() {
168
+ assert.ok(myp5.colorMode);
169
+ });
170
+
171
+ test('should set mode to RGB', function() {
172
+ myp5.colorMode(myp5.RGB);
173
+ assert.equal(myp5._colorMode, myp5.RGB);
174
+ });
175
+
176
+ test('should correctly set color RGB maxes', function() {
177
+ assert.deepEqual(myp5._colorMaxes[myp5.RGB], [255, 255, 255, 255]);
178
+ myp5.colorMode(myp5.RGB, 1, 1, 1);
179
+ assert.deepEqual(myp5._colorMaxes[myp5.RGB], [1, 1, 1, 255]);
180
+ myp5.colorMode(myp5.RGB, 1);
181
+ assert.deepEqual(myp5._colorMaxes[myp5.RGB], [1, 1, 1, 1]);
182
+ myp5.colorMode(myp5.RGB, 255, 255, 255, 1);
183
+ assert.deepEqual(myp5._colorMaxes[myp5.RGB], [255, 255, 255, 1]);
184
+ myp5.colorMode(myp5.RGB, 255);
185
+ });
186
+
187
+ test('should set mode to HSL', function() {
188
+ myp5.colorMode(myp5.HSL);
189
+ assert.equal(myp5._colorMode, myp5.HSL);
190
+ });
191
+
192
+ test('should correctly set color HSL maxes', function() {
193
+ assert.deepEqual(myp5._colorMaxes[myp5.HSL], [360, 100, 100, 1]);
194
+ myp5.colorMode(myp5.HSL, 255, 255, 255);
195
+ assert.deepEqual(myp5._colorMaxes[myp5.HSL], [255, 255, 255, 1]);
196
+ myp5.colorMode(myp5.HSL, 360);
197
+ assert.deepEqual(myp5._colorMaxes[myp5.HSL], [360, 360, 360, 360]);
198
+ myp5.colorMode(myp5.HSL, 360, 100, 100, 1);
199
+ assert.deepEqual(myp5._colorMaxes[myp5.HSL], [360, 100, 100, 1]);
200
+ });
201
+
202
+ test('should set mode to HSB', function() {
203
+ myp5.colorMode(myp5.HSB);
204
+ assert.equal(myp5._colorMode, myp5.HSB);
205
+ });
206
+
207
+ test('should correctly set color HSB maxes', function() {
208
+ assert.deepEqual(myp5._colorMaxes[myp5.HSB], [360, 100, 100, 1]);
209
+ myp5.colorMode(myp5.HSB, 255, 255, 255);
210
+ assert.deepEqual(myp5._colorMaxes[myp5.HSB], [255, 255, 255, 1]);
211
+ myp5.colorMode(myp5.HSB, 360);
212
+ assert.deepEqual(myp5._colorMaxes[myp5.HSB], [360, 360, 360, 360]);
213
+ myp5.colorMode(myp5.HSB, 360, 100, 100, 1);
214
+ assert.deepEqual(myp5._colorMaxes[myp5.HSB], [360, 100, 100, 1]);
215
+ });
216
+ });
217
+
218
+ suite('p5.Color components', function() {
219
+ test('setRed() correctly sets red component', function() {
220
+ myp5.colorMode(myp5.RGB, 255);
221
+ const c = myp5.color(0, 162, 205, 255);
222
+ c.setRed(100);
223
+ assert.equal(myp5.red(c), 100);
224
+ assert.equal(myp5.green(c), 162);
225
+ assert.equal(myp5.blue(c), 205);
226
+ assert.equal(myp5.alpha(c), 255);
227
+ });
228
+
229
+ test('setGreen() correctly sets green component', function() {
230
+ myp5.colorMode(myp5.RGB, 255);
231
+ const c = myp5.color(0, 162, 205, 255);
232
+ c.setGreen(100);
233
+ assert.equal(myp5.red(c), 0);
234
+ assert.equal(myp5.green(c), 100);
235
+ assert.equal(myp5.blue(c), 205);
236
+ assert.equal(myp5.alpha(c), 255);
237
+ });
238
+
239
+ test('setBlue() correctly sets blue component', function() {
240
+ myp5.colorMode(myp5.RGB, 255);
241
+ const c = myp5.color(0, 162, 205, 255);
242
+ c.setBlue(100);
243
+ assert.equal(myp5.red(c), 0);
244
+ assert.equal(myp5.green(c), 162);
245
+ assert.equal(myp5.blue(c), 100);
246
+ assert.equal(myp5.alpha(c), 255);
247
+ });
248
+
249
+ test('setAlpha correctly sets alpha component', function() {
250
+ myp5.colorMode(myp5.RGB, 255);
251
+ const c = myp5.color(0, 162, 205, 255);
252
+ c.setAlpha(100);
253
+ assert.equal(myp5.red(c), 0);
254
+ assert.equal(myp5.green(c), 162);
255
+ assert.equal(myp5.blue(c), 205);
256
+ assert.equal(myp5.alpha(c), 100);
257
+ });
258
+
259
+ test('changing the red/green/blue/alpha components should clear the cached HSL/HSB values', function() {
260
+ myp5.colorMode(myp5.RGB, 255);
261
+ const c = myp5.color(0, 162, 205, 255);
262
+
263
+ // create HSL/HSB values
264
+ myp5.lightness(c);
265
+ myp5.brightness(c);
266
+ c.setRed(100);
267
+ assert(!c.hsba);
268
+ assert(!c.hsla);
269
+
270
+ myp5.lightness(c);
271
+ myp5.brightness(c);
272
+ c.setGreen(100);
273
+ assert(!c.hsba);
274
+ assert(!c.hsla);
275
+
276
+ myp5.lightness(c);
277
+ myp5.brightness(c);
278
+ c.setBlue(100);
279
+ assert(!c.hsba);
280
+ assert(!c.hsla);
281
+
282
+ myp5.lightness(c);
283
+ myp5.brightness(c);
284
+ c.setAlpha(100);
285
+ assert(!c.hsba);
286
+ assert(!c.hsla);
287
+ });
288
+ });
289
+ });