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 › fluent Seconds
Page Index Toggle Pages: 1
fluent Seconds (Read 750 times)
fluent Seconds
Oct 18th, 2007, 12:16am
 
Hello,

i started to work with Processing,
and i had a simple Problem, but i dont have any clue to solve it.

I have written an short Sketch, with an rect which works like a second hand in a clock. But the second() function gives me only one signal every second. And i want a static fluent movement.

Anybody an idea to solve the Problem?

Code:

float a = 0;

void setup(){
size(200,200);
smooth();
}

void draw(){

background(255);
translate(width/2,height/2);

a =map(second(),0,59,0,360);
rotate(radians(a));
rect(0,0,40,40);

println(second());
}


ps: sorry for the bad english. Smiley
Re: fluent Seconds
Reply #1 - Oct 18th, 2007, 12:56am
 
You could try using millis()instead.

a = map(millis(),0,59000,0,360);
Re: fluent Seconds
Reply #2 - Oct 18th, 2007, 6:46am
 
But millis Returns the number of milliseconds since starting an applet. Not the actually Time.
Re: fluent Seconds
Reply #3 - Oct 18th, 2007, 7:24am
 
another option is to store the "millis" upon starting the clock and then base the clock's movement based on an offset.

maybe something like this? "current" is called in setup and then it is subtracted from the current time while time is running.

Code:

float a = 0;
long current;

void setup(){
size(200,200);
smooth();
current = System.currentTimeMillis();
}

void draw(){

background(255);
translate(width/2,height/2);

a =map(System.currentTimeMillis()-current ,0,59000,0,360);
rotate(radians(a-90)); // we subtract 90 here to start the clock at straight up, like a normal clock would
rect(0,0,40,40);

println(second());
}
Re: fluent Seconds
Reply #4 - Oct 18th, 2007, 7:59am
 
Works very well. Nice Idea.

Thank you.
I dont understand every command, but i will find it out.

My idea with easing is not work so nice. Smiley

Code:

float floatingsecond;
float targetsecond;
float easing = 0.01;

void setup(){
size(200,200);
smooth();
}

void draw(){
background(255);
translate(width/2,height/2);

targetsecond = map(second(),0,59,0,360);
float dx = map(second(),0,59,0,360) - floatingsecond;
if (abs(dx) > 1){
floatingsecond += dx * easing;
}

rotate(radians(floatingsecond+180));
line(0,0,0,60);
}
Re: fluent Seconds
Reply #5 - Oct 18th, 2007, 12:51pm
 
So after I had a closer lock to your Code Aaron, i had a small problem. The static rotation works fine, but whatever time it is, the rect starts every time on the same position.

The same effect as if i only use millis().

And not in connection with the Time.
Re: fluent Seconds
Reply #6 - Oct 19th, 2007, 12:26am
 
I think i got it.

Two Problems did I have with the Code from Aaron.

First problem was the start position from the line.

Second problem was, the map command. After the Clock runs some time, and the millis got to be bigger as 59000, it becomes incorrect.

Here my modified version:

Code:

float a = 0;
int s = second();
float current;

void setup(){
size(200,200);
smooth();

}

void draw(){

background(255);
translate(width/2,height/2);
current = millis();
a =current*0.006 ; //no map() command needed anymore.
rotate(radians(a-180+s*6)); //once time I set the line on the correct start position with "s*6"
line(0,0,0,60);

println(second());
println(current);
}
Page Index Toggle Pages: 1