FORUMS: list search recent posts

This rotation expression, but with slider control?

FAQ   •   VIEW ALL
 This rotation expression, but with slider control? on Aug 19, 2015 at 11:57:27 amLast Edited By Bas v Breugel on Aug 20, 2015 at 2:03:32 pm

Hi guys,

Is it possible to have this expression below, powered by an slider control?
So if you would set the slider control to 1, it turns every second, if you would change the slider to 4, it would turn 4 times as fast.

(I have a sort of abstract clock ticking, but at a specific moment I want the clock to turn faster)

```wholeSecond = Math.floor(time); rotateDuration = 0.2; anglePerSecond = 6; // 360 / 60 startAngle = wholeSecond * anglePerSecond; linear(time, wholeSecond + 0.8, wholeSecond + 1, startAngle, startAngle + anglePerSecond)```

 Re: This rotation expression, but with slider control?on Aug 19, 2015 at 4:24:26 pm

Should work if you pick whip the slider to the beginning of the last line (before "linear")and add a multiplication "*" in between.

 Re: This rotation expression, but with slider control?on Aug 20, 2015 at 1:00:53 pm

Hmm, the slider works with 1, but wen set to 4, the rotation goes 4 times more rotation degrees instead of 4 times same rotation in one second.

 Re: This rotation expression, but with slider control?on Aug 20, 2015 at 1:47:02 pm

Ok, I see the problem. Try putting the slider reference and "*" right before "time" inside the parenthesis.

 Re: This rotation expression, but with slider control?on Aug 20, 2015 at 2:01:29 pmLast Edited By Bas v Breugel on Aug 20, 2015 at 2:02:18 pm

Thanks Kalle, but it doenst seem to have any effect.
See https://vimeo.com/136826287 where I recorded my screen. thanks so much for you help sofar.

 Re: This rotation expression, but with slider control?on Aug 21, 2015 at 6:26:59 am

Ok, so much for trying to do it without actually trying to see if it works...

After actually trying it, it is definitely more complicated than I thought. Since the rotation is tied to the Time value, it gets tricky to do what you want with the current method. It would be better to animate the slider to represent time. If you use Time, you will have to sample all previous frames for what the slider value was and add them all up. While it can be done, it is inefficient.

So, if you use the slider to represent time, the following does it:

```t = effect("Slider Control")("Slider"); wholeSecond = Math.floor(t); rotateDuration = 0.2; anglePerSecond = 6; // 360 / 60 startAngle = wholeSecond * anglePerSecond; linear(t, wholeSecond + 0.8, wholeSecond + 1, startAngle, startAngle + anglePerSecond)```

Unfortunately, you'll have to track the time usage yourself if done this way. For instance, if you wan to speed up between seconds 5 and 6, the keyframed slider values would be:

0 seconds: 0
5 seconds: 5
6 seconds: 9 (time advances 4 seconds within 1 second)
10 seconds: 13

 Re: This rotation expression, but with slider control?on Aug 21, 2015 at 6:51:31 amLast Edited By Kalle Kannisto on Aug 21, 2015 at 6:57:21 am

But, if you want to do as you originally planned, this would be the expression. (I named the slider "Speed Control" and it's on the second hand layer.)

```frame = thisComp.frameDuration; current_time=0; for (i = 0; i <=time; i += frame){ current_time += effect("Speed Control")("Slider").valueAtTime(i)*frame; } wholeSecond = Math.floor(current_time); rotateDuration = 0.2; anglePerSecond = 6; // 360 / 60 startAngle = wholeSecond * anglePerSecond; linear(current_time, wholeSecond + 0.8, wholeSecond + 1, startAngle, startAngle + anglePerSecond)```

BTW, the "rotateDuration = 0.2;" line doesn't do anything, you can take it out.