Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Array, color and looping

  • Array, color and looping

    Posted by Cindy Towsley on January 25, 2024 at 8:49 pm

    Hello everyone!

    Been searching for a way to solve this problem for a while now and I just can’t find anything.

    For the video I’m working on, there will be a series of spotlights that have to change colour fairly rapidly while they move. So I found this script in a tutorial and showed a short render to the project team.

    var color1 = [0,0,0,0];
    var color2 = [1,1,1,1];

    It works but when they saw it, they said the colours were “too random” and they want a range of certain colours. So now I have 2 problems, it has to be #OnlyTheseColours and looping or pingpong smoothly back and forth. It can’t just go from one colour to the other one time. And of course loopOut() only works with keyframes drat it all.

    So I found something that talked about “linear” and that does not work, it picks a percentage (sort of) amount between 2 array items.

    var color1 = comp(“XControl”).layer(“AAA”).effect(“White”)(“Color”);
    var color2 = comp(“XControl”).layer(“AAA”).effect(“Orange”)(“Color”);
    var color3 = comp(“XControl”).layer(“AAA”).effect(“Green”)(“Color”);

    linear(.8,color1,color3) <– .8 is not time here but a value amount

    Is there an expression that would cover this? At this point, I have only one spotlight in the composition but there has to be more and I’d like to nail this down before I make more of them. Unfortunately, it will need to be flexible. I thought expressions would be the way to do it, but maybe I need to try plugins as the clock is ticking.

    At this point, there hasn’t been any question about amount of time for the colour changes, which is another reason why I was trying this with my very limited expressions knowledge. It would be easier to change if I get a “slow it down” or “speed it up”. I think I’ll try a plugin colour cycle and see how that goes.

    thank you for your help 🙂

    Brie Clayton replied 1 month ago 3 Members · 3 Replies
  • 3 Replies
  • Dan Ebberts

    January 25, 2024 at 9:34 pm

    You could start with something like this, where the array colors defines the repeating sequence of colors and the variable freq defines how fast the colors change:

    var color1 = comp("XControl").layer("AAA").effect("White")("Color");
    var color2 = comp("XControl").layer("AAA").effect("Orange")("Color");
    var color3 = comp("XControl").layer("AAA").effect("Green")("Color");
    var colors = [color1, color2, color3];
    var freq = 4; // color changes per second
    var idx = Math.floor(time*freq)%colors.length;
  • Cindy Towsley

    January 25, 2024 at 11:11 pm

    You sir are a freakin’ genius!!!

  • Brie Clayton

    January 26, 2024 at 1:40 am

    Thank you for the solve, Dan!

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy