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 & HelpSyntax Questions › 'resetting' millis
Page Index Toggle Pages: 1
'resetting' millis (Read 871 times)
'resetting' millis
Jun 3rd, 2009, 2:55am
 
Ok i have a question, can somebody help me out.

I want to restart the following whenever I press the space bar:

import processing.video.*;
int onthouden = 0;
float m;
int numPixels;
int[] vorigFrame;
Capture video;

void setup() {
 size(640, 480);

 video = new Capture(this, width, height, 24);
 numPixels = video.width * video.height;
 vorigFrame = new int[numPixels];
 loadPixels();
}

void draw() {

 if (video.available()) {
   video.read();
   video.loadPixels();
   m= millis();

   println (m);
   if (m <10000){
     int score = 0;
     for (int i = 0; i < numPixels; i++) {
       color currColor = video.pixels[i];
       color prevColor = vorigFrame[i];

       int currR = (currColor >> 16) & 0xFF;
       int currG = (currColor >> 8) & 0xFF;
       int currB = currColor & 0xFF;

       int prevR = (prevColor >> 16) & 0xFF;
       int prevG = (prevColor >> 8) & 0xFF;
       int prevB = prevColor & 0xFF;

       int diffR = abs(currR - prevR);
       int diffG = abs(currG - prevG);
       int diffB = abs(currB - prevB);

       score += diffR + diffG + diffB;

       pixels[i] = color(diffR, diffG, diffB);

       vorigFrame[i] = currColor;

     }
     score= score/10000000;
     onthouden += score;
     println(onthouden);
     updatePixels();
     image(video,0,0);
     rect(0,0,onthouden,20);
     if (score > 0) {
     }
   }
 }
}

void keyPressed() {
 if (key == ' ') {

 }
}

Anyone know how to fix this?

Re: 'resetting' millis
Reply #1 - Jun 3rd, 2009, 5:27am
 
Code:
import processing.video.*;
int onthouden = 0;
float m;
int numPixels;
int[] vorigFrame;
Capture video;

// start time
int start;

void setup() {
size(640, 480);

video = new Capture(this, width, height, 24);
numPixels = video.width * video.height;
vorigFrame = new int[numPixels];
loadPixels();

// set start time
start=millis();
}

void draw() {

if (video.available()) {
video.read();
video.loadPixels();
m= millis()-start;

println (m);
if (m <10000){
int score = 0;
for (int i = 0; i < numPixels; i++) {
color currColor = video.pixels[i];
color prevColor = vorigFrame[i];

int currR = (currColor >> 16) & 0xFF;
int currG = (currColor >> 8) & 0xFF;
int currB = currColor & 0xFF;

int prevR = (prevColor >> 16) & 0xFF;
int prevG = (prevColor >> 8) & 0xFF;
int prevB = prevColor & 0xFF;

int diffR = abs(currR - prevR);
int diffG = abs(currG - prevG);
int diffB = abs(currB - prevB);

score += diffR + diffG + diffB;

pixels[i] = color(diffR, diffG, diffB);

vorigFrame[i] = currColor;

}
score= score/10000000;
onthouden += score;
println(onthouden);
updatePixels();
image(video,0,0);
rect(0,0,onthouden,20);
if (score > 0) {
}
}
}
}

void keyPressed() {
if (key == ' ') {
// reset start time
start=millis();

}
}
Re: 'resetting' millis
Reply #2 - Jun 3rd, 2009, 1:44pm
 
thanks a lot!
Page Index Toggle Pages: 1