Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions rotating a clock based on time

  • rotating a clock based on time

    Posted by Martin Löfqvist on March 10, 2012 at 10:43 pm

    Hi,

    I’m trying to write a (simple I thought) code for rotating a clock, based on the actual time in the comp.
    I figured it would work like this.

    1) Have something constantly counting (variable i), in my example using timeToFrames
    2) Translate that to seconds, I used Math.floor(i/25) to get the current second (yeah the base is 25)
    3) see if the variable is equal to the variabel seconds.
    4) if so, rotate the pointer with 6 degrees.

    This didn’t quite work, I think because the condition only occurs on one frame.

    So I tried adding another counter, c. That would be set to 6 when i and seconds matched up.
    Then, as long as c was less or equal to 6 i would subtract it by 1 and rotate the layer by 1 degree.

    Sadly this didn’t work either. Anyone has any thoughts on how to solve this?

    rot = this.rotation;
    i = timeToFrames(t = time + thisComp.displayStartTime, fps = 1.0 / thisComp.frameDuration, isDuration = false);
    seconds = Math.floor(i/25);
    if (i/25 == seconds) {
    c = 6;
    } else {
    c = 0; }

    if (c <= 6) { 
    c = -1;
    transform.rotation = rot+1;
    }

    Dan Ebberts replied 14 years, 2 months ago 2 Members · 1 Reply
  • 1 Reply
  • Dan Ebberts

    March 10, 2012 at 11:30 pm

    This should work:

    Math.floor(timeToFrames(time)/25)*6

    Actually, I think this should work as well:

    Math.floor(time)*6

    Dan

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy