Looping countdown that lands on a specific number.

Scripting for After Effects

Looping countdown that lands on a specific number.

Postby mbeasom on 08/4/2015, 8:41 am

I'm going to try and explain this the best I can. I want to create and animation where I start at 2 and go to 10 and loop several times before it slows down and lands on a number specified (Somewhat like a slot machine).

This video is close to the effect I want to achieve.

https://youtu.be/baGCfPyVc4Q

Could someone help me set up an expression to achieve this?

Thanks.
mbeasom
 
Posts: 3
Joined: 08/4/2015, 8:34 am
System Specs: Intel(R) Xeon(R) CPU W3550 @3.07 GHz
AMD Radeon R7 200 Series
4gb Ram
Windows 8 64-bit

Re: Looping countdown that lands on a specific number.

Postby star+circle on 08/5/2015, 1:07 am

I would use a slider, as then you can animate the slider to slow down the counter and end up on a specific number.

The expression for the source text would then be:

Code: Select all
V= effect("Slider Control")("Slider");
V = 2+ Math.floor(V-Math.floor(V/9)*9);


Note that the slider value and the numeric output do not correspond, since you're rotating in units of 9, so you'll have to find the suitable end value by dragging the slider.
star+circle
 
Posts: 745
Joined: 12/6/2014, 3:07 pm
Location: Finland

Re: Looping countdown that lands on a specific number.

Postby mbeasom on 08/5/2015, 10:37 am

Thank you! This is exactly what I was looking for. Do you mind explaining what the expression is doing to achieve this?
mbeasom
 
Posts: 3
Joined: 08/4/2015, 8:34 am
System Specs: Intel(R) Xeon(R) CPU W3550 @3.07 GHz
AMD Radeon R7 200 Series
4gb Ram
Windows 8 64-bit

Re: Looping countdown that lands on a specific number.

Postby star+circle on 08/6/2015, 9:22 am

The first line gets the value of the slider (between 0 and 100 as you animate it).

The second line calculates the modulo (i.e. remainder) of the slider value divided by 9, which makes it circle from 0 to 8. And adds 2 to it, resulting in circling from 2 to 10.

Math.floor returns the value of "V" without any trailing digits. For instance, if V = 3.57664, Math.floor(V) = 3.
star+circle
 
Posts: 745
Joined: 12/6/2014, 3:07 pm
Location: Finland

Re: Looping countdown that lands on a specific number.

Postby mbeasom on 08/6/2015, 11:17 am

Math.floor the same as Math.round?
mbeasom
 
Posts: 3
Joined: 08/4/2015, 8:34 am
System Specs: Intel(R) Xeon(R) CPU W3550 @3.07 GHz
AMD Radeon R7 200 Series
4gb Ram
Windows 8 64-bit

Re: Looping countdown that lands on a specific number.

Postby star+circle on 08/7/2015, 1:25 am

Similar. Math.round outputs the closest integer, Math.floor only the full integers of the input, discarding anything after the decimal point, even if it is .999999.

Actually, there is a simpler way to get the modulus than that, the operator "%". The second line can be written as:

Code: Select all
V = 2 + Math.floor(V % 9)
star+circle
 
Posts: 745
Joined: 12/6/2014, 3:07 pm
Location: Finland

Re: Looping countdown that lands on a specific number.

Postby pavelusha on 08/27/2015, 7:16 pm

I did similar animation a few years back.
[youtube]https://www.youtube.com/watch?v=7zfGIvw0ZUg[/youtube]

Here you can download the project file if you'd like: https://www.facebook.com/download/98178 ... ometer.aep
pavelusha
 
Posts: 4
Joined: 10/31/2010, 3:57 am


Return to After Effects Expressions