Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Making an array of color values

  • Making an array of color values

    Posted by Ryan Paterson on January 17, 2014 at 9:19 pm

    So I have a “fill” effect, and I want an expression to randomly select a color from a palette of 3 colors. Is is possible to declare an array of 3 RGB values, and then have the layer pick a random number between 0 and 2, and use the corresponding value from the array?

    This is ALMOST working, can’t figure out why it won’t recognize the first color properly, this is applied to the “color” property-

    options = [[120, 120, 120], [0, 255, 0], [0, 0, 255]];
    //seedRandom(index, true);
    r = Math.round(random(2));
    v = options[r];
    [v[0], v[1], v[2], 255]

    Edward Foster replied 12 years ago 3 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    January 17, 2014 at 9:27 pm

    Try it this way:

    options = [[120, 120, 120, 255], [0, 255, 0, 255], [0, 0, 255, 255]];
    //seedRandom(index, true);
    r = Math.floor(random(3));
    options[r]/255;

    Dan

  • Ryan Paterson

    January 17, 2014 at 9:42 pm

    Ah, this is because the “color” value is between 0 and 1, correct? I like that array syntax at the end too, nice and simple. Thanks!

  • Edward Foster

    May 5, 2014 at 4:16 pm

    This is almost exactly what I need, but the colors rotate on every frame when I use the expression. I just need one color per layer that doesn’t change over time. I’m not sure how I need to modify the expression

  • Dan Ebberts

    May 5, 2014 at 4:27 pm

    The code you need to do that is commented out. Just change this:

    //seedRandom(index, true);

    to this:

    seedRandom(index, true);

    Dan

  • Edward Foster

    May 5, 2014 at 5:04 pm

    Oh geez, thanks, I didn’t even notice that!

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