Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity › Forums › Adobe After Effects Expressions › coloring text based on numbers from an array (list)

  • coloring text based on numbers from an array (list)

    Posted by Chris Gulliford on September 10, 2014 at 7:51 pm

    So I have the following expression that takes a number from a list and puts it up on the screen every six frames (30 fps). Works great. Now i need compare each number from the list to the following and change the color of the test accordingly:

    0-100 – Green
    101-140 – Yellow
    141 – 160 – Orange
    161 – Up – Red

    I’ve tried to use different animator descriptions and changing the hue/saturation, but to no avail.

    Any ideas would be greatly appreciated.

    Thanks.

    // expression to take input of series of numerical values and display them five per second or every six frames
    // get our source list
    listText = thisComp.layer("heart").text.sourceText;

    // now make an array, assuming a comma delimiter
    list = listText.split(",");

    // what's the biggest value? we'll use this as our denominator
    maximum = Math.max.apply(Math, list);

    // which number should we look at? one per six frames
    wholeSeconds = Math.floor(time-inPoint);
    milliSeconds = Math.floor(((time-inPoint) - wholeSeconds) * 1000);
    indexModifier = Math.floor(milliSeconds/200);
    target = (wholeSeconds*5) + indexModifier;

    // make sure we don't try to find the value-as-a-percentage for an out-of-bounds array number, or try to divide by zero
    if ((target >= 0) && (target < list.length) && (maximum != 0)) {

    // this will print to screen the array number or zero
    speed = list[target];
    } else speed= 0;

    Chris Gulliford replied 12 years ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    September 10, 2014 at 8:29 pm

    Assuming that you’re using an RGB fill animator and “n” represents your number, something like this for fill color should work:


    if (n <= 100)
    [0,1,0,1]
    else if (n <= 140)
    [1,1,0,1]
    else if (n <= 160)
    [1,.5,0,1]
    else
    [1,0,0,1];

    Dan

  • Chris Gulliford

    September 10, 2014 at 8:59 pm

    that works good, but returns whatever’s between the square brackets… How do I get that number to return and change in the text’s color?

    Thanks again.

  • Dan Ebberts

    September 10, 2014 at 9:35 pm

    I’m lost. I would only work as part of an expression for Fill Color.

    Dan

  • Chris Gulliford

    September 11, 2014 at 4:12 pm

    This was great! thanks…. It took me a bit to think to put the code in under “color” lol.

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