Skip to content

Commit f55c878

Browse files
author
Lauren McCarthy
committed
Merge branch 'master' of github.com:processing/p5.js
2 parents 443986a + f7a2eab commit f55c878

File tree

5 files changed

+141
-9
lines changed

5 files changed

+141
-9
lines changed

lib/addons/p5.dom.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2935,7 +2935,10 @@
29352935
this.setModified(true);
29362936
return this;
29372937
};
2938-
p5.MediaElement.prototype.get = p5.Renderer2D.prototype.get;
2938+
p5.MediaElement.prototype.get = function() {
2939+
this._ensureCanvas();
2940+
return p5.Renderer2D.prototype.get.apply(this, arguments);
2941+
};
29392942
p5.MediaElement.prototype._getPixel = function() {
29402943
if (this.loadedmetadata) {
29412944
// wait for metadata

src/core/p5.Graphics.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ p5.Graphics = function(w, h, renderer, pInst) {
3030
var node = pInst._userNode || document.body;
3131
node.appendChild(this.canvas);
3232

33-
p5.Element.call(this, this.canvas, pInst, false);
33+
p5.Element.call(this, this.canvas, pInst);
3434

3535
// bind methods and props of p5 to the new object
3636
for (var p in p5.prototype) {

src/typography/p5.Font.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ p5.Font.prototype.textBounds = function(str, x, y, fontSize, opts) {
164164
* @param {Object} [options] an (optional) object that can contain:
165165
*
166166
* <br>sampleFactor - the ratio of path-length to number of samples
167-
* (default=.25); higher values yield more points and are therefore
167+
* (default=.1); higher values yield more points and are therefore
168168
* more precise
169169
*
170170
* <br>simplifyThreshold - if set to a non-zero value, collinear points will be

test/manual-test-examples/webgl/material/perPixelLighting/sketch.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function setup() {
99
noStroke();
1010
}
1111

12-
var lights = [
12+
var lightsData = [
1313
{ c: '#f00', t: 1.12, p: 1.91, r: 0.2 },
1414
{ c: '#0f0', t: 1.21, p: 1.31, r: 0.2 },
1515
{ c: '#00f', t: 1.37, p: 1.57, r: 0.2 },
@@ -24,11 +24,11 @@ function draw() {
2424

2525
directionalLight(color('#111'), 1, 1, 1);
2626

27-
for (var i = 0; i < lights.length; i++) {
28-
var light = lights[i];
27+
for (var i = 0; i < lightsData.length; i++) {
28+
var lightData = lightsData[i];
2929
pointLight(
30-
color(light.c),
31-
p5.Vector.fromAngles(t * light.t, t * light.p, width * 2)
30+
color(lightData.c),
31+
p5.Vector.fromAngles(t * lightData.t, t * lightData.p, width * 2)
3232
);
3333
}
3434

test/unit/events/keyboard.js

Lines changed: 130 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,90 @@
11
suite('Keyboard Events', 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.keyIsPressed', function() {
18+
test('keyIsPressed should be a boolean', function() {
19+
assert.isBoolean(myp5.keyIsPressed);
20+
});
21+
22+
test('keyIsPressed should be true on key press', function() {
23+
window.dispatchEvent(new KeyboardEvent('keydown'));
24+
assert.strictEqual(myp5.keyIsPressed, true);
25+
});
26+
27+
test('keyIsPressed should be false on key up', function() {
28+
window.dispatchEvent(new KeyboardEvent('keyup'));
29+
assert.strictEqual(myp5.keyIsPressed, false);
30+
});
31+
});
32+
33+
suite('p5.prototype.isKeyPressed', function() {
34+
test('isKeyPressed should be a boolean', function() {
35+
assert.isBoolean(myp5.isKeyPressed);
36+
});
37+
38+
test('isKeyPressed should be true on key press', function() {
39+
window.dispatchEvent(new KeyboardEvent('keydown'));
40+
assert.strictEqual(myp5.isKeyPressed, true);
41+
});
42+
43+
test('isKeyPressed should be false on key up', function() {
44+
window.dispatchEvent(new KeyboardEvent('keyup'));
45+
assert.strictEqual(myp5.isKeyPressed, false);
46+
});
47+
});
48+
49+
suite('p5.prototype.key', function() {
50+
test('key should be a string', function() {
51+
window.dispatchEvent(new KeyboardEvent('keydown', { key: 's' }));
52+
assert.isString(myp5.key);
53+
});
54+
55+
test('key should return the key pressed', function() {
56+
window.dispatchEvent(new KeyboardEvent('keydown', { key: 'A' }));
57+
assert.strictEqual(myp5.key, 'A');
58+
});
59+
60+
test('key should return the key pressed', function() {
61+
window.dispatchEvent(new KeyboardEvent('keydown', { key: '9' }));
62+
assert.strictEqual(myp5.key, '9');
63+
});
64+
65+
test('key should return the key pressed', function() {
66+
window.dispatchEvent(new KeyboardEvent('keydown', { key: 'CapsLock' }));
67+
assert.strictEqual(myp5.key, 'CapsLock');
68+
});
69+
});
70+
71+
suite('p5.prototype.keyCode', function() {
72+
test('keyCode should be a number', function() {
73+
window.dispatchEvent(new KeyboardEvent('keydown', { key: 's' }));
74+
assert.isNumber(myp5.keyCode);
75+
});
76+
77+
test('key should return the key pressed', function() {
78+
window.dispatchEvent(new KeyboardEvent('keydown', { keyCode: 65 }));
79+
assert.strictEqual(myp5.keyCode, 65);
80+
});
81+
82+
test('key should return the key pressed', function() {
83+
window.dispatchEvent(new KeyboardEvent('keydown', { keyCode: 20 }));
84+
assert.strictEqual(myp5.keyCode, 20);
85+
});
86+
});
87+
288
suite('keyPressed', function() {
389
test('keyPressed functions on multiple instances must run once', async function() {
490
let sketchFn = function(sketch, resolve, reject) {
@@ -13,7 +99,50 @@ suite('Keyboard Events', function() {
1399
};
14100
let sketches = parallelSketches([sketchFn, sketchFn]); //create two sketches
15101
await sketches.setup; //wait for all sketches to setup
16-
window.dispatchEvent(new KeyboardEvent('keydown')); //dipatch a keyboard event to trigger the keyPressed functions
102+
window.dispatchEvent(new KeyboardEvent('keydown')); //dispatch a keyboard event to trigger the keyPressed functions
103+
sketches.end(); //resolve all sketches by calling their finish functions
104+
let counts = await sketches.result; //get array holding number of times keyPressed was called. Rejected sketches also thrown here
105+
assert.deepEqual(counts, [1, 1]); //check if every keyPressed function was called once
106+
});
107+
});
108+
109+
suite('keyReleased', function() {
110+
test('keyReleased functions on multiple instances must run once', async function() {
111+
let sketchFn = function(sketch, resolve, reject) {
112+
let count = 0;
113+
114+
sketch.keyReleased = function() {
115+
count += 1;
116+
};
117+
118+
sketch.finish = function() {
119+
resolve(count);
120+
};
121+
};
122+
let sketches = parallelSketches([sketchFn, sketchFn]); //create two sketches
123+
await sketches.setup; //wait for all sketches to setup
124+
window.dispatchEvent(new KeyboardEvent('keyup')); //dispatch a keyboard event to trigger the keyReleased functions
125+
sketches.end(); //resolve all sketches by calling their finish functions
126+
let counts = await sketches.result; //get array holding number of times keyPressed was called. Rejected sketches also thrown here
127+
assert.deepEqual(counts, [1, 1]); //check if every keyPressed function was called once
128+
});
129+
});
130+
131+
suite('keyTyped', function() {
132+
test('keyTyped functions on multiple instances must run once', async function() {
133+
let sketchFn = function(sketch, resolve, reject) {
134+
let count = 0;
135+
sketch.keyTyped = function() {
136+
count += 1;
137+
};
138+
139+
sketch.finish = function() {
140+
resolve(count);
141+
};
142+
};
143+
let sketches = parallelSketches([sketchFn, sketchFn]); //create two sketches
144+
await sketches.setup; //wait for all sketches to setup
145+
window.dispatchEvent(new KeyboardEvent('keypress', { key: 'A' })); //dispatch a keyboard event to trigger the keyTyped functions
17146
sketches.end(); //resolve all sketches by calling their finish functions
18147
let counts = await sketches.result; //get array holding number of times keyPressed was called. Rejected sketches also thrown here
19148
assert.deepEqual(counts, [1, 1]); //check if every keyPressed function was called once

0 commit comments

Comments
 (0)