/* * In this sketch, we use the luminosity formula to compute grayscale, but * then we adjust the image to be a gradient that transitions from the * original color to the full grayscale. */ // Can either load an image stored locally, as follows: // PImage slu = loadImage("campus4.jpg"); // Or can load an image from a URL PImage slu = loadImage("http://business.slu.edu/uploads/2012/11/08/slu-homepage-campus4.jpg"); int w = slu.width; int h = slu.height; for (int x=0; x < w; x++) { float pct = float(x)/(w-1); for (int y=0; y < h; y++) { color c = slu.get(x,y); float gray = (0.21 * red(c) + 0.72 * green(c) + 0.07 * blue(c)); float r = gray * pct + red(c)*(1-pct); float g = gray * pct + green(c)*(1-pct); float b = gray * pct + blue(c)*(1-pct); color replace = color(r,g,b); slu.set(x,y,replace); } } // time to display it size(w,h); image(slu,0,0);