Assignment 11: Photobooth

This week, I tried to make a Photobooth sort of program, in which you can see yourself in a variety of colored filters and save an image with the filter you like best. When the program is run, at the top of the screen there are a few colored boxes — hovering the mouse over each of those boxes produces a differently colored filter. On clicking anywhere on the screen, you are able to save the image into a folder on my computer.

These are the different filters in the program:

(Note: the screen is not lined this heavily when it actually runs, I would think these lines are there because of the screen recording.)

The best part of doing this was for me to play around the with the colors and come up with the different filters. The hardest part for me was probably to solve the saving image part of the program, which I don’t think I have still fully solved. Currently, because of the “save()” function, I am able to download a picture from the program and save it to a folder on my computer, but I would love to explore more interesting and efficient ways to do that. Perhaps something along the lines of Mari’s Etch-a-Sketch recording mechanism would be suitable.

For the future, apart from the saving image issue, I would also like to incorporate more complex filters. This current program is quite simple and relies mostly on an alteration of RGB values, but I would love to further incorporate tracking color mechanisms and such.

Here is the code:

import processing.video.*;
Capture video;
int shapesize = 30;
color c;

void setup() {
 size(720, 480);
 video = new Capture(this, 720, 480, 30);
 video.start();
 


 c=color(255, 0, 0);
}

void draw() {
 if (video.available()) {
 video.read();
 }
 
 background(0);
 loadPixels();
 video.loadPixels();

 //for (int i=0; i<pixels.length; i++) {
 // pixels[i]= color(random(255));
 //}
 if (mouseX < 50 && mouseY < 50) {
 for (int y =0; y<height; y++) {
 for ( int x=0; x<width; x++) {
 int loc = x+y*width;
 float r = red(video.pixels[loc]);
 float g = green(video.pixels[loc]);
 float b = blue(video.pixels[loc]);

 //float brightness = ((float)mouseX/width)*8;
 float brightness = 5;
 r*=brightness;
 g*=brightness;
 b*=brightness;

 if (x%2==0)
 pixels[loc]=color(r, g, b);
 else
 pixels[loc] = color(0);
 }
 }
 } else if (mouseX < 100 && mouseX > 50 && mouseY < 50) {

 for (int y =0; y<height; y++) {
 for ( int x=0; x<width; x++) {
 int loc = x+y*width;
 float r = red(video.pixels[loc]);
 float g = green(video.pixels[loc]);
 float b = blue(video.pixels[loc]);

 r *= 0.2989;
 g *= 0.5870;
 b *= 0.1140;

 if (x%2==0)
 pixels[loc]=color(r, g, b);
 else
 pixels[loc] = color(0);
 }
 }

 } else if (mouseX < 150 && mouseX > 100 && mouseY < 50) {

 for (int y =0; y<height; y++) {
 for ( int x=0; x<width; x++) {
 int loc = x+y*width;
 float r = red(video.pixels[loc]);
 float g = green(video.pixels[loc]);
 float b = blue(video.pixels[loc]);

 float intensity = (float)(height - y) / (float)height;
 r *= intensity;
 g *= intensity;
 b *= intensity;

 if (x%2==0)
 pixels[loc]=color(r, g, b);
 else
 pixels[loc] = color(0);
 }
 }
 }else if (mouseX < 200 && mouseX > 150 && mouseY < 50) {

 for (int y =0; y<height; y++) {
 for ( int x=0; x<width; x++) {
 int loc = x+y*width;
 float r = red(video.pixels[loc]);
 float g = green(video.pixels[loc]);
 float b = blue(video.pixels[loc]);

 r *= 1;
 g *= 3;
 b *= 0.1140;

 if (x%2==0)
 pixels[loc]=color(r, g, b);
 else
 pixels[loc] = color(0);
 }
 }
 }
 else if (mouseX < 250 && mouseX > 200 && mouseY < 50) {

 for (int y =0; y<height; y++) {
 for ( int x=0; x<width; x++) {
 int loc = x+y*width;
 float r = red(video.pixels[loc]);
 float g = green(video.pixels[loc]);
 float b = blue(video.pixels[loc]);

 r *= 0.2989;
 g *= 0.5870;
 b *= 0.1140;

 if (x%2==0)
 pixels[loc]=color(r+ g + b);
 else
 pixels[loc] = color(0);
 }
 }
 }
 else if (mouseX < 300 && mouseX > 250 && mouseY < 50) {

 for (int y =0; y<height; y++) {
 for ( int x=0; x<width; x++) {
 int loc = x+y*width;
 float r = red(video.pixels[loc]);
 float g = green(video.pixels[loc]);
 float b = blue(video.pixels[loc]);

 r *= 0.2989;
 g *= 0.5870;
 b *= 2;

 if (x%2==0)
 pixels[loc]=color(r, g, b);
 else
 pixels[loc] = color(0);
 }
 }
 }else if (mouseX < 350 && mouseX > 300 && mouseY < 50) {

 for (int y =0; y<height; y++) {
 for ( int x=0; x<width; x++) {
 int loc = x+y*width;
 float r = red(video.pixels[loc]);
 float g = green(video.pixels[loc]);
 float b = blue(video.pixels[loc]);

 r *= 1;
 g *= 0.5;
 b *= 2;

 if (x%2==0)
 pixels[loc]=color(r, g, b);
 else
 pixels[loc] = color(0);
 }
 }
 } else {
 
 for (int y =0; y<height; y++) {
 for ( int x=0; x<width; x++) {
 int loc = x+y*width;
 float r = red(video.pixels[loc]);
 float g = green(video.pixels[loc]);
 float b = blue(video.pixels[loc]);

 //float brightness = ((float)mouseX/width)*8;
 float brightness = 1;
 r*=brightness;
 g*=brightness;
 b*=brightness;

 if (x%2==0)
 pixels[loc]=color(r, g, b);
 else
 pixels[loc] =color(0);
 }
 }
 
 }
 updatePixels();
 video.updatePixels();
 fill(255, 0, 0);
 rect(0, 0, 50, 50);
 fill(0, 255, 0);
 rect(50, 0, 50, 50);
 fill(0);
 rect(100, 0, 50, 50);
 fill(255,255,0);
 rect(150, 0, 50, 50);
 fill(255);
 rect(200, 0, 50, 50);
 fill(0, 0, 255);
 rect(250, 0, 50, 50);
 fill(255,192,203);
 rect(300, 0, 50, 50);
 
 
 }

void mouseClicked(){
 save("image.png"); 
}