Hi all,
i am trying to code an Poster wich takes the color out of the webcam and draws shaps on the canvas. This works finde, but now i want to it to only draw a certain amount of shapes on the canvas, like 50 or so and the old ones should disapper. I have worked it around with drawing a background wich has an opaccity of 10. But this does not look good… Maybe the last 50 shapes can be drawn by an array or so…
Sorry for my bad englisch …
maybe you can help me
import processing.pdf.*;
import processing.video.*;
Capture video;
PGraphics pg;
//Arrays for the color RGB Value
int[] red = new int[4];
int[] blue = new int[4];
int[] green = new int[4];
//--------------SetUp------------------------------------------------------//
void setup() {
size(595, 842);
background(255);
smooth(8);
//Initialize Capture object via Constructor
video = new Capture(this, 640, 480);
video.start();
//Begin Record of the PDF
beginRecord(PDF, "test.pdf");
//creat Pgraphics
pg = createGraphics(595, 842);
}
//--------------Draw--------------------------------------------------------//
void draw() {
// get 3 colors from the Webcam feed
color c1 = video.get(329, 380);
color c2 = video.get(330, 380);
color c3 = video.get(331, 380);
//RedValues
//Get Int Value of Red
int redValue1 = int(red(c1));
int redValue2 = int(red(c2));
int redValue3 = int(red(c3));
//safe redValue in Array
red[0] = redValue1;
red[1] = redValue2;
red[2] = redValue3;
//BlueValues
//Get Int Value of Blue
int blueValue1 = int(blue(c1));
int blueValue2 = int(blue(c2));
int blueValue3 = int(blue(c3));
//safe blueValue
blue[0] = blueValue1;
blue[1] = blueValue2;
blue[2] = blueValue3;
//GreenValues
//Get Int Value of Green
int greenValue1 = int(green(c1));
int greenValue2 = int(green(c2));
int greenValue3 = int(green(c3));
//safe greenvalue
green[0] = greenValue1;
green[1] = greenValue2;
green[2] = greenValue3;
//calculate Brightness of Pixels and generate a Size based on th ebrightness
float pixBright1 = (redValue1*0.33 + greenValue1*0.5 + blueValue1*0.16);
int shapeSize1 = int(pixBright1);
float pixBright2 = (redValue3*0.33 + greenValue3*0.5 + blueValue3*0.16);
int shapeSize2 = int(pixBright2);
//Calculate the avarage color of the pixels
int avgGreen = (greenValue1 + greenValue2 + greenValue3)/3 ;
int avgRed = (redValue1 + redValue2 + redValue3)/3 ;
int avgBlue = (blueValue1 + blueValue2 + blueValue3)/3 ;
//random range
int ranRange = 11;
//Calculate the Shapes and their sizes
int shapeAmount = 20;
for (int i = 1; i < shapeAmount; i++) {
pg.beginDraw();
pg.noStroke();
pg.fill(avgRed, avgGreen, avgBlue);
pg.rect(avgRed*random(ranRange)*i, avgBlue*random(ranRange)*i, shapeSize1, shapeSize2, random(50), random(50), random(50), random(50));
pg.fill(avgRed, avgGreen, avgBlue);
pg.ellipse(avgRed*random(ranRange)*i, avgBlue*random(ranRange)*i, shapeSize1, shapeSize1);
pg.fill(255, 10);
pg.rect(0, 0, 595,842);
pg.noFill();
pg.stroke(avgRed, avgGreen, avgBlue);
pg.rect(avgRed*random(ranRange)*i, avgBlue*random(ranRange)*i, shapeSize1, shapeSize2, random(50), random(50), random(50), random(50));
pg.stroke(avgRed, avgGreen, avgBlue);
pg.ellipse(avgRed*random(ranRange)*i, avgBlue*random(ranRange)*i, shapeSize1, shapeSize1);
pg.endDraw();
}
//Draw the PGraphics
image(pg, 0, 0);
//Safe a PDF on mouseclick
if (mousePressed==true) {
endRecord();
}
//TestCam
/*
image(video, 0, 0);
fill(255);
rect(325,380,5,5);
rect(330,380,5,5);
rect(335,380,5,5);
*/
}
//--------------Function-----------------------------------------------------//
// An event for when a new frame is available
void captureEvent(Capture video) {
// Read the image from the camera.
video.read();
}