ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Less elegant but more robust

COW Forums : Adobe After Effects Expressions

FAQ   •   VIEW ALL   •   ADD A NEW POST   •   PRINT
Respond to this post   •   Return to posts index   •   Read entire thread


Elad Menashe
Less elegant but more robust
on Mar 6, 2010 at 10:06:42 am

This code will work in all cases, except overflowing of the Hours
in case you'll get to 23:59:59:24 next frame will be 24:00:00:00

Enjoy

separator = ":"

// offset
startH = 21;
startM = 19;
startS = 20;
startF = 02;

// calculate current time in H:M:S:F format
framesPerSec = 1/thisComp.frameDuration;
F = Math.round((time % 1) * framesPerSec);
timeRemainder = Math.floor(time);
S = timeRemainder % 60;
timeRemainder = timeRemainder - S;
timeRemainder = timeRemainder / 60;

M = timeRemainder % 60;
timeRemainder = timeRemainder - M;
timeRemainder = timeRemainder / 60;

H = timeRemainder; // there's no handling if H > 24...

// add offset
F = F + startF
S = S + startS
M = M + startM
H = H + startH

// check overflowing
if (F >= framesPerSec)
{
F = F - framesPerSec;
S = S + 1;
}

if (S >= 60)
{
S = S - 60;
M = M + 1;
}

if (M >= 60)
{
M = M - 60;
H = H + 1;
}

// add "0" to the beginning of the number if it is smaller than 10
StrF = (F < 10 ? "0" : "") + F;
StrS = (S < 10 ? "0" : "") + S;
StrM = (M < 10 ? "0" : "") + M;
StrH = (H < 10 ? "0" : "") + H;

"" + StrH + separator + StrM + separator + StrS + separator + StrF


Posts IndexRead Thread 


Current Message Thread:
  • Clock by Jack Parks on Mar 5, 2010 at 8:51:09 am





© 2020 CreativeCOW.net All Rights Reserved
[TOP]