Skip to content

Instantly share code, notes, and snippets.

@jkwok91
Created March 31, 2014 06:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkwok91/a26a25cdab74153cc950 to your computer and use it in GitHub Desktop.
Save jkwok91/a26a25cdab74153cc950 to your computer and use it in GitHub Desktop.
in which I load an image into my sketch
/*
loading an image into my processing sketch
*/
PImage popcorn;
color yellow = color(255, 255, 0);
int radius;
void setup() {
size(480, 320);
radius = 50;
popcorn = loadImage("DSC_0199.JPG");
image(popcorn, 0, 0, 600, 400);
}
void draw() {
image(popcorn, 0, 0, 600, 400);
mask();
fill(yellow);
text("you can click to lift the mask!",mouseX,mouseY+2*radius);
}
void mousePressed() {
// lifts the mask
image(popcorn, 0, 0, 600, 400);
noLoop();
}
void mouseReleased() {
loop();
}
void mask() {
// create mask except where mouse is
loadPixels();
// square of sidelength 2*radius centered around mouse
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
if ((i < mouseX-radius || i > mouseX+radius) || (j < mouseY-radius || j > mouseY+radius)) {
pixels[j*width+i] = color(0);
}
}
}
updatePixels();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment