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 › Smooth Seconds hand...
Page Index Toggle Pages: 1
Smooth Seconds hand... (Read 863 times)
Smooth Seconds hand...
Jul 27th, 2005, 5:46am
 
  I'm making a Clock class (Yes, it's another class for a clock..) and I was wondering if there was any way to get the seconds hand to move smoothly instead of jerking forward with every second. I'm sure there's a work-around, by either using the milliseconds(), or with a simple counter, but I'm not sure. Thank you for any help!
Re: Smooth Seconds hand...
Reply #1 - Jul 29th, 2005, 5:16am
 
Just use milliseconds(). If you divide it by 1000, you'll have seconds, but it'll move 1000 times more smoothly.
Re: Smooth Seconds hand...
Reply #2 - Jul 29th, 2005, 7:22am
 
I'm sorry if I somehow misunderstood you, but there is no 'milliseconds()', 'millisecond()' or otherwise function. There is a 'millis()' function, but that counts the number of milliseconds since the start of the program. Which I know I could use, but I'm still wondering if there's an easier way... Thanks again for the help.
Re: Smooth Seconds hand...
Reply #3 - Jul 29th, 2005, 10:02am
 
the function you're looking for is millis();
But it doesn't give you the current millisecond of the current time..
"Returns the number of milliseconds (thousandths of a second) since starting an applet. This information is often used for timing animation sequences."

but you still can make it work.. do a modulo on the millis.. float m = millis()%1000; which would just give you 1000 steps between previous second and current second.. (m will allways be lower than 1000, when using

good luck
Re: Smooth Seconds hand...
Reply #4 - Jul 29th, 2005, 2:52pm
 
millis() works fine for me. You just need to do a little creative number shifting. (Note the synchronization code... that's the most important part here.)

Code:
int millisoff;

void setup () {
size(128, 128, P3D);
ellipseMode(CENTER);

// this little bit lets us synchronize the milliseconds to the current second
// this way, (millis() - millisoff) % 1000 will always be 0 on a new second
int s = second();
while(s == second());
millisoff = millis();
}

void draw () {
// get hour, minute, second distances around the clock
// second is found by adding the current millisecond % 1000 / 1000 to it, so we get a smooth transition.
// hour and minute each take from the previous one so that they move smoothly as well.
float s = (second() + ((millis()- millisoff) % 1000) / 1000.0) / 60.0, m = (minute() + s) / 60.0, h = (hour() + m) / 12.0;

background(255);
translate(64, 64); rotate(-HALF_PI);

stroke(0);
ellipse(0, 0, 112, 112);
line(0, 0, cos(h * TWO_PI) * 32, sin(h * TWO_PI) * 32);
line(0, 0, cos(m * TWO_PI) * 48, sin(m * TWO_PI) * 48);

stroke(255, 0, 0);
line(0, 0, cos(s * TWO_PI) * 48, sin(s * TWO_PI) * 48);
}


Good luck!
Page Index Toggle Pages: 1