-
-
Save jkwok91/a26a25cdab74153cc950 to your computer and use it in GitHub Desktop.
in which I load an image into my sketch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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