Skip to content

Commit a11e2bc

Browse files
committed
add createGraphics test for mask
1 parent 7d0e9c2 commit a11e2bc

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

test/unit/image/p5.Image.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,25 @@ suite('p5.Image', function() {
119119
}
120120
});
121121

122+
test('it should mask images from createGraphics', function() {
123+
myp5.createCanvas(10,10);
124+
myp5.pixelDensity(2);
125+
let img = myp5.createGraphics(10,10);
126+
img.rect(0,0,10,10);
127+
img.background(0);
128+
let mask = createGraphics(10,10);
129+
mask.rect(0,0,5,5);
130+
let masked = img.get();
131+
masked.mask( mask.get() );
132+
133+
for (let i = 0; i < masked.width; i++) {
134+
for (let j = 0; j < masked.height; j++) {
135+
let alpha = i < 5 && j < 5 ? 255 : 0;
136+
assert.strictEqual(masked.get(i, j)[3], alpha);
137+
}
138+
}
139+
});
140+
122141
test('it should mask the animated gif image', function() {
123142
const imagePath = 'unit/assets/nyan_cat.gif';
124143
return new Promise(function(resolve, reject) {

0 commit comments

Comments
 (0)