- May 6, 2020 at 11:41 am
Hi there. I am creating this clock widget where I need the sun and moon layer to rotate alternatively when time goes from 6 to 12. From 12 to 6 there’s no change and so on it continues…
I’ve set the speed of clock based on comp duration so that I can multiply it by any number
And also I have the sun and moon in the same layer…
I’m having trouble making the sun and moon rotate correctly…
6 -12——–moon stay
Next 6-12——- moon rotate by 180 to show the sun
12-6—— sun stay
And so the loop continues..
I want it all without any keyframes..
Pls, .help me…
- May 6, 2020 at 11:52 am
12-6——moon. (First frame)
6-12——- moon rotate by 180 to show the sun
12-6—— sun stay
6-12——sun rotate 180 to show the sun
And the loop goes on
THIS IS THE CORRECT ORDER
- May 6, 2020 at 10:48 pm
Hi, using this script by Dan Ebberts I got it kinda working the way you want to, but a little bit different. The clock works now by a slider-value, which dictates how long a 6hour cycle will take.
Expression for the minute hand:
cyc= thisComp.layer("Null 1").effect("6h-cycle length")(1); //the aforementioned slider, here with the value 5(sec)
t=time%cyc; //t as a time driven variable will jump back to zero every "cyc" seconds
seg = Math.floor(time/(cyc)); //calculating the number of rounds, important for the last step
(180*12)*seg+linear(t,0,cyc,0,(180*12)) //"linear"-ing the rotation and adding the amounts of full rotations
180*12 for 6 full rotations, I was to lazy to tidy this up. I also forgot to calculate for the layer.inPoint, for example if you move your layer around on the timeline.
Expression for the hourhand:
thisComp.layer("min").transform.rotation/12 //Nothing special, just dividing the minute rotation by 12
And the most important, expression on the sun/moon-thingy:
rampDur = thisComp.layer("Null 1").effect("6h-cycle length")(1); //same
segDur = 2*rampDur;// double it up for a full 12h circle. Since the widget will be resting for 6 hours and rotating for the other six
t = (time+rampDur - inPoint)%segDur; //same as before but this time I "offset" the whole thing by a 6 hour cycle, since it should start stationary
seg = Math.floor((time+rampDur-inPoint)/segDur); //again as before but added the "rampDur" as a 6-hour-cycle offset
180*seg + ease(t,0,rampDur/1,0,180)// decided to use ease instead of linear since it looks nicer. I explain below why I left the devision after rampDur in
I hope you understand evertything with my comments, but I’ll attach a file as well. Now, if you want to speed up or slow down your clock animation change or animate the slider on the Null. If you feel your sun/moon rotation should be faster than a 6-hour-cycle, just divide the last rampDur in the ease by the desired amount, eg in this case by 5 to have the rotation be 1 second long. In this example I put the 1 to leave it just as it is.
I hope I could help, I definetly learned a few new things while working on this problem ???? Thanks to Dan for his awesome expression powers, I hope its okay I borrowed from your last solution… and didnt even bother to rename the variables. Sorry!????
- May 7, 2020 at 10:04 am
Thank you soooooo much Robert and Dan for making me understand the logic behind it.
And I was ae to successfully set up the rog as I wanted. Now it can loop seamlessly based in comp duration.
The only thing is the no of cycles should be even to loop seamlessly….
Thank you guys again ….????????????
Here is the code
cyc =4; // should be even for a seamless loop
segDur = thisComp.duration/cyc;
rampDur = (segDur*0.5).toFixed(2);
t = time%segDur.toFixed(2);
seg = Math.floor(time/segDur);
deg = 180;
Log in to reply.