@@ -50,7 +50,7 @@ suite('p5.Image', function() {
50
50
} ) ;
51
51
} ) ;
52
52
53
- suite ( 'p5.Image.prototype.mask' , function ( ) {
53
+ suite . only ( 'p5.Image.prototype.mask' , function ( ) {
54
54
for ( const density of [ 1 , 2 ] ) {
55
55
test ( `it should mask the image at pixel density ${ density } ` , function ( ) {
56
56
let img = myp5 . createImage ( 10 , 10 ) ;
@@ -86,6 +86,39 @@ suite('p5.Image', function() {
86
86
} ) ;
87
87
}
88
88
89
+ test ( 'it should mask images of different density' , function ( ) {
90
+ let img = myp5 . createImage ( 10 , 10 ) ;
91
+ img . pixelDensity ( 1 ) ;
92
+ img . loadPixels ( ) ;
93
+ for ( let i = 0 ; i < img . height ; i ++ ) {
94
+ for ( let j = 0 ; j < img . width ; j ++ ) {
95
+ let alpha = i < 5 ? 255 : 0 ;
96
+ img . set ( i , j , myp5 . color ( 0 , 0 , 0 , alpha ) ) ;
97
+ }
98
+ }
99
+ img . updatePixels ( ) ;
100
+
101
+ let mask = myp5 . createImage ( 20 , 20 ) ;
102
+ mask . loadPixels ( ) ;
103
+ for ( let i = 0 ; i < mask . width ; i ++ ) {
104
+ for ( let j = 0 ; j < mask . height ; j ++ ) {
105
+ let alpha = j < 10 ? 255 : 0 ;
106
+ mask . set ( i , j , myp5 . color ( 0 , 0 , 0 , alpha ) ) ;
107
+ }
108
+ }
109
+ mask . updatePixels ( ) ;
110
+ mask . pixelDensity ( 2 ) ;
111
+
112
+ img . mask ( mask ) ;
113
+ img . loadPixels ( ) ;
114
+ for ( let i = 0 ; i < img . width ; i ++ ) {
115
+ for ( let j = 0 ; j < img . height ; j ++ ) {
116
+ let alpha = i < 5 && j < 5 ? 255 : 0 ;
117
+ assert . strictEqual ( img . get ( i , j ) [ 3 ] , alpha ) ;
118
+ }
119
+ }
120
+ } ) ;
121
+
89
122
test ( 'it should mask the animated gif image' , function ( ) {
90
123
const imagePath = 'unit/assets/nyan_cat.gif' ;
91
124
return new Promise ( function ( resolve , reject ) {
0 commit comments