rate = -1;
clockStart = 388;
function padZero(n){
if (n < 10) return "0" + n else return "" + n
}
clockTime = Math.max(clockStart + rate*(time - inPoint),0);
t = Math.floor(clockTime);
min = Math.floor((t%3600)/60);
sec = Math.floor(t%60);
milliseconds = clockTime.toFixed(3).split(".")[1];
min + ":" + padZero(sec) + "." + milliseconds;
The magic happens here:
milliseconds = clockTime.toFixed(3).split(".")[1];
Here’s a translation. toFixed() is a method that converts a number to a string with a fixed number of decimal places (in this use above, 3). It will pad with zeroes as necessary to maintain this fixed number.
split() is a method which splits a string into an array of substrings when given a separator. In this case, the separator is a period. For the string “0.123.456”, split(“.”) yields this array of strings: [“0″,”123″,”456”]. We use array indices to access a specific substring.
In plain English, the above line says convert the clock time to a string including 3 decimal places, then take only the digits after the decimal point and call them “milliseconds.”
Walter Soyka
Designer & Mad Scientist at Keen Live [link]
Motion Graphics, Widescreen Events, Presentation Design, and Consulting
@keenlive | RenderBreak [blog] | Profile [LinkedIn]