"""
Image Mask

Move the mouse to reveal the image through the dynamic mask.
"""

maskShader = None
srcImage = None
maskImage = None


def setup():
    global maskShader, srcImage, maskImage
    size(640, 360, P2D)
    srcImage = loadImage("leaves.jpg")
    maskImage = createGraphics(srcImage.width, srcImage.height, P2D)
    maskImage.noSmooth()
    maskShader = loadShader("mask.glsl")
    maskShader.set("mask", maskImage)
    background(255)


def draw():
    maskImage.beginDraw()
    maskImage.background(0)
    if mouseX != 0 and mouseY != 0:
        maskImage.noStroke()
        maskImage.fill(255, 0, 0)
        maskImage.ellipse(mouseX, mouseY, 50, 50)
    maskImage.endDraw()
    shader(maskShader)
    image(srcImage, 0, 0, width, height)
