@@ -51,36 +51,40 @@ suite('p5.Image', function() {
51
51
} ) ;
52
52
53
53
suite ( 'p5.Image.prototype.mask' , function ( ) {
54
- test ( 'it should mask the image' , function ( ) {
55
- let img = myp5 . createImage ( 10 , 10 ) ;
56
- img . loadPixels ( ) ;
57
- for ( let i = 0 ; i < img . height ; i ++ ) {
58
- for ( let j = 0 ; j < img . width ; j ++ ) {
59
- let alpha = i < 5 ? 255 : 0 ;
60
- img . set ( i , j , myp5 . color ( 0 , 0 , 0 , alpha ) ) ;
54
+ for ( const density of [ 1 , 2 ] ) {
55
+ test ( `it should mask the image at pixel density ${ density } ` , function ( ) {
56
+ let img = myp5 . createImage ( 10 , 10 ) ;
57
+ img . pixelDensity ( density ) ;
58
+ img . loadPixels ( ) ;
59
+ for ( let i = 0 ; i < img . height ; i ++ ) {
60
+ for ( let j = 0 ; j < img . width ; j ++ ) {
61
+ let alpha = i < 5 ? 255 : 0 ;
62
+ img . set ( i , j , myp5 . color ( 0 , 0 , 0 , alpha ) ) ;
63
+ }
61
64
}
62
- }
63
- img . updatePixels ( ) ;
65
+ img . updatePixels ( ) ;
64
66
65
- let mask = myp5 . createImage ( 10 , 10 ) ;
66
- mask . loadPixels ( ) ;
67
- for ( let i = 0 ; i < mask . width ; i ++ ) {
68
- for ( let j = 0 ; j < mask . height ; j ++ ) {
69
- let alpha = j < 5 ? 255 : 0 ;
70
- mask . set ( i , j , myp5 . color ( 0 , 0 , 0 , alpha ) ) ;
67
+ let mask = myp5 . createImage ( 10 , 10 ) ;
68
+ mask . pixelDensity ( density ) ;
69
+ mask . loadPixels ( ) ;
70
+ for ( let i = 0 ; i < mask . width ; i ++ ) {
71
+ for ( let j = 0 ; j < mask . height ; j ++ ) {
72
+ let alpha = j < 5 ? 255 : 0 ;
73
+ mask . set ( i , j , myp5 . color ( 0 , 0 , 0 , alpha ) ) ;
74
+ }
71
75
}
72
- }
73
- mask . updatePixels ( ) ;
76
+ mask . updatePixels ( ) ;
74
77
75
- img . mask ( mask ) ;
76
- img . loadPixels ( ) ;
77
- for ( let i = 0 ; i < img . width ; i ++ ) {
78
- for ( let j = 0 ; j < img . height ; j ++ ) {
79
- let alpha = i < 5 && j < 5 ? 255 : 0 ;
80
- assert . strictEqual ( img . get ( i , j ) [ 3 ] , alpha ) ;
78
+ img . mask ( mask ) ;
79
+ img . loadPixels ( ) ;
80
+ for ( let i = 0 ; i < img . width ; i ++ ) {
81
+ for ( let j = 0 ; j < img . height ; j ++ ) {
82
+ let alpha = i < 5 && j < 5 ? 255 : 0 ;
83
+ assert . strictEqual ( img . get ( i , j ) [ 3 ] , alpha ) ;
84
+ }
81
85
}
82
- }
83
- } ) ;
86
+ } ) ;
87
+ }
84
88
85
89
test ( 'it should mask the animated gif image' , function ( ) {
86
90
const imagePath = 'unit/assets/nyan_cat.gif' ;
0 commit comments