How to make a Countdown?
in
Contributed Library Questions
•
8 months ago
Ok, I don't know why, but I can't find a solution for my problem. Can someone help me here? Maybe it's so simple, but I don't get it.
I'm making a Videotracking with the JMyron example "Myron_CameraAsMouse" and I like it, but what I want to change, is that circle don't stay on same Position, when the movement is over. It should move to the point 0,0. But that is not my real problem.
My Problem is that this shouldend happen immediatelly. I tried to make something like a countdown for this thing. It means, when the movement stop, it should start a countdown for e.g. 3 seconds and than the circle should move to the point 0,0. All I made doesn't works. So I only post the JMyron Version with the 0,0 movement.
- import JMyron.*;
- JMyron m;//a camera object
- //variables to maintain the floating green circle
- float objx = 160;
- float objy = 120;
- float objdestx = 160;
- float objdesty = 120;
- void setup() {
- size(320, 240);
- m = new JMyron();//make a new instance of the object
- m.start(width, height);//start a capture at 320x240
- m.trackColor(255, 255, 255, 256*3-100);//track white
- m.update();
- m.adaptivity(10);
- m.adapt();// immediately take a snapshot of the background for differencing
- println("Myron " + m.version());
- rectMode(CENTER);
- noStroke();
- }
- void draw() {
- m.update();//update the camera view
- drawCamera();
- int[][] centers = m.globCenters();//get the center points
- //draw all the dots while calculating the average.
- float avX=0;
- float avY=0;
- for (int i=0;i<centers.length;i++) {
- fill(80);
- rect(centers[i][0], centers[i][1], 5, 5);
- avX += centers[i][0];
- avY += centers[i][1];
- }
- if (centers.length-1>0) {
- avX/=centers.length-1;
- avY/=centers.length-1;
- }
- ////////////THIS IS WHAT I ADD!!!!!!
- if (centers.length == 0) {
- objdestx = 0;
- objdesty = 0;
- }
- //draw the average of all the points in red.
- fill(255, 0, 0);
- rect(avX, avY, 5, 5);
- //update the location of the thing on the screen.
- if (!(avX==0&&avY==0)&¢ers.length>0) {
- objdestx = avX;
- objdesty = avY;
- }
- objx += (objdestx-objx)/10.0f;
- objy += (objdesty-objy)/10.0f;
- fill(30, 100, 0);
- ellipseMode(CENTER);
- ellipse(objx, objy, 30, 30);
- }
- void drawCamera() {
- int[] img = m.differenceImage(); //get the normal image of the camera
- loadPixels();
- for (int i=0;i<width*height;i++) { //loop through all the pixels
- pixels[i] = img[i]; //draw each pixel to the screen
- }
- updatePixels();
- }
- void mousePressed() {
- m.settings();//click the window to get the settings
- }
- public void stop() {
- m.stop();//stop the object
- super.stop();
- }
Regards
Patrick
1