// Learning Processing // Daniel Shiffman //
http://www.learningprocessing.com  // Example 15-9: Adjusting
image brightness based on pixel location (Flashlight effect)
PImage img;  void setup() {   img = loadImage( "sunflower.jpg"
);  void draw() {   // We must also call loadPixels() on the
PImage since we are going to read its pixels.  img.loadPixels();
for (int y = 0; y < img.height; y++ ) {       // Calculate the
1D pixel location       int loc = x + y*img.width;       // Get
the R,G,B values from image       float r = red
(img.pixels[loc]);       float g = green (img.pixels[loc]);
float b = blue (img.pixels[loc]);       // Calculate an amount
to change brightness       // based on proximity to the mouse
float distance = dist(x,y,mouseX,mouseY);       // The closer
the pixel is to the mouse, the lower the value of "distance"
// We want closer pixels to be brighter, however, so we invert
the value with the formula: adjustBrightness = (50-distance)/50
// Pixels with a distance