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 & HelpPrograms › animate with millis()
Page Index Toggle Pages: 1
animate with millis() (Read 1278 times)
animate with millis()
Mar 11th, 2008, 12:06pm
 
hi,
i try to code an oldschool filmcount with the use of the millis() function. the problem is that the numbers for the count are displayed in completely different intervals.
is it because the programm is too slow, or did i make some mistake in my code ???

thanx for every answer

import processing.candy.*;
import processing.xml.*;

SVG[] numbers;
String svgName;

int x = 0;
int y,y1;

int fileName = 1;
int letterBox = 67;
int svgCount = 9;


void setup(){
 size(1024,768);
 //frameRate(100);
 smooth();
 numbers = new SVG[10];
 for(int i=0;i<10;i++){
   svgName = "nr" + fileName + ".svg";
   fileName++;
   numbers[i] = new SVG(this,svgName);
   numbers[i].drawMode(CENTER);
   numbers[i].ignoreStyles();
 }
   
}

void draw(){
 smooth();
 background(190);  
 
 y = 0;
 y1 = height - letterBox;
 
 noStroke();
 fill(0);
 rectMode(CORNER);
 rect(x,y,width,letterBox);
 rect(x,y1,width,letterBox);

 
 noFill();
 stroke(255);
 strokeWeight(10);
 ellipse(width/2,height/2,550,550);
 strokeWeight(4);
 ellipse(width/2,height/2,500,500);
 
 
 noStroke();
 fill(255);  
 numbers[svgCount].draw(width/2,height/2);
 int s = millis();
 if(s%1000 == 0){
   svgCount--;
 }
   
 stroke(0);
 strokeWeight(1);
 line(0,height/2,width,height/2);
 line(width/2,0,width/2,height);
 
}
Re: animate with millis()
Reply #1 - Mar 11th, 2008, 2:13pm
 
millis() might just not return values as 1000, if it hits on 999 or 1001 the counter wont decrease.
you should use some other method to check for a timehit..


void setup()
{
 startTime = millis();
}


void draw()
{
 timer = millis() - startTime;
 if( timer >= 1000 )
 {
   count --;

   startTime = millis();
 }
}

that should work
Re: animate with millis()
Reply #2 - Mar 11th, 2008, 2:30pm
 
that works great
thanks a lot
Page Index Toggle Pages: 1