Dynamic Mask // ver C

_20080522_dynamicMask_c
run the sketch—view the code

How do you use it?
Move the mouse around to reposition the mask window. Click the mouse to switch the mask mode.

What is it?
The .mask method requires either (A) the image that will be masked and a grayscale image for the mask itself, or (B) the image that will be masked and an integer array containing the color values for the mask (this is essentially an image for the mask but it hangs out in the RAM instead of being read from a file). This sketch demonstrates how to make a dynamic mask with both techniques.

(A) Before the photo is displayed, a separate grayscale image is loaded into the program to be used as the mask. The colors in this image’s pixels[] array are then modified based on the position of the mouse. Finally, the modified grayscale image is applied to the background image with the .mask method. Because this happens in each cycle of the draw() loop, the mask functions interactively.

(B) maskArray is an array containing the same number of integers as there are pixels in the background image. All values in this array are either 0, or 255 (ints btwn 0 and 255 can also be used). Before the photo is displayed, the values in the array are modified based on the position of the mouse. The array is then applied to the image using the .mask method which interprets its values as 0=black=opaque and 255=white=transparent.

Comments are closed.