topical media & game development
graphic-processing-algorithm-Ch05-p120-p120.pde / pde
PImage myImage; //define an image object
PImage cpImage; //define a copy image
void setup(){
myImage = loadImage("memorial.jpg"); //load it
cpImage = loadImage("memorial.jpg"); //load the copy
size(myImage.width,myImage.height); //size it to fit the window
image(myImage, 0,0); //display the image
loadPixels(); //load the pixels
}
//**********
void draw(){
}
//********* drag to simulate a paint brush
void mouseDragged(){
for(int y=mouseY-10; y<mouseY+10; y++) //for a 10x10 brush area
for(int x=mouseX-10; x<mouseX+10; x++){
int xx = constrain(x,0,width-1); //do not exceed the screen
int yy = constrain(y,0,height-1);
//read from the copy and update the image
pixels[yy*width+xx] = cpImage.pixels[yy*width+xx]^0x0000FF;
//invert blue
}
//copy the two images
myImage.copy(cpImage, 0,0,width,height,0,0,width,height);
updatePixels(); //update to see the changes
}
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.