PImage[] imgs = new PImage[4]; // loaded images PImage img; // current image int curImg = 0; // current image void setup() { size(500,400); smooth(); rectMode(CENTER); for(int i = 0; i < imgs.length; i ++) imgs[i] = loadImage("img-"+(i+1)+".jpg"); img = imgs[curImg]; textFont(loadFont("Helvetica-24.vlw")); } void draw() { background(0); image(img,0,0); // put it at the corner (doesn't fill whole window) // Get the moused-over pixel and extract its r,g,b components color pixel = get(mouseX,mouseY); float r=red(pixel), g=green(pixel), b=blue(pixel); // Display the color on the side stroke(200); strokeWeight(2); fill(r,g,b); rect(img.width+50,height/5,50,50); fill(r,0,0); rect(img.width+50,2*height/5,50,50); fill(0,g,0); rect(img.width+50,3*height/5,50,50); fill(0,0,b); rect(img.width+50,4*height/5,50,50); // write the pixel values fill(200); text("pixel", img.width+100,height/5+10); text("r = " + int(r), img.width+100,2*height/5+10); text("g = " + int(g), img.width+100,3*height/5+10); text("b = " + int(b), img.width+100,4*height/5+10); } void keyPressed() { if(key == ' ') { curImg = (curImg+1)%imgs.length; img = imgs[curImg]; } } // START NO NOTES // code used to capture screenshots void keyReleased() { if(key == '`' && !online) save("sketch.png"); }