q5 2.9.21 → 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 (77) 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 +158 -54
  62. package/q5.min.js +1 -1
  63. package/src/q5-2d-canvas.js +8 -2
  64. package/src/q5-2d-drawing.js +20 -7
  65. package/src/q5-2d-image.js +4 -1
  66. package/src/q5-2d-text.js +7 -0
  67. package/src/q5-canvas.js +6 -5
  68. package/src/q5-color.js +5 -0
  69. package/src/q5-core.js +3 -1
  70. package/src/q5-input.js +12 -0
  71. package/src/q5-math.js +11 -3
  72. package/src/q5-record.js +2 -0
  73. package/src/q5-vector.js +33 -0
  74. package/src/q5-webgpu-canvas.js +11 -7
  75. package/src/q5-webgpu-drawing.js +15 -12
  76. package/src/q5-webgpu-image.js +1 -1
  77. package/src/q5-webgpu-text.js +22 -15
@@ -0,0 +1,293 @@
1
+ suite('Structure', 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.loop and p5.prototype.noLoop', function() {
18
+ test('noLoop should stop', function() {
19
+ return new Promise(function(resolve, reject) {
20
+ var c0 = myp5.frameCount;
21
+ myp5.noLoop();
22
+ myp5.draw = function() {
23
+ var c1 = myp5.frameCount;
24
+ // Allow one final draw to run
25
+ if (c1 > c0 + 1) {
26
+ reject('Entered draw');
27
+ }
28
+ };
29
+ setTimeout(resolve, 100);
30
+ });
31
+ });
32
+
33
+ test('loop should restart', function() {
34
+ return new Promise(function(resolve, reject) {
35
+ var c0 = myp5.frameCount;
36
+ myp5.noLoop();
37
+ myp5.draw = function() {
38
+ var c1 = myp5.frameCount;
39
+ // Allow one final draw to run
40
+ if (c1 > c0 + 1) {
41
+ reject('Entered draw');
42
+ }
43
+ };
44
+ setTimeout(resolve, 100);
45
+ }).then(function() {
46
+ return new Promise(function(resolve, reject) {
47
+ myp5.draw = resolve;
48
+ myp5.loop();
49
+ setTimeout(function() {
50
+ reject('Failed to restart draw.');
51
+ }, 100);
52
+ });
53
+ });
54
+ });
55
+ });
56
+
57
+ suite('p5.prototype.push and p5.prototype.pop', function() {
58
+ function getRenderState() {
59
+ var state = {};
60
+ for (var key in myp5._renderer) {
61
+ var value = myp5._renderer[key];
62
+ if (
63
+ typeof value !== 'function' &&
64
+ key !== '_cachedFillStyle' &&
65
+ key !== '_cachedStrokeStyle'
66
+ ) {
67
+ state[key] = value;
68
+ }
69
+ }
70
+ return state;
71
+ }
72
+
73
+ function assertCanPreserveRenderState(work) {
74
+ var originalState = getRenderState();
75
+ myp5.push();
76
+ work();
77
+ myp5.pop();
78
+ assert.deepEqual(getRenderState(), originalState);
79
+ }
80
+
81
+ test('leak no state after fill()', function() {
82
+ myp5.noFill();
83
+ assertCanPreserveRenderState(function() {
84
+ myp5.fill('red');
85
+ });
86
+ });
87
+
88
+ test('leak no state after noFill()', function() {
89
+ myp5.fill('red');
90
+ assertCanPreserveRenderState(function() {
91
+ myp5.noFill();
92
+ });
93
+ });
94
+
95
+ test('leak no state after stroke()', function() {
96
+ myp5.noStroke();
97
+ assertCanPreserveRenderState(function() {
98
+ myp5.stroke('red');
99
+ });
100
+ });
101
+
102
+ test('leak no state after noStroke()', function() {
103
+ myp5.stroke('red');
104
+ assertCanPreserveRenderState(function() {
105
+ myp5.noStroke();
106
+ });
107
+ });
108
+
109
+ test('leak no state after tint()', function() {
110
+ myp5.noTint();
111
+ assertCanPreserveRenderState(function() {
112
+ myp5.tint(255, 0, 0);
113
+ });
114
+ });
115
+
116
+ test('leak no state after noTint()', function() {
117
+ myp5.tint(255, 0, 0);
118
+ assertCanPreserveRenderState(function() {
119
+ myp5.noTint();
120
+ });
121
+ });
122
+
123
+ test('leak no state after strokeWeight()', function() {
124
+ myp5.strokeWeight(1);
125
+ assertCanPreserveRenderState(function() {
126
+ myp5.strokeWeight(10);
127
+ });
128
+ });
129
+
130
+ test('leak no state after strokeCap()', function() {
131
+ myp5.strokeCap(myp5.ROUND);
132
+ assertCanPreserveRenderState(function() {
133
+ myp5.strokeCap(myp5.SQUARE);
134
+ });
135
+ });
136
+
137
+ test('leak no state after strokeJoin()', function() {
138
+ myp5.strokeJoin(myp5.BEVEL);
139
+ assertCanPreserveRenderState(function() {
140
+ myp5.strokeJoin(myp5.MITER);
141
+ });
142
+ });
143
+
144
+ test('leak no state after imageMode()', function() {
145
+ myp5.imageMode(myp5.CORNER);
146
+ assertCanPreserveRenderState(function() {
147
+ myp5.imageMode(myp5.CENTER);
148
+ });
149
+ });
150
+
151
+ test('leak no state after rectMode()', function() {
152
+ myp5.rectMode(myp5.CORNER);
153
+ assertCanPreserveRenderState(function() {
154
+ myp5.rectMode(myp5.CENTER);
155
+ });
156
+ });
157
+
158
+ test('leak no state after ellipseMode()', function() {
159
+ myp5.ellipseMode(myp5.CORNER);
160
+ assertCanPreserveRenderState(function() {
161
+ myp5.ellipseMode(myp5.CENTER);
162
+ });
163
+ });
164
+
165
+ test('leak no state after colorMode()', function() {
166
+ myp5.colorMode(myp5.HSB);
167
+ assertCanPreserveRenderState(function() {
168
+ myp5.colorMode(myp5.RGB);
169
+ });
170
+ });
171
+
172
+ test('leak no state after textAlign()', function() {
173
+ myp5.textAlign(myp5.RIGHT, myp5.BOTTOM);
174
+ assertCanPreserveRenderState(function() {
175
+ myp5.textAlign(myp5.CENTER, myp5.CENTER);
176
+ });
177
+ });
178
+
179
+ test('leak no state after textFont()', function() {
180
+ myp5.textFont('Georgia');
181
+ assertCanPreserveRenderState(function() {
182
+ myp5.textFont('Helvetica');
183
+ });
184
+ });
185
+
186
+ test('leak no state after textStyle()', function() {
187
+ myp5.textStyle(myp5.ITALIC);
188
+ assertCanPreserveRenderState(function() {
189
+ myp5.textStyle(myp5.BOLD);
190
+ });
191
+ });
192
+
193
+ test('leak no state after textSize()', function() {
194
+ myp5.textSize(12);
195
+ assertCanPreserveRenderState(function() {
196
+ myp5.textSize(16);
197
+ });
198
+ });
199
+
200
+ test('leak no state after textLeading()', function() {
201
+ myp5.textLeading(20);
202
+ assertCanPreserveRenderState(function() {
203
+ myp5.textLeading(30);
204
+ });
205
+ });
206
+ });
207
+
208
+ suite('p5.prototype.redraw', function() {
209
+ var iframe;
210
+
211
+ teardown(function() {
212
+ if (iframe) {
213
+ iframe.teardown();
214
+ iframe = null;
215
+ }
216
+ });
217
+
218
+ test('resets the rendering matrix between frames', function() {
219
+ return new Promise(function(resolve, reject) {
220
+ myp5.draw = function() {
221
+ myp5.background(0);
222
+ myp5.stroke(255);
223
+ myp5.point(10, 10);
224
+ if (myp5.get(10, 10)[0] === 0) {
225
+ reject(new Error("Drawing matrix doesn't appear to be reset"));
226
+ }
227
+ myp5.rotate(10);
228
+ };
229
+ myp5.redraw(10);
230
+ resolve();
231
+ });
232
+ });
233
+
234
+ test('instance redraw is independent of window', function() {
235
+ // callback for p5 instance mode.
236
+ // It does not call noLoop so redraw will be called many times.
237
+ // Redraw is not supposed to call window.draw even though no draw is defined in cb
238
+ function cb(s) {
239
+ s.setup = function() {
240
+ setTimeout(window.afterSetup, 1000);
241
+ };
242
+ }
243
+ return new Promise(function(resolve) {
244
+ iframe = createP5Iframe(
245
+ [
246
+ P5_SCRIPT_TAG,
247
+ '<script>',
248
+ 'globalDraws = 0;',
249
+ 'function setup() { noLoop(); }',
250
+ 'function draw() { window.globalDraws++; }',
251
+ 'new p5(' + cb.toString() + ');',
252
+ '</script>'
253
+ ].join('\n')
254
+ );
255
+ iframe.elt.contentWindow.afterSetup = resolve;
256
+ }).then(function() {
257
+ var win = iframe.elt.contentWindow;
258
+ assert.strictEqual(win.globalDraws, 1);
259
+ });
260
+ });
261
+ });
262
+
263
+ suite('loop', function() {
264
+ testSketchWithPromise('loop in setup does not call draw', function(
265
+ sketch,
266
+ resolve,
267
+ reject
268
+ ) {
269
+ sketch.setup = function() {
270
+ sketch.loop();
271
+ resolve();
272
+ };
273
+
274
+ sketch.draw = function() {
275
+ reject(new Error('Entered draw during loop()'));
276
+ };
277
+ });
278
+
279
+ testSketchWithPromise('loop in draw does not call draw', function(
280
+ sketch,
281
+ resolve,
282
+ reject
283
+ ) {
284
+ sketch.draw = function() {
285
+ if (sketch.frameCount > 1) {
286
+ reject(new Error('re-entered draw during loop() call'));
287
+ }
288
+ sketch.loop();
289
+ resolve();
290
+ };
291
+ });
292
+ });
293
+ });
@@ -0,0 +1,144 @@
1
+ suite('Transform', function() {
2
+ var sketch1; // sketch without WEBGL Mode
3
+ var sketch2; // skecth with WEBGL mode
4
+ setup(function(done) {
5
+ new p5(function(p) {
6
+ p.setup = function() {
7
+ sketch1 = p;
8
+ };
9
+ });
10
+ new p5(function(p) {
11
+ p.setup = function() {
12
+ p.createCanvas(100, 100, p.WEBGL);
13
+ sketch2 = p;
14
+ };
15
+ });
16
+ done();
17
+ });
18
+
19
+ teardown(function() {
20
+ sketch1.remove();
21
+ sketch2.remove();
22
+ });
23
+
24
+ suite('p5.prototype.rotate', function() {
25
+ test('should be a function', function() {
26
+ assert.ok(sketch1.rotate);
27
+ assert.typeOf(sketch1.rotate, 'function');
28
+ });
29
+ test('wrong param type at #0', function() {
30
+ assert.validationError(function() {
31
+ sketch1.rotate('a');
32
+ });
33
+ });
34
+ test('wrong param type at #1', function() {
35
+ assert.validationError(function() {
36
+ sketch1.rotate(sketch1.PI, 'x');
37
+ });
38
+ });
39
+ });
40
+
41
+ suite('p5.prototype.rotateX', function() {
42
+ test('should be a function', function() {
43
+ assert.ok(sketch1.rotateX);
44
+ assert.typeOf(sketch1.rotateX, 'function');
45
+ });
46
+ test('throws error. should be used in WEBGL mode', function() {
47
+ assert.throws(function() {
48
+ sketch1.rotateX(100);
49
+ }, Error);
50
+ });
51
+ test('wrong param type at #0', function() {
52
+ assert.validationError(function() {
53
+ sketch2.rotateX('x');
54
+ });
55
+ });
56
+ });
57
+
58
+ suite('p5.prototype.rotateY', function() {
59
+ test('should be a function', function() {
60
+ assert.ok(sketch1.rotateY);
61
+ assert.typeOf(sketch1.rotateY, 'function');
62
+ });
63
+ test('throws error. should be used in WEBGL mode', function() {
64
+ assert.throws(function() {
65
+ sketch1.rotateY(100);
66
+ }, Error);
67
+ });
68
+ test('wrong param type at #0', function() {
69
+ assert.validationError(function() {
70
+ sketch2.rotateY('x');
71
+ });
72
+ });
73
+ });
74
+
75
+ suite('p5.prototype.rotateZ', function() {
76
+ test('should be a function', function() {
77
+ assert.ok(sketch1.rotateZ);
78
+ assert.typeOf(sketch1.rotateZ, 'function');
79
+ });
80
+ test('throws error. should be used in WEBGL mode', function() {
81
+ assert.throws(function() {
82
+ sketch1.rotateZ(100);
83
+ }, Error);
84
+ });
85
+ test('wrong param type at #0', function() {
86
+ assert.validationError(function() {
87
+ sketch2.rotateZ('x');
88
+ });
89
+ });
90
+ });
91
+
92
+ suite('p5.prototype.scale', function() {
93
+ test('should be a function', function() {
94
+ assert.ok(sketch1.scale);
95
+ assert.typeOf(sketch1.scale, 'function');
96
+ });
97
+ test('wrong param type at #0', function() {
98
+ assert.validationError(function() {
99
+ sketch1.scale('a');
100
+ });
101
+ });
102
+ });
103
+
104
+ suite('p5.prototype.shearX', function() {
105
+ test('should be a function', function() {
106
+ assert.ok(sketch1.shearX);
107
+ assert.typeOf(sketch1.shearX, 'function');
108
+ });
109
+ test('wrong param type at #0', function() {
110
+ assert.validationError(function() {
111
+ sketch1.shearX('a');
112
+ });
113
+ });
114
+ });
115
+
116
+ suite('p5.prototype.shearY', function() {
117
+ test('should be a function', function() {
118
+ assert.ok(sketch1.shearY);
119
+ assert.typeOf(sketch1.shearY, 'function');
120
+ });
121
+ test('wrong param type at #0', function() {
122
+ assert.validationError(function() {
123
+ sketch1.shearY('a');
124
+ });
125
+ });
126
+ });
127
+
128
+ suite('p5.prototype.translate', function() {
129
+ test('should be a function', function() {
130
+ assert.ok(sketch1.translate);
131
+ assert.typeOf(sketch1.translate, 'function');
132
+ });
133
+ test('wrong param type at #0', function() {
134
+ assert.validationError(function() {
135
+ sketch1.translate('a', 10);
136
+ });
137
+ });
138
+ test('missing param #1', function() {
139
+ assert.validationError(function() {
140
+ sketch1.translate(10);
141
+ });
142
+ });
143
+ });
144
+ });
@@ -0,0 +1,28 @@
1
+ suite('Version', 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
+ test('exists on p5 object', function() {
18
+ assert.isString(p5.VERSION);
19
+ // ensure the string isn't empty
20
+ assert.isTrue(p5.VERSION.length > 0);
21
+ });
22
+
23
+ test('exists on instance of p5 sketch', function() {
24
+ assert.isString(myp5.VERSION);
25
+ // ensure the string isn't empty
26
+ assert.isTrue(myp5.VERSION.length > 0);
27
+ });
28
+ });
@@ -0,0 +1,137 @@
1
+ suite('Vertex', function() {
2
+ var myp5;
3
+ let _friendlyErrorSpy;
4
+ setup(function(done) {
5
+ _friendlyErrorSpy = sinon.spy(p5, '_friendlyError');
6
+ new p5(function(p) {
7
+ p.setup = function() {
8
+ myp5 = p;
9
+ done();
10
+ };
11
+ });
12
+ });
13
+
14
+ teardown(function() {
15
+ _friendlyErrorSpy.restore();
16
+ myp5.remove();
17
+ });
18
+
19
+ suite('p5.prototype.beginShape', function() {
20
+ test('should be a function', function() {
21
+ assert.ok(myp5.beginShape);
22
+ assert.typeOf(myp5.beginShape, 'function');
23
+ });
24
+ test('no friendly-err-msg. missing param #0', function() {
25
+ assert.doesNotThrow(
26
+ function() {
27
+ myp5.beginShape();
28
+ },
29
+ Error,
30
+ 'got unwanted exception'
31
+ );
32
+ });
33
+ test('wrong param type at #0', function() {
34
+ assert.validationError(function() {
35
+ myp5.beginShape(myp5.BEVEL);
36
+ });
37
+ });
38
+ test('wrong param type at #0', function() {
39
+ assert.validationError(function() {
40
+ myp5.beginShape(20);
41
+ });
42
+ });
43
+ });
44
+
45
+ suite('p5.prototype.quadraticVertex', function() {
46
+ test('should be a function', function() {
47
+ assert.ok(myp5.quadraticVertex);
48
+ assert.typeOf(myp5.quadraticVertex, 'function');
49
+ });
50
+ test('missing param #3', function() {
51
+ assert.validationError(function() {
52
+ myp5.quadraticVertex(80, 20, 50);
53
+ });
54
+ });
55
+ test('missing param #5', function() {
56
+ assert.validationError(function() {
57
+ myp5.quadraticVertex(80, 20, 50, 50, 10);
58
+ });
59
+ });
60
+ test('_friendlyError is called. vertex() should be used once before quadraticVertex()', function() {
61
+ myp5.quadraticVertex(80, 20, 50, 50, 10, 20);
62
+ assert(_friendlyErrorSpy.calledOnce, 'p5._friendlyError was not called');
63
+ });
64
+ });
65
+
66
+ suite('p5.prototype.bezierVertex', function() {
67
+ test('should be a function', function() {
68
+ assert.ok(myp5.bezierVertex);
69
+ assert.typeOf(myp5.bezierVertex, 'function');
70
+ });
71
+ test('missing param #6', function() {
72
+ assert.validationError(function() {
73
+ myp5.bezierVertex(25, 30, 25, -30, -25);
74
+ });
75
+ });
76
+ test('missing param #8-9', function() {
77
+ assert.validationError(function() {
78
+ myp5.bezierVertex(25, 30, 25, -30, -25, 30, 20);
79
+ });
80
+ });
81
+ test('_friendlyError is called. vertex() should be used once before bezierVertex()', function() {
82
+ myp5.bezierVertex(25, 30, 25, -30, -25, 30);
83
+ assert(_friendlyErrorSpy.calledOnce, 'p5._friendlyError was not called');
84
+ });
85
+ });
86
+
87
+ suite('p5.prototype.curveVertex', function() {
88
+ test('should be a function', function() {
89
+ assert.ok(myp5.curveVertex);
90
+ assert.typeOf(myp5.curveVertex, 'function');
91
+ });
92
+ test('missing param #1', function() {
93
+ assert.validationError(function() {
94
+ myp5.curveVertex(40);
95
+ });
96
+ });
97
+ });
98
+
99
+ suite('p5.prototype.endShape', function() {
100
+ test('should be a function', function() {
101
+ assert.ok(myp5.endShape);
102
+ assert.typeOf(myp5.endShape, 'function');
103
+ });
104
+ test('no friendly-err-msg. missing param #0', function() {
105
+ assert.doesNotThrow(
106
+ function() {
107
+ myp5.endShape();
108
+ },
109
+ Error,
110
+ 'got unwanted exception'
111
+ );
112
+ });
113
+ test('wrong param type at #0', function() {
114
+ assert.validationError(function() {
115
+ myp5.endShape(20);
116
+ });
117
+ });
118
+ });
119
+
120
+ suite('p5.prototype.vertex', function() {
121
+ test('should be a function', function() {
122
+ assert.ok(myp5.vertex);
123
+ assert.typeOf(myp5.vertex, 'function');
124
+ });
125
+ // p5.prototype.vertex parameter validation is absent
126
+ test.skip('missing param #1', function() {
127
+ assert.validationError(function() {
128
+ myp5.vertex(10);
129
+ });
130
+ });
131
+ test.skip('wrong param type at #0', function() {
132
+ assert.validationError(function() {
133
+ myp5.vertex('a', 1);
134
+ });
135
+ });
136
+ });
137
+ });