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,139 +0,0 @@
1
- suite('Curves', 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.bezier', function() {
18
- test('should be a function', function() {
19
- assert.ok(myp5.bezier);
20
- assert.typeOf(myp5.bezier, 'function');
21
- });
22
- test('no friendly-err-msg', function() {
23
- assert.doesNotThrow(
24
- function() {
25
- myp5.bezier(85, 20, 10, 10, 90, 90, 15, 80);
26
- },
27
- Error,
28
- 'got unwanted exception'
29
- );
30
- });
31
- test('no friendly-err-msg. missing param #6, #7', function() {
32
- assert.validationError(function() {
33
- myp5.bezier(85, 20, 10, 10, 90, 90);
34
- });
35
- });
36
- test('wrong param type at #0', function() {
37
- assert.validationError(function() {
38
- myp5.bezier('a', 20, 10, 10, 90, 90, 15, 80);
39
- });
40
- });
41
- });
42
-
43
- suite('p5.prototype.bezierPoint', function() {
44
- var result;
45
- test('should be a function', function() {
46
- assert.ok(myp5.bezierPoint);
47
- assert.typeOf(myp5.bezierPoint, 'function');
48
- });
49
- test('should return a number: missing param #0~4', function() {
50
- assert.validationError(function() {
51
- result = myp5.bezierPoint();
52
- });
53
- });
54
- test('should return the correct point on a Bezier Curve', function() {
55
- result = myp5.bezierPoint(85, 10, 90, 15, 0.5);
56
- assert.equal(result, 50);
57
- assert.notEqual(result, -1);
58
- });
59
- });
60
-
61
- suite('p5.prototype.bezierTangent', function() {
62
- var result;
63
- test('should be a function', function() {
64
- assert.ok(myp5.bezierTangent);
65
- assert.typeOf(myp5.bezierTangent, 'function');
66
- });
67
- test('should return a number: missing param #0~4', function() {
68
- assert.validationError(function() {
69
- result = myp5.bezierTangent();
70
- });
71
- });
72
- test('should return the correct point on a Bezier Curve', function() {
73
- result = myp5.bezierTangent(95, 73, 73, 15, 0.5);
74
- assert.equal(result, -60);
75
- });
76
- });
77
-
78
- suite('p5.prototype.curve', function() {
79
- test('should be a function', function() {
80
- assert.ok(myp5.curve);
81
- assert.typeOf(myp5.curve, 'function');
82
- });
83
- test('no friendly-err-msg', function() {
84
- assert.doesNotThrow(
85
- function() {
86
- myp5.curve(5, 26, 5, 26, 73, 24, 73, 61);
87
- },
88
- Error,
89
- 'got unwanted exception'
90
- );
91
- });
92
- test('no friendly-err-msg. missing param #6, #7', function() {
93
- assert.validationError(function() {
94
- myp5.curve(5, 26, 5, 26, 73, 24);
95
- });
96
- });
97
- test('wrong param type at #0', function() {
98
- assert.validationError(function() {
99
- myp5.curve('a', 26, 5, 26, 73, 24, 73, 61);
100
- });
101
- });
102
- });
103
-
104
- suite('p5.prototype.curvePoint', function() {
105
- var result;
106
- test('should be a function', function() {
107
- assert.ok(myp5.curvePoint);
108
- assert.typeOf(myp5.curvePoint, 'function');
109
- });
110
- test('should return a number: missing param #0~4', function() {
111
- assert.validationError(function() {
112
- result = myp5.curvePoint();
113
- });
114
- });
115
- test('should return the correct point on a Catmull-Rom Curve', function() {
116
- result = myp5.curvePoint(5, 5, 73, 73, 0.5);
117
- assert.equal(result, 39);
118
- assert.notEqual(result, -1);
119
- });
120
- });
121
-
122
- suite('p5.prototype.curveTangent', function() {
123
- var result;
124
- test('should be a function', function() {
125
- assert.ok(myp5.curveTangent);
126
- assert.typeOf(myp5.curveTangent, 'function');
127
- });
128
- test('should return a number: missing param #0~4', function() {
129
- assert.validationError(function() {
130
- result = myp5.curveTangent();
131
- });
132
- });
133
- test('should return the correct point on a Catmull-Rom Curve', function() {
134
- result = myp5.curveTangent(95, 73, 73, 15, 0.5);
135
- assert.equal(result, 10);
136
- assert.notEqual(result, -1);
137
- });
138
- });
139
- });
@@ -1,248 +0,0 @@
1
- suite('Environment', 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.frameCount', function() {
18
- test('starts at zero', function() {
19
- return new Promise(function(resolve, reject) {
20
- // Has to use a custom p5 to hook setup correctly
21
- new p5(function(p) {
22
- p.setup = function() {
23
- if (p.frameCount !== 0) {
24
- reject('frameCount is not 0 in setup');
25
- }
26
- };
27
- p.draw = function() {
28
- if (p.frameCount === 1) {
29
- resolve();
30
- }
31
- };
32
- });
33
- });
34
- });
35
- test('matches draw calls', function() {
36
- return new Promise(function(resolve, reject) {
37
- var frames = myp5.frameCount;
38
- var start = myp5.frameCount;
39
- myp5.draw = function() {
40
- try {
41
- frames += 1;
42
- assert.equal(myp5.frameCount, frames);
43
- if (frames === start + 5) {
44
- // Test 5 seperate redraws
45
- myp5.noLoop();
46
- setTimeout(myp5.redraw.bind(myp5), 10);
47
- setTimeout(myp5.redraw.bind(myp5), 20);
48
- setTimeout(myp5.redraw.bind(myp5), 30);
49
- setTimeout(myp5.redraw.bind(myp5), 40);
50
- setTimeout(myp5.redraw.bind(myp5), 50);
51
- } else if (frames === start + 10) {
52
- // Test loop resuming
53
- myp5.loop();
54
- } else if (frames === start + 15) {
55
- // Test queuing multiple redraws
56
- myp5.noLoop();
57
- setTimeout(myp5.redraw.bind(myp5, 5), 10);
58
- } else if (frames === start + 20) {
59
- resolve();
60
- }
61
- assert.equal(myp5.frameCount, frames);
62
- } catch (err) {
63
- reject(err);
64
- }
65
- };
66
- });
67
- });
68
- });
69
-
70
- suite('p5.prototype.focused', function() {
71
- test('it should return true on focus', function() {
72
- window.dispatchEvent(new Event('focus'));
73
- assert.strictEqual(myp5.focused, true);
74
- });
75
-
76
- test('it should return true on blur', function() {
77
- window.dispatchEvent(new Event('blur'));
78
- assert.strictEqual(myp5.focused, false);
79
- });
80
- });
81
-
82
- suite('p5.prototype.cursor', function() {
83
- test('should change cursor to cross', function() {
84
- myp5.cursor(myp5.CROSS);
85
- assert.strictEqual(myp5._curElement.elt.style.cursor, 'crosshair');
86
- });
87
- });
88
-
89
- suite('p5.prototype.noCursor', function() {
90
- test('should change cursor to none', function() {
91
- myp5.noCursor();
92
- assert.strictEqual(myp5._curElement.elt.style.cursor, 'none');
93
- });
94
- });
95
-
96
- suite('p5.prototype.frameRate', function() {
97
- test('returns 0 on first draw call', function() {
98
- assert.strictEqual(myp5.frameRate(), 0);
99
- });
100
-
101
- test('returns current frame rate after first draw call', function() {
102
- return new Promise(function(resolve, reject) {
103
- new p5(function(p) {
104
- p.draw = function() {
105
- if (p.frameCount === 2 && p.frameRate() > 0) {
106
- resolve();
107
- p.remove();
108
- }
109
- };
110
- });
111
- });
112
- });
113
-
114
- test('wrong param type. throws error.', function() {
115
- assert.validationError(function() {
116
- myp5.frameRate('a');
117
- });
118
- });
119
-
120
- test('p5.prototype.getFrameRate', function() {
121
- assert.strictEqual(myp5.getFrameRate(), 0);
122
- });
123
-
124
- suite('drawing with target frame rates', function() {
125
- let clock;
126
- let prevRequestAnimationFrame;
127
- let nextFrameCallback = () => {};
128
- let controlledP5;
129
-
130
- setup(function() {
131
- clock = sinon.useFakeTimers(0);
132
- sinon.stub(window.performance, 'now', Date.now);
133
-
134
- // Save the real requestAnimationFrame so we can restore it later
135
- prevRequestAnimationFrame = window.requestAnimationFrame;
136
- // Use a fake requestAnimationFrame that just stores a ref to the callback
137
- // so that we can call it manually
138
- window.requestAnimationFrame = function(cb) {
139
- nextFrameCallback = cb;
140
- };
141
-
142
- return new Promise(function(resolve) {
143
- controlledP5 = new p5(function(p) {
144
- p.setup = function() {
145
- p.createCanvas(10, 10);
146
- p.frameRate(60);
147
- p.loop();
148
- resolve(p);
149
- };
150
-
151
- p.draw = function() {};
152
- });
153
- });
154
- });
155
-
156
- teardown(function() {
157
- clock.restore();
158
- window.performance.now.restore();
159
- window.requestAnimationFrame = prevRequestAnimationFrame;
160
- nextFrameCallback = function() {};
161
- controlledP5.remove();
162
- });
163
-
164
- test('draw() is called at the correct frame rate given a faster display', function() {
165
- sinon.spy(controlledP5, 'draw');
166
-
167
- clock.tick(1000 / 200); // Simulate a 200Hz refresh rate
168
- nextFrameCallback(); // trigger the next requestAnimationFrame
169
- assert(controlledP5.draw.notCalled, 'draw() should not be called before 1s/60');
170
-
171
- // Advance until 5ms before the next frame should render.
172
- // This should be within p5's threshold for rendering the frame.
173
- clock.tick(1000 / 60 - 1000 / 200 - 5);
174
- nextFrameCallback(); // trigger the next requestAnimationFrame
175
- assert(controlledP5.draw.calledOnce, 'one frame should have been drawn');
176
- // deltaTime should reflect real elapsed time
177
- assert.equal(controlledP5.deltaTime, 1000 / 60 - 5);
178
-
179
- // Advance enough time forward to be 1s/60 - 5ms from the last draw
180
- clock.tick(1000 / 60 - 5);
181
- nextFrameCallback(); // trigger the next requestAnimationFrame
182
- // Even though this is 1s/60 - 5ms from the last draw, the last frame came
183
- // in early, so we still shouldn't draw
184
- assert(controlledP5.draw.calledOnce, 'draw() should not be called before 1s/60 past the last target draw time');
185
-
186
- // Advance enough time forward to be 1s/60 from the last draw
187
- clock.tick(5);
188
- nextFrameCallback();
189
- assert(controlledP5.draw.calledTwice); // Now it should draw again!
190
- // deltaTime should reflect real elapsed time
191
- assert.equal(controlledP5.deltaTime, 1000 / 60);
192
- });
193
- });
194
- });
195
-
196
- suite('p5.prototype.getTargetFrameRate', function() {
197
- test('returns 60 on the first call', function() {
198
- assert.strictEqual(myp5.getTargetFrameRate(), 60);
199
- });
200
-
201
- test('returns set value of randomize integer', function() {
202
- let randVal = Math.floor(Math.random()*120);
203
- myp5.frameRate(randVal);
204
- assert.strictEqual(myp5.getTargetFrameRate(), randVal);
205
- });
206
- });
207
-
208
- suite('Canvas dimensions', function() {
209
- test('p5.prototype.width', function() {
210
- myp5.createCanvas(20, 30);
211
- assert.strictEqual(myp5.width, 20);
212
- });
213
-
214
- test('p5.prototype.height', function() {
215
- myp5.createCanvas(20, 30);
216
- assert.strictEqual(myp5.height, 30);
217
- });
218
- });
219
-
220
- suite('p5.prototype.pixelDensity', function() {
221
- test('returns the pixel density', function() {
222
- assert.isNumber(myp5.pixelDensity());
223
- });
224
-
225
- test('sets the pixel density', function() {
226
- myp5.pixelDensity(2);
227
- assert.strictEqual(myp5.pixelDensity(), 2);
228
- });
229
-
230
- test('wrong param type. throws validationError.', function() {
231
- assert.validationError(function() {
232
- myp5.pixelDensity('a');
233
- });
234
- });
235
- });
236
-
237
- suite('p5.prototype.displayDensity', function() {
238
- test('returns the pixel density of the display', function() {
239
- assert.isNumber(myp5.displayDensity());
240
- });
241
-
242
- test('pixelDensity does not change display density', function() {
243
- let pd = myp5.displayDensity();
244
- myp5.pixelDensity(pd + 1);
245
- assert.isNumber(myp5.displayDensity(), pd);
246
- });
247
- });
248
- });