ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Expression to count up every X amount of frames

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
aoife mccarthy
Expression to count up every X amount of frames
on Jun 18, 2020 at 5:32:09 pm

Hi all!

I'm currently working on an animated data visualisation, and I'm having issues syncing up my animated timeline with my data points on the chart. The timeline looks like this:



The marker moves along the timeline from left to right, whilst the day marker to the right counts up.

In the expression for the data points, each day has a duration of 3 frames. So 0:00:00:00 = val1, 0:00:00:03 = val2, 0:00:00:06 = val3 etc.

I've used a slider control for the day marker (setting start and end values to 1 and 29/30/31 respectively), with this expression in Source Text:

Math.round(effect("Slider Control")("Slider"))

However it doesn't exactly sync up with the data - some days get 4 frames, some get 3 etc. Is it a rounding issue?

I think I need to create some kind of integer counter that counts up every 3 frames exactly – can anybody help?


Return to posts index

aoife mccarthy
Re: Expression to count up every X amount of frames
on Jun 18, 2020 at 8:24:04 pm

If it helps, this is how I've managed to get it working with keyframes... there must be a way to automate this though!



Return to posts index

Dan Ebberts
Re: Expression to count up every X amount of frames
on Jun 18, 2020 at 9:39:50 pm

I'm not clear on what you're doing, but something like this might fit in there somewhere:

Math.floor(effect("Slider Control")("Slider")/3)*3


Dan



Return to posts index


aoife mccarthy
Re: Expression to count up every X amount of frames
on Jun 19, 2020 at 8:41:01 am

Hi Dan, thanks for your suggestion. That's not quite what I need though – I've just tried it out and it's counting up in 3's, I need it to increment by 1.

Basically what I need is a counter that counts up from 1 - 30, with each number having an exact 3 keyframe duration. I think my issue with using a slider is I end up dealing with floating point precision, which makes the distribution of keyframes slightly uneven.

I've achieved it manually by using toggle hold keyframes on the slider property, ie 0:00:00:00 → Slider = 1, 0:00:00:03 → Slider = 2, 0:00:00:03 → Slider = 3 etc.

Does that make sense? Let me know if there's any other salient points I've missed!


Return to posts index

Robert Müller
Re: Expression to count up every X amount of frames
on Jun 19, 2020 at 9:40:20 am

Hi, this should do what you are looking for

t=timeToFrames();
frameStep=3;
days=30;
Math.floor(t/frameStep)%days+1

this counts to 30 (or any number you put for "days") every 3 frames (or any number you put for "frameStep"), starting at 1 and resetting back to 1 after 30.
If you want to stop at 30 try this:
t=timeToFrames();
frameStep=3;
f=Math.floor(t/frameStep)+1;
if (f>30){30}else{f};


Return to posts index

aoife mccarthy
Re: Expression to count up every X amount of frames
on Jun 19, 2020 at 11:59:38 am

Hi Robert - that's it! Thanks a million


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2020 CreativeCOW.net All Rights Reserved
[TOP]