DIGITAL CLOCK / TIMER ANIMATION in After Effects | Easy Timing with Expressions
Вставка
- Опубліковано 6 жов 2024
- How to make digital clock effect, counter animation and stopwatch animation easily with a few lines of code without using plugins with After Effects.
Codes: www.ekinyalgin...
Font: www.dafont.com...
Brilliant video. I left the background black but with the shadow centred, making it look back lit. It looks great in bright red. Thanks for the tutorial. It was everything I wanted and a whole lot more besides.
Here is a javascript alternative so you dont have to switch to the old extendscript
rate = 1;
clockStart = 0;
function timerg(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);
result = min + ":" + timerg(sec);
result;
Here's the modified expression that includes hours, minutes, and seconds in double digits, along with AM/PM indication:
rate = 1;
clockStart = 0;
function timerg(n) {
return (n < 10) ? "0" + n : "" + n;
}
clockTime = Math.max(clockStart + rate * (time - inPoint), 0);
t = Math.floor(clockTime);
hours = Math.floor(t / 3600);
min = Math.floor((t % 3600) / 60);
sec = Math.floor(t % 60);
// Determine whether it's AM or PM
ampm = (hours < 12) ? "AM" : "PM";
// Convert to 12-hour format
hours = (hours % 12 === 0) ? 12 : hours % 12;
result = timerg(hours) + ":" + timerg(min) + ":" + timerg(sec) + " " + ampm;
result;
This modification calculates whether it's AM or PM based on the hours and converts the hours to a 12-hour format. The result string includes hours, minutes, seconds, and AM/PM indication.
You saved me lot of time, thank you so mcuch
Thank you! If you want to add the hours to the clock, you can add this variable line and add it to the text print :
t = Math.floor(clockTime);
hou = Math.floor((t/3600));
min = Math.floor((t%3600)/60);
sec = Math.floor(t%60);
hou + ":" + min + ":" + timerg(sec)
Also make sure you add the timerg function to the hours and minutes to get them properly formatted:
timerg(hou) + ":" + timerg(min) + ":" + timerg(sec);
Thank you
Thank you!!! Just what I was looking for! 👍🏻
Thank you, sir! Quick question: is there a way to advance the timer faster? I'm guessing you need to adjust something on the expression, just -what- that would be is the question
Modifiy the rate
Excelente, gracias! 😃
Great video! How would I make the clock start at 4:59:55 as though an alarm clock is counting up to 5pm?
4*3600 + 59*60 +55 = clockStart = 17995;
Add the Hours variable :
t = Math.floor(clockTime);
hou = Math.floor((t/3600));
min = Math.floor((t%3600)/60);
sec = Math.floor(t%60);
hou + ":" + min + ":" + timerg(sec)
thank a lot. very usefull
Thanks mate!
You're welcome!
Also if you use your own font, remember it must be a monospaced font
Thankyou very much... How can I set the clock for hours and minutes?
Hi! To set the clock for hours and minutes in After Effects, you can modify the expressions used in the tutorial. Instead of using just seconds, you'll need to format the time to include hours and minutes. Here's an example expression:
clockStart = 0;
rate = 1;
timeInSeconds = Math.floor(clockStart + rate * (time - inPoint));
hours = Math.floor(timeInSeconds / 3600);
minutes = Math.floor((timeInSeconds % 3600) / 60);
seconds = Math.floor(timeInSeconds % 60);
(hours < 10 ? "0" + hours : hours) + ":" + (minutes < 10 ? "0" + minutes : minutes) + ":" + (seconds < 10 ? "0" + seconds : seconds);
This will display the time in HH:MM format. Adjust the clockStart and rate variables as needed.
hi, when i click source text nothing appears on the timeline, please can you tell me how to fix this, thank you
If nothing appears on the timeline when you click the source text, it's possible that the layer might be locked or not properly selected. Make sure the text layer is unlocked and selected in the timeline panel. Also, try clicking the arrow next to the text layer to expand its properties.
@@ekin-yalgin thank you boss, i fixed it, appreciate your help
May I know how to fix the digit position is changing?
To fix the digit position changing in After Effects, ensure that the anchor points of your text layers are aligned correctly. Use the "Character" panel to adjust the baseline shift and kerning to keep the digits in a fixed position. Additionally, consider using a monospaced font to ensure each digit occupies the same amount of space.
Does anybody know how to make the clock stop at a certain time?
To make the clock stop at a certain time in After Effects, you can use keyframes to animate the timer and then add a hold keyframe at the point where you want the clock to stop. Alternatively, you can use an expression to control the timer. For example, you can use the time expression and add a conditional statement to stop the timer at a specific time.
if i need to count down what should i change please?
do it normal, forward, and then on another comp put a reverse. (just an idea)
The way I dit it was by changing the clockstart to the beginning time I wanted, and change "clockTime = Math.max(clockStart + rate*(time - inPoint),0)" to "clockTime = Math.max(clockStart - rate*(time - inPoint),0)" , which is basically subtract 1 instead of add 1 to the current time.
Do you know how to make the timer advance faster?@@cedricgovaerts3279
@@cedricgovaerts3279goated
thank you