We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › Drawing Program in Processing
Page Index Toggle Pages: 1
Drawing Program in Processing (Read 817 times)
Drawing Program in Processing
Jul 1st, 2009, 2:03am
 
// 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.
Re: Drawing Program in Processing
Reply #1 - Jul 3rd, 2009, 2:06am
 
you could draw your lines in a separate PGraphics
Re: Drawing Program in Processing
Reply #2 - Jul 8th, 2009, 2:33pm
 
actually what i did was expending the view screen in the end to the same size next to the webcam image and moved the pixels by the ammount of space (the 320 pxls width), so you see yourself drawing, but in the screen next to it, you are drawing, the solution was a little bit more easier then creating a PGraphic which you suggested, but if i had it created, i would have had problems with clearing the image i think. Not totally sure. Anyway, i ll post the code as soon as its approved tomorrow

Thanks for your input

Page Index Toggle Pages: 1