Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Color exploration using a pixel mirror.
/*
Color Exploration by Brett Peterson 2012
Pixel mirror Processing sketch that explores the changes
in hue, brightness and saturation. Click the mouse to change which
value is reflected correctly from the webcam and which 2 will be held constant.
Moving the mouse along the Y-axis will change the other 2 values
(not the currently-reflected value)
*/
import processing.video.*;
Capture cam;
PImage displayImg;
color pixColor;
int clicks = 0;
float other = 0;
void setup(){
background(0);
size(640, 480);
//Use HSB color
colorMode(HSB, 100);
// Start the webcam
cam = new Capture(this, 640, 480);
cam.start();
displayImg = new PImage(640, 480);
}
void draw(){
// Get and map the y-coordinate of mouse
other = map(mouseY, 0, height, 0, 100);
// loop through pixel array of camera and pull each pixel color
if (cam.available()) {
cam.read();
// +=10 makes gaps in the pixels for an interesting look
for (int x = 0; x < cam.width; x+=10) {
for (int y = 0; y < cam.height; y+=10) {
int camIndex = x + y * cam.width;
int disIndex = (width -x - 1) + y * cam.width;
color pixColor = cam.pixels[disIndex];
displayImg.pixels[disIndex] = cam.pixels[camIndex];
// Check clicks and cycle through the display of hue,
// brightness and saturation
int sel = clicks % 3;
switch(sel) {
case 0:
fill(hue(pixColor), other, other);
break;
case 1:
fill(other, brightness(pixColor), other);
break;
case 2:
fill(other, other, saturation(pixColor));
break;
}
noStroke();
rect(x, y, 5, 5);
}
}
}
// displayImg.updatePixels();
// image(displayImg, 0, 0);
}
void mousePressed(){
clicks++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.