topical media & game development

talk show tell print

graphic-processing-algorithm-Ch05-p119-p119.pde / pde



  PImage myImage; //define an image object
  void setup(){
    myImage = loadImage("memorial.jpg"); //load it
    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 20x20 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);
        pixels[yy*width+xx] = pixels[yy*width+xx]^0x0000FF;
      } //invert blue
    updatePixels();
    //update to see the changes
  }
  //********** Save just in case it is needed
  void keyPressed(){
    save("memorial_inverted.jpg");
  }
  


(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.