Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Switching between an array of colors

  • Switching between an array of colors

    Posted by Thomas Hannen on March 1, 2016 at 4:54 pm

    I have a set of 14 different colors stored as RGBA, or Hex values.
    I would like to be able to apply those colors to a solid, and switch between them using a slider control.

    I’ve found a way to do this using Hue angles, but not for RGBA or Hex values. If I name each of the arrays with a number in the name, can I append that number to a string, then call it in the expression somehow?

    mycolor1 = [81,45,10,255];
    mycolor2 = [38,184,82,255];
    mycolor3 = [255,157,150,255];
    mycolor4 = [19,23,148,255];
    mycolor5 = [119,241,225,255];
    mycolor6 = [255,59,212,255];
    mycolor7 = [44,134,120,255];
    mycolor8 = [255,89,10,255];
    mycolor9 = [235,213,8,255];
    mycolor10 = [236,39,34,255];
    mycolor11 = [228,212,136,255];
    mycolor12 = [186,38,138,255];
    mycolor13 = [255,142,144,255];
    mycolor14 = [48,205,187,255];

    mynumber = thisComp.layer("Null 3").effect("choosecolor")("Slider");

    finalstring = 'mycolor' + mynumber +'[0]/255'; // this doesn't work!

    var r = mycolor2[0]/255;
    var g = mycolor2[1]/255;
    var b = mycolor2[2]/255;
    var a = mycolor2[3]/255;

    [r,g,b,a]

    Dan Ebberts replied 10 years, 2 months ago 2 Members · 1 Reply
  • 1 Reply
  • Dan Ebberts

    March 1, 2016 at 5:43 pm

    You could do it by building a string and using eval() to evaluate it, but I think I’d just use nested arrays, like this:


    myColors = [[81,45,10,255],
    [38,184,82,255],
    [255,157,150,255],
    [19,23,148,255],
    [119,241,225,255],
    [255,59,212,255],
    [44,134,120,255],
    [255,89,10,255],
    [235,213,8,255],
    [236,39,34,255],
    [228,212,136,255],
    [186,38,138,255],
    [255,142,144,255],
    [48,205,187,255]];

    myNumber = Math.round(thisComp.layer("Null 3").effect("choosecolor")("Slider"));

    myColors[clamp(myNumber,0,myColors.length-1)]/255;

    Dan

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