/* * A program that shows individual color plates. * * User can switch by typing 'r', 'g', or 'b'. */ PImage slu, sluRed, sluGreen, sluBlue, current; void setup() { size(408,300); // take advantage of our knowledge of the size // slu = loadImage("http://business.slu.edu/uploads/2012/11/08/slu-homepage-campus4.jpg"); slu = loadImage("campus4.jpg"); // load local copy int w = slu.width; int h = slu.height; // let's precompute all three color plates sluRed = createImage(w, h, RGB); sluGreen = createImage(w, h, RGB); sluBlue = createImage(w, h, RGB); for (int x=0; x < w; x++) { for (int y=0; y < h; y++) { color c = slu.get(x, y); sluRed.set(x, y, color(red(c), 0, 0)); sluGreen.set(x, y, color(0, green(c), 0)); sluBlue.set(x, y, color(0, 0, blue(c))); } } current = slu; // the original } void draw() { image(current, 0, 0); } void keyPressed() { if (key == 'r') { current = sluRed; } else if (key == 'g') { current = sluGreen; } else if (key == 'b') { current = sluBlue; } else { current = slu; } }