We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › uncovering an image
Page Index Toggle Pages: 1
uncovering an image (Read 579 times)
uncovering an image
Feb 7th, 2009, 5:25pm
 
Not necessarily looking for exact code, although not opposed to it, but how would you go about making a program that loads a picture to the background and then covers said image with a strait fill color of say gray, and when the mouse hovers over the picture it uncovers the part of the picture under it with a square like eraser type tool.  As you move the mouse over the picture, the parts you have uncovered stay uncovered.  Sort of like in paint when your erasing something, only under all he gray is a picture that does not get erased with it.
Re: uncovering an image
Reply #1 - Feb 8th, 2009, 6:38am
 
You can use an alpha mask
http://processing.org/reference/PImage_mask_.html

with PGraphics
http://processing.org/reference/PGraphics.html

Draw (in black and white) your mask onto a PGraphics object and use that as a mask for your image.

I do have a working example if you have trouble.
Re: uncovering an image
Reply #2 - Feb 9th, 2009, 11:29pm
 
Having a little trouble getting it to work, if its not a big deal could i see your working example?

Thanks in advance
Re: uncovering an image
Reply #3 - Feb 10th, 2009, 7:17am
 
Not a problem.

Code:

PImage img;
PGraphics maskg;

void setup() {
size(200,200);
img = loadImage("test.jpg");
maskg = createGraphics(img.width, img.height, P2D);
}

void mouseMoved() {
maskg.beginDraw();//do not call background here or it will only show one box
maskg.noStroke();
maskg.fill(255);
maskg.rect(mouseX-10,mouseY-10,20,20);
maskg.endDraw();
}

void draw() {
background(0);
img.mask(maskg);
image(img, 0, 0);
}
Re: uncovering an image
Reply #4 - Feb 10th, 2009, 1:19pm
 
See also causing pixels to fall (from same author).
Re: uncovering an image
Reply #5 - Feb 10th, 2009, 3:24pm
 
Ok thanks a ton guys.
Page Index Toggle Pages: 1