Activity › Forums › Adobe After Effects Expressions › Repeat After Effects expressions
Tagged: Basic
-
Repeat After Effects expressions
Posted by Steve Robinsons on March 2, 2021 at 4:11 pmHi!
I need help to repeat this js code (like Looping Out). I mean, I want to repeat it based on the next 360º full rotations. I also hear tips to improve my code! Thx
rot = transform.rotation;
if(rot>=0 && rot<=45) ease(rot,0,45,10,100)
else if(rot>=45 && rot<=90) ease(rot,45,90,100,10)
else if(rot>=90 && rot<=135) ease(rot,90,135,10,100)
else if(rot>=135 && rot<=180) ease(rot,135,180,100,10)
else if(rot>=180 && rot<=225) ease(rot,180,225,10,100)
else if(rot>=225 && rot<=270) ease(rot,225,270,100,10)
else if(rot>=270 && rot<=315) ease(rot,270,315,10,100)
else if(rot>=315 && rot<=360) ease(rot,315,360,100,10);
Dan Ebbertsreplied 5 years, 2 months ago 2 Members · 6 Replies
-
6 Replies
-
Dan Ebberts
March 2, 2021 at 5:13 pmTry it this way:
rot = transform.rotation%90;
if(rot < 45)
ease(rot,0,45,10,100)
else
ease(rot,45,90,100,10)
-
Dan Ebberts
March 3, 2021 at 1:07 pmYou mean %90 ? % is the modulus operator in JavaScript. It returns the remainder from a division operation. So, for example 108 % 90 would give you 18. In this case, it keeps all your angles in the range from 0 to 89.9999… degrees.
-
Steve Robinsons
March 3, 2021 at 9:45 pmHello again Dan,
How can I simplify this code? It is similar to the one last sent.
Thank you so much, I’m learning a lot!
rot = transform.rotation;
tsx = 360;
// 1. 360
if(rot>=-30 && rot<=30) ease(rot,-30,30,effect("Color Control 2")("Color"),effect("Color Control")("Color"))
else if(rot>=60 && rot<=120) ease(rot,60,120,effect("Color Control")("Color"),effect("Color Control 2")("Color"))
else if(rot>=120 && rot<=150) effect("Color Control 2")("Color")
else if(rot>=150 && rot<=210) ease(rot,150,210,effect("Color Control 2")("Color"),effect("Color Control")("Color"))
else if(rot>=240 && rot<=300) ease(rot,240,300,effect("Color Control")("Color"),effect("Color Control 2")("Color"))
else if(rot>=300 && rot<=tsx-30) effect("Color Control 2")("Color")
// 2. 360
else if(rot>=tsx-30 && rot<=tsx+30) ease(rot,tsx-30,tsx+30,effect("Color Control 2")("Color"),effect("Color Control")("Color"))
else if(rot>=tsx+60 && rot<=tsx+120) ease(rot,tsx+60,tsx+120,effect("Color Control")("Color"),effect("Color Control 2")("Color"))
else if(rot>=tsx+120 && rot<=tsx+150) effect("Color Control 2")("Color")
else if(rot>=tsx+150 && rot<=tsx+210) ease(rot,tsx+150,tsx+210,effect("Color Control 2")("Color"),effect("Color Control")("Color"))
else if(rot>=tsx+240 && rot<=tsx+300) ease(rot,tsx+240,tsx+300,effect("Color Control")("Color"),effect("Color Control 2")("Color"))
else if(rot>=tsx+300 && rot<=tsx*2-30) effect("Color Control 2")("Color")
// 3. 360
else if(rot>=tsx*2-30 && rot<=tsx*2+30) ease(rot,tsx*2-30,tsx*2+30,effect("Color Control 2")("Color"),effect("Color Control")("Color"))
else if(rot>=tsx*2+60 && rot<=tsx*2+120) ease(rot,tsx*2+60,tsx*2+120,effect("Color Control")("Color"),effect("Color Control 2")("Color"))
else if(rot>=tsx*2+120 && rot<=tsx*2+150) effect("Color Control 2")("Color")
else if(rot>=tsx*2+150 && rot<=tsx*2+210) ease(rot,tsx*2+150,tsx*2+210,effect("Color Control 2")("Color"),effect("Color Control")("Color"))
else if(rot>=tsx*2+240 && rot<=tsx*2+300) ease(rot,tsx*2+240,tsx*2+300,effect("Color Control")("Color"),effect("Color Control 2")("Color"))
else if(rot>=tsx*2+300 && rot<=tsx*3-30) effect("Color Control 2")("Color")
// 4. 360
else if(rot>=tsx*3-30 && rot<=tsx*3+30) ease(rot,tsx*3-30,tsx*3+30,effect("Color Control 2")("Color"),effect("Color Control")("Color"))
else if(rot>=tsx*3+60 && rot<=tsx*3+120) ease(rot,tsx*3+60,tsx*3+120,effect("Color Control")("Color"),effect("Color Control 2")("Color"))
else if(rot>=tsx*3+120 && rot<=tsx*3+150) effect("Color Control 2")("Color")
else if(rot>=tsx*3+150 && rot<=tsx*3+210) ease(rot,tsx*3+150,tsx*3+210,effect("Color Control 2")("Color"),effect("Color Control")("Color"))
else if(rot>=tsx*3+240 && rot<=tsx*3+300) ease(rot,tsx*3+240,tsx*3+300,effect("Color Control")("Color"),effect("Color Control 2")("Color"))
else if(rot>=tsx*3+300 && rot<=tsx*4-30) effect("Color Control 2")("Color")
else if(rot>=tsx*4-30 && rot<=tsx*4+30) ease(rot,tsx*4-30,tsx*4+30,effect("Color Control 2")("Color"),effect("Color Control")("Color"))
-
Dan Ebberts
March 4, 2021 at 6:56 amThere has to be a way to vastly simplify the code, but it’s hard to tell from looking at it what it’s supposed to be doing exactly. There seem to be gaps, like from 30 to 60, and from 210 to 240 where no action is defined. If you could describe what you need it to do, it might be easier to start there.
Reply to this Discussion! Login or Sign Up