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.
- package/.vscode/launch.json +26 -0
- package/bun.lockb +0 -0
- package/p5-tests/js/chai_helpers.js +20 -0
- package/p5-tests/js/mocha_setup.js +2 -0
- package/p5-tests/js/modernizr.js +5 -0
- package/p5-tests/js/p5_helpers.js +135 -0
- package/p5-tests/js/sinon.js +5949 -0
- package/p5-tests/mocha.css +289 -0
- package/p5-tests/test.html +71 -0
- package/p5-tests/unit/color/color_conversion.js +68 -0
- package/p5-tests/unit/color/creating_reading.js +217 -0
- package/p5-tests/unit/color/p5.Color.js +1000 -0
- package/p5-tests/unit/color/setting.js +289 -0
- package/p5-tests/unit/core/2d_primitives.js +490 -0
- package/p5-tests/unit/core/attributes.js +115 -0
- package/p5-tests/unit/core/curves.js +139 -0
- package/p5-tests/unit/core/environment.js +248 -0
- package/p5-tests/unit/core/error_helpers.js +1158 -0
- package/p5-tests/unit/core/main.js +340 -0
- package/p5-tests/unit/core/p5.Element.js +773 -0
- package/p5-tests/unit/core/p5.Graphics.js +179 -0
- package/p5-tests/unit/core/preload.js +285 -0
- package/p5-tests/unit/core/rendering.js +116 -0
- package/p5-tests/unit/core/structure.js +293 -0
- package/p5-tests/unit/core/transform.js +144 -0
- package/p5-tests/unit/core/version.js +28 -0
- package/p5-tests/unit/core/vertex.js +137 -0
- package/p5-tests/unit/dom/dom.js +2146 -0
- package/p5-tests/unit/events/acceleration.js +213 -0
- package/p5-tests/unit/events/keyboard.js +179 -0
- package/p5-tests/unit/events/mouse.js +487 -0
- package/p5-tests/unit/events/touch.js +180 -0
- package/p5-tests/unit/image/downloading.js +379 -0
- package/p5-tests/unit/image/filters.js +92 -0
- package/p5-tests/unit/image/loading.js +413 -0
- package/p5-tests/unit/image/p5.Image.js +201 -0
- package/p5-tests/unit/image/pixels.js +234 -0
- package/p5-tests/unit/io/files.js +378 -0
- package/p5-tests/unit/io/loadBytes.js +149 -0
- package/p5-tests/unit/io/loadImage.js +123 -0
- package/p5-tests/unit/io/loadJSON.js +185 -0
- package/p5-tests/unit/io/loadModel.js +215 -0
- package/p5-tests/unit/io/loadShader.js +176 -0
- package/p5-tests/unit/io/loadStrings.js +140 -0
- package/p5-tests/unit/io/loadTable.js +183 -0
- package/p5-tests/unit/io/loadXML.js +127 -0
- package/p5-tests/unit/io/saveModel.js +113 -0
- package/p5-tests/unit/io/saveTable.js +142 -0
- package/p5-tests/unit/math/calculation.js +452 -0
- package/p5-tests/unit/math/noise.js +66 -0
- package/p5-tests/unit/math/p5.Vector.js +1886 -0
- package/p5-tests/unit/math/random.js +177 -0
- package/p5-tests/unit/math/trigonometry.js +144 -0
- package/p5-tests/unit/spec.js +50 -0
- package/p5-tests/unit/typography/attributes.js +120 -0
- package/p5-tests/unit/typography/loadFont.js +162 -0
- package/p5-tests/unit/typography/p5.Font.js +63 -0
- package/p5-tests/unit/utilities/conversion.js +329 -0
- package/p5-tests/unit/utilities/time_date.js +133 -0
- package/package.json +1 -1
- package/q5.js +48 -37
- package/q5.min.js +1 -1
- package/src/q5-2d-image.js +3 -1
- package/src/q5-core.js +3 -1
- package/src/q5-math.js +1 -0
- package/src/q5-webgpu-canvas.js +8 -7
- package/src/q5-webgpu-drawing.js +15 -12
- package/src/q5-webgpu-image.js +1 -1
- package/src/q5-webgpu-text.js +17 -15
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
suite('Graphics', 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
|
+
function assertValidGraphSizes(graph, w, h, density) {
|
|
18
|
+
assert.strictEqual(graph.pixelDensity(), density, 'invalid pixel density');
|
|
19
|
+
assert.strictEqual(graph.width, w, 'invalid width');
|
|
20
|
+
assert.strictEqual(graph.height, h, 'invalid height');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function assertValidCanvasSizes(canvas, w, h, density) {
|
|
24
|
+
assert.strictEqual(canvas.width, w * density, 'canvas.width');
|
|
25
|
+
assert.strictEqual(canvas.height, h * density, 'canvas.height');
|
|
26
|
+
assert.strictEqual(
|
|
27
|
+
canvas.style.width,
|
|
28
|
+
'' + w + 'px',
|
|
29
|
+
'invalid canvas.style.width'
|
|
30
|
+
);
|
|
31
|
+
assert.strictEqual(
|
|
32
|
+
canvas.style.height,
|
|
33
|
+
'' + h + 'px',
|
|
34
|
+
'invalid canvas.style.height'
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function assertValidPixels(graph, w, h, density) {
|
|
39
|
+
graph.loadPixels();
|
|
40
|
+
var real = graph.pixels.length;
|
|
41
|
+
var expected = w * density * h * density * 4;
|
|
42
|
+
assert.strictEqual(real, expected, 'invalid number of pixels');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
suite('p5.prototype.createGraphics', function() {
|
|
46
|
+
test('it creates a graphics', function() {
|
|
47
|
+
var graph = myp5.createGraphics(10, 17);
|
|
48
|
+
assert.isObject(graph);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
suite('p5.Graphics', function() {
|
|
54
|
+
test('it has necessary properties', function() {
|
|
55
|
+
var graph = myp5.createGraphics(10, 17);
|
|
56
|
+
assert.property(graph, 'width');
|
|
57
|
+
assert.property(graph, 'height');
|
|
58
|
+
assert.property(graph, 'canvas');
|
|
59
|
+
assert.property(graph, 'pixelDensity');
|
|
60
|
+
assert.property(graph, 'loadPixels');
|
|
61
|
+
assert.property(graph, 'pixels');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('it has consistent sizes', function() {
|
|
65
|
+
var graph = myp5.createGraphics(10, 17);
|
|
66
|
+
graph.pixelDensity(1);
|
|
67
|
+
assertValidGraphSizes(graph, 10, 17, 1);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('its canvas has consistent sizes', function() {
|
|
71
|
+
var graph = myp5.createGraphics(10, 17);
|
|
72
|
+
graph.pixelDensity(1);
|
|
73
|
+
assertValidCanvasSizes(graph.canvas, 10, 17, 1);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test('it has a valid pixels array', function() {
|
|
77
|
+
var graph = myp5.createGraphics(10, 17);
|
|
78
|
+
graph.pixelDensity(1);
|
|
79
|
+
assertValidPixels(graph, 10, 17, 1);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
suite('p5.Graphics.pixelDensity', function() {
|
|
84
|
+
test('it can change density', function() {
|
|
85
|
+
var graph = myp5.createGraphics(10, 17);
|
|
86
|
+
graph.pixelDensity(1);
|
|
87
|
+
assert.strictEqual(graph.pixelDensity(), 1);
|
|
88
|
+
graph.pixelDensity(3);
|
|
89
|
+
assert.strictEqual(graph.pixelDensity(), 3);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test('it keeps valid sizes after change', function() {
|
|
93
|
+
var graph = myp5.createGraphics(10, 17);
|
|
94
|
+
graph.pixelDensity(1);
|
|
95
|
+
assertValidGraphSizes(graph, 10, 17, 1);
|
|
96
|
+
graph.pixelDensity(3);
|
|
97
|
+
assertValidGraphSizes(graph, 10, 17, 3);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test('its canvas keeps valid sizes after change', function() {
|
|
101
|
+
var graph = myp5.createGraphics(10, 17);
|
|
102
|
+
graph.pixelDensity(1);
|
|
103
|
+
assertValidCanvasSizes(graph.canvas, 10, 17, 1);
|
|
104
|
+
graph.pixelDensity(3);
|
|
105
|
+
assertValidCanvasSizes(graph.canvas, 10, 17, 3);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test('it keeps a valid pixel array after change', function() {
|
|
109
|
+
var graph = myp5.createGraphics(10, 17);
|
|
110
|
+
graph.pixelDensity(1);
|
|
111
|
+
assertValidPixels(graph, 10, 17, 1);
|
|
112
|
+
|
|
113
|
+
graph.pixelDensity(3);
|
|
114
|
+
assertValidPixels(graph, 10, 17, 3);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
suite('p5.Graphics.resizeCanvas', function() {
|
|
119
|
+
test('it can call resizeCanvas', function() {
|
|
120
|
+
var graph = myp5.createGraphics(10, 17);
|
|
121
|
+
var resize = function() {
|
|
122
|
+
graph.resizeCanvas(19, 16);
|
|
123
|
+
};
|
|
124
|
+
assert.doesNotThrow(resize);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test('it resizes properly with pixelDensity 1', function() {
|
|
128
|
+
var graph = myp5.createGraphics(10, 17);
|
|
129
|
+
graph.pixelDensity(1);
|
|
130
|
+
graph.resizeCanvas(19, 16);
|
|
131
|
+
assertValidGraphSizes(graph, 19, 16, 1);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test('its canvas resizes properly with pixelDensity 1', function() {
|
|
135
|
+
var graph = myp5.createGraphics(10, 17);
|
|
136
|
+
graph.pixelDensity(1);
|
|
137
|
+
graph.resizeCanvas(19, 16);
|
|
138
|
+
assertValidCanvasSizes(graph.canvas, 19, 16, 1);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test('it resizes properly the pixels array with density 1', function() {
|
|
142
|
+
var graph = myp5.createGraphics(10, 17);
|
|
143
|
+
graph.pixelDensity(1);
|
|
144
|
+
graph.resizeCanvas(19, 16);
|
|
145
|
+
assertValidPixels(graph, 19, 16, 1);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test('it resizes properly with pixelDensity 2', function() {
|
|
149
|
+
var graph = myp5.createGraphics(10, 17);
|
|
150
|
+
graph.pixelDensity(2);
|
|
151
|
+
graph.resizeCanvas(19, 16);
|
|
152
|
+
assertValidGraphSizes(graph, 19, 16, 2);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
test('its canvas resizes properly with pixelDensity 2', function() {
|
|
156
|
+
var graph = myp5.createGraphics(10, 17);
|
|
157
|
+
graph.pixelDensity(2);
|
|
158
|
+
graph.resizeCanvas(19, 16);
|
|
159
|
+
assertValidCanvasSizes(graph.canvas, 19, 16, 2);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
test('it resizes properly the pixels array with density 2', function() {
|
|
163
|
+
var graph = myp5.createGraphics(10, 17);
|
|
164
|
+
graph.pixelDensity(2);
|
|
165
|
+
graph.resizeCanvas(19, 16);
|
|
166
|
+
assertValidPixels(graph, 19, 16, 2);
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
suite('p5.Graphics.remove()', function() {
|
|
171
|
+
test('it sets properties to undefined after removal', function() {
|
|
172
|
+
var graph = myp5.createGraphics(10, 17);
|
|
173
|
+
graph.remove();
|
|
174
|
+
assert.isUndefined(graph.canvas);
|
|
175
|
+
assert.isUndefined(graph._renderer);
|
|
176
|
+
assert.isUndefined(graph.elt);
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
});
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
suite('preloads', () => {
|
|
2
|
+
let preloadCache = null;
|
|
3
|
+
setup(() => {
|
|
4
|
+
preloadCache = p5.prototype._promisePreloads;
|
|
5
|
+
p5.prototype._promisePreloads = [...preloadCache];
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
teardown(() => {
|
|
9
|
+
p5.prototype._promisePreloads = preloadCache;
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
suite('From external sources', () => {
|
|
13
|
+
test('Extension preload causes setup to wait', () => {
|
|
14
|
+
let resolved = false;
|
|
15
|
+
const target = {
|
|
16
|
+
async testPreloadFunction() {
|
|
17
|
+
await new Promise(res => setTimeout(res, 10));
|
|
18
|
+
resolved = true;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
p5.prototype._promisePreloads.push({
|
|
23
|
+
target,
|
|
24
|
+
method: 'testPreloadFunction'
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
return promisedSketch((sketch, resolve, reject) => {
|
|
28
|
+
sketch.preload = () => {
|
|
29
|
+
target.testPreloadFunction();
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
sketch.setup = () => {
|
|
33
|
+
if (resolved) {
|
|
34
|
+
resolve();
|
|
35
|
+
} else {
|
|
36
|
+
reject(new Error('Sketch enetered setup too early.'));
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('Extension preload error causes setup to not execute', () => {
|
|
43
|
+
const target = {
|
|
44
|
+
async testPreloadFunction() {
|
|
45
|
+
throw new Error('Testing Error');
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
p5.prototype._promisePreloads.push({
|
|
50
|
+
target,
|
|
51
|
+
method: 'testPreloadFunction'
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
return promisedSketch((sketch, resolve, reject) => {
|
|
55
|
+
sketch.preload = () => {
|
|
56
|
+
target.testPreloadFunction();
|
|
57
|
+
setTimeout(resolve, 10);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
sketch.setup = () => {
|
|
61
|
+
reject('Sketch should not enter setup');
|
|
62
|
+
};
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
suite('addCallbacks', () => {
|
|
67
|
+
test('Extension is passed all arguments when not using addCallbacks', () => {
|
|
68
|
+
const target = {
|
|
69
|
+
async testPreloadFunction(...args) {
|
|
70
|
+
assert.lengthOf(args, 3);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
p5.prototype._promisePreloads.push({
|
|
75
|
+
target,
|
|
76
|
+
method: 'testPreloadFunction',
|
|
77
|
+
addCallbacks: false
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
return promisedSketch((sketch, resolve, reject) => {
|
|
81
|
+
sketch.preload = () => {
|
|
82
|
+
target
|
|
83
|
+
.testPreloadFunction(() => {}, () => {}, () => {})
|
|
84
|
+
.catch(reject);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
sketch.setup = resolve;
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test('Extension gets stripped arguments when using addCallbacks', () => {
|
|
92
|
+
const target = {
|
|
93
|
+
async testPreloadFunction(...args) {
|
|
94
|
+
assert.lengthOf(args, 1);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
p5.prototype._promisePreloads.push({
|
|
99
|
+
target,
|
|
100
|
+
method: 'testPreloadFunction',
|
|
101
|
+
addCallbacks: true
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
return promisedSketch((sketch, resolve, reject) => {
|
|
105
|
+
sketch.preload = () => {
|
|
106
|
+
target
|
|
107
|
+
.testPreloadFunction(() => {}, () => {}, () => {})
|
|
108
|
+
.catch(reject);
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
sketch.setup = resolve;
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test('Extension with addCallbacks supports success callback', () => {
|
|
116
|
+
const target = {
|
|
117
|
+
async testPreloadFunction(...args) {
|
|
118
|
+
assert.lengthOf(args, 1);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
p5.prototype._promisePreloads.push({
|
|
123
|
+
target,
|
|
124
|
+
method: 'testPreloadFunction',
|
|
125
|
+
addCallbacks: true
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
let success = 0;
|
|
129
|
+
|
|
130
|
+
return promisedSketch((sketch, resolve, reject) => {
|
|
131
|
+
sketch.preload = () => {
|
|
132
|
+
target
|
|
133
|
+
.testPreloadFunction(0, () => {
|
|
134
|
+
success++;
|
|
135
|
+
})
|
|
136
|
+
.catch(reject);
|
|
137
|
+
target
|
|
138
|
+
.testPreloadFunction(
|
|
139
|
+
() => {},
|
|
140
|
+
() => {
|
|
141
|
+
success++;
|
|
142
|
+
},
|
|
143
|
+
() => {
|
|
144
|
+
reject(new Error('Failure callback executed'));
|
|
145
|
+
}
|
|
146
|
+
)
|
|
147
|
+
.catch(reject);
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
sketch.setup = () => {
|
|
151
|
+
if (success !== 2) {
|
|
152
|
+
reject(
|
|
153
|
+
new Error(`Not all success callbacks were run: ${success}/2`)
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
resolve();
|
|
157
|
+
};
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
suite('legacyPreload', () => {
|
|
163
|
+
test('Extension legacy preload causes setup to wait', () => {
|
|
164
|
+
let resolved = false;
|
|
165
|
+
const target = {
|
|
166
|
+
async testPreloadFunction() {
|
|
167
|
+
await new Promise(res => setTimeout(res, 10));
|
|
168
|
+
resolved = true;
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
p5.prototype._promisePreloads.push({
|
|
173
|
+
target,
|
|
174
|
+
method: 'testPreloadFunction',
|
|
175
|
+
legacyPreloadSetup: {
|
|
176
|
+
method: 'testPreloadLegacy'
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
return promisedSketch((sketch, resolve, reject) => {
|
|
181
|
+
sketch.preload = () => {
|
|
182
|
+
target.testPreloadLegacy();
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
sketch.setup = () => {
|
|
186
|
+
if (resolved) {
|
|
187
|
+
resolve();
|
|
188
|
+
} else {
|
|
189
|
+
reject(new Error('Sketch enetered setup too early.'));
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
test('Extension legacy preload error causes setup to not execute', () => {
|
|
196
|
+
const target = {
|
|
197
|
+
async testPreloadFunction() {
|
|
198
|
+
throw new Error('Testing Error');
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
p5.prototype._promisePreloads.push({
|
|
203
|
+
target,
|
|
204
|
+
method: 'testPreloadFunction',
|
|
205
|
+
legacyPreloadSetup: {
|
|
206
|
+
method: 'testPreloadLegacy'
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
return promisedSketch((sketch, resolve, reject) => {
|
|
211
|
+
sketch.preload = () => {
|
|
212
|
+
target.testPreloadLegacy();
|
|
213
|
+
setTimeout(resolve, 10);
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
sketch.setup = () => {
|
|
217
|
+
reject('Sketch should not enter setup');
|
|
218
|
+
};
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
test('Extension legacy preload returns objects correctly', async () => {
|
|
223
|
+
let testItem = {
|
|
224
|
+
test: true,
|
|
225
|
+
otherTest: []
|
|
226
|
+
};
|
|
227
|
+
const target = {
|
|
228
|
+
async testPreloadFunction() {
|
|
229
|
+
return testItem;
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
p5.prototype._promisePreloads.push({
|
|
234
|
+
target,
|
|
235
|
+
method: 'testPreloadFunction',
|
|
236
|
+
legacyPreloadSetup: {
|
|
237
|
+
method: 'testPreloadLegacy'
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
let testResult;
|
|
242
|
+
|
|
243
|
+
await promisedSketch((sketch, resolve, reject) => {
|
|
244
|
+
sketch.preload = () => {
|
|
245
|
+
testResult = target.testPreloadLegacy();
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
sketch.setup = resolve();
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
assert.deepEqual(testResult, testItem);
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
test('Extension legacy preload returns arrays correctly', async () => {
|
|
255
|
+
let testItem = [true, [], {}];
|
|
256
|
+
const target = {
|
|
257
|
+
async testPreloadFunction() {
|
|
258
|
+
return testItem;
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
p5.prototype._promisePreloads.push({
|
|
263
|
+
target,
|
|
264
|
+
method: 'testPreloadFunction',
|
|
265
|
+
legacyPreloadSetup: {
|
|
266
|
+
method: 'testPreloadLegacy',
|
|
267
|
+
createBaseObject: () => []
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
let testResult;
|
|
272
|
+
|
|
273
|
+
await promisedSketch((sketch, resolve, reject) => {
|
|
274
|
+
sketch.preload = () => {
|
|
275
|
+
testResult = target.testPreloadLegacy();
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
sketch.setup = resolve();
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
assert.deepEqual(testResult, testItem);
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
});
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
suite('Rendering', 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.createCanvas', function() {
|
|
18
|
+
test('should have correct initial colors', function() {
|
|
19
|
+
var white = myp5.color(255, 255, 255).levels;
|
|
20
|
+
var black = myp5.color(0, 0, 0).levels;
|
|
21
|
+
assert.deepEqual(myp5.color(myp5._renderer._getFill()).levels, white);
|
|
22
|
+
assert.deepEqual(myp5.color(myp5._renderer._getStroke()).levels, black);
|
|
23
|
+
assert.deepEqual(myp5.color(myp5.drawingContext.fillStyle).levels, white);
|
|
24
|
+
assert.deepEqual(
|
|
25
|
+
myp5.color(myp5.drawingContext.strokeStyle).levels,
|
|
26
|
+
black
|
|
27
|
+
);
|
|
28
|
+
myp5.createCanvas(100, 100);
|
|
29
|
+
assert.deepEqual(myp5.color(myp5._renderer._getFill()).levels, white);
|
|
30
|
+
assert.deepEqual(myp5.color(myp5._renderer._getStroke()).levels, black);
|
|
31
|
+
assert.deepEqual(myp5.color(myp5.drawingContext.fillStyle).levels, white);
|
|
32
|
+
assert.deepEqual(
|
|
33
|
+
myp5.color(myp5.drawingContext.strokeStyle).levels,
|
|
34
|
+
black
|
|
35
|
+
);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
suite('p5.prototype.resizeCanvas', function() {
|
|
40
|
+
// let glStub;
|
|
41
|
+
|
|
42
|
+
// afterEach(() => {
|
|
43
|
+
// if (glStub) {
|
|
44
|
+
// glStub.restore();
|
|
45
|
+
// glStub = null;
|
|
46
|
+
// }
|
|
47
|
+
// });
|
|
48
|
+
|
|
49
|
+
test('should resize canvas', function() {
|
|
50
|
+
myp5.resizeCanvas(10, 20);
|
|
51
|
+
assert.equal(myp5.canvas.width, 10 * myp5.pixelDensity());
|
|
52
|
+
assert.equal(myp5.canvas.height, 20 * myp5.pixelDensity());
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('should restore fill color', function() {
|
|
56
|
+
myp5.fill('#f0f0f0');
|
|
57
|
+
myp5.resizeCanvas(10, 10);
|
|
58
|
+
assert.equal(myp5.drawingContext.fillStyle, '#f0f0f0');
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('should restore stroke color', function() {
|
|
62
|
+
myp5.stroke('#f0f0f0');
|
|
63
|
+
myp5.resizeCanvas(10, 10);
|
|
64
|
+
assert.equal(myp5.drawingContext.strokeStyle, '#f0f0f0');
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('should restore stroke weight', function() {
|
|
68
|
+
myp5.strokeWeight(323);
|
|
69
|
+
myp5.resizeCanvas(10, 10);
|
|
70
|
+
assert.equal(myp5.drawingContext.lineWidth, 323);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('should restore stroke cap', function() {
|
|
74
|
+
myp5.strokeCap(myp5.PROJECT);
|
|
75
|
+
myp5.resizeCanvas(10, 10);
|
|
76
|
+
assert.equal(myp5.drawingContext.lineCap, myp5.PROJECT);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
suite('p5.prototype.blendMode', function() {
|
|
81
|
+
var drawX = function() {
|
|
82
|
+
myp5.strokeWeight(30);
|
|
83
|
+
myp5.stroke(80, 150, 255);
|
|
84
|
+
myp5.line(25, 25, 75, 75);
|
|
85
|
+
myp5.stroke(255, 50, 50);
|
|
86
|
+
myp5.line(75, 25, 25, 75);
|
|
87
|
+
};
|
|
88
|
+
test('should be a function', function() {
|
|
89
|
+
assert.ok(myp5.blendMode);
|
|
90
|
+
assert.typeOf(myp5.blendMode, 'function');
|
|
91
|
+
});
|
|
92
|
+
test('should be able to ADD', function() {
|
|
93
|
+
myp5.blendMode(myp5.ADD);
|
|
94
|
+
drawX();
|
|
95
|
+
});
|
|
96
|
+
test('should be able to MULTIPLY', function() {
|
|
97
|
+
myp5.blendMode(myp5.MULTIPLY);
|
|
98
|
+
drawX();
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
suite('p5.prototype.setAttributes', function() {
|
|
103
|
+
test('_glAttributes should be null at start', function() {
|
|
104
|
+
assert.deepEqual(myp5._glAttributes, null);
|
|
105
|
+
});
|
|
106
|
+
test('_glAttributes should modify with setAttributes', function() {
|
|
107
|
+
myp5.setAttributes({ antialias: false, perPixelLighting: true });
|
|
108
|
+
assert.deepEqual(myp5._glAttributes.antialias, false);
|
|
109
|
+
assert.deepEqual(myp5._glAttributes.perPixelLighting, true);
|
|
110
|
+
});
|
|
111
|
+
test('_glAttributes.antialias modify with smooth()', function() {
|
|
112
|
+
myp5.smooth();
|
|
113
|
+
assert.deepEqual(myp5._glAttributes.antialias, true);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
});
|