// probably threw this in wrong forum, i realize now... its not 3d, but i guess it has to do with it
As part of a school project, me and my group have to build in proces an application. We decided to make a draw application that you can control with your finger in front of the webcam. Now my problem is the refresh. The webcam (moving at 60 fps) refreshes, but when it draws, it puts it on top of the line just drawn, so you are looking at zip again. I want it so the lines stay on top of the proces instead getting in the refresh rate of the webcam. (if you remove the webcam line, the lines will be there)
Anybody can help me out?
Code:
int pixel, pixelx, pixely, roodx, roody, nieuwx, nieuwy;
int diameter = 10;
int d = 999;
color kleur;
float roodtemp, rood;
PImage tekening;
import processing.video.*;
Capture myCapture;
int frameRateSet = 10;
void setup() {
size(320, 240);
// frame size
frameRate(frameRateSet);
// framrate
myCapture = new Capture(this, width, height, Capture.list()[0]);
// update van de webcam
myCapture.frameRate(60);
// refresh framrate
tekening = createImage(width, height, RGB);
}
void draw() {
if (myCapture.available() == true) {
myCapture.read();
image(myCapture, 0, 0);
for (int i = 0; i < myCapture.pixels.length; i ++ ) {
pixelx = i%width;
pixely = (i-pixelx)/width;
kleur = get(pixelx, pixely);
//hier zoekt hij alleen naar alle pixels en defineert ie de kleur
if (colorDist(myCapture.pixels[i], color (0,0,255)) < d) {
d = colorDist(myCapture.pixels[i], color (0,0,255));
pixel = i;
roodx = pixelx;
roody = pixely;
}
// hier bepaald ie de meest groene pixel
}
fill(255,255,255,50);
ellipse(roodx,roody,diameter,diameter);
d = 999;
line(roodx,roody,nieuwx,nieuwy);
strokeWeight(4);
nieuwx = roodx;
nieuwy = roody;
}
}
void captureEvent(Capture myCapture) {
}
void keyPressed() { // voor rode kleur
if (key == 'r' || key == 'R') {
fill (255,0,0,50);
line(roodx,roody,nieuwx,nieuwy);
stroke(255,0,0);
strokeWeight(4);
}
if (key == 'b' || key == 'B') { // voor blauwe kleur
fill (0,0,255,50);
line(roodx,roody,nieuwx,nieuwy);
stroke(0,0,255);
strokeWeight(4);
}
if (key == 'g' || key == 'G') { // voor groene kleur
fill (0,255,0,50);
line(roodx,roody,nieuwx,nieuwy);
stroke(0,255,0);
strokeWeight(4);
}
}
int colorDist(color a, color b){
int c = (int) dist(red(a), green(a), blue(a), red(b), green(b), blue(b));
return c;
// de kleur definitie
i did mess arround with it, (changed pixel collors to make sure i could draw) but every time i change or think i figured it out, it wont work.