Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Expression to color specific numbers

  • Expression to color specific numbers

    Posted by Richard Clayton on June 20, 2019 at 3:44 pm

    I’ve created a count down clock using this expression:

    I want to be able to assign a rgb colour value to each number, for example all 7’s are green or all 2’s are red etc…

    rateOfSpeed = 1;
    clockStartTime = thisComp.layer("TIMER DURATION").effect("Slider Control")("Slider")*60;

    function addZero(n) {
    if (n<10) return "0" + n else return n;
    }

    clockTimeNumber = Math.floor(clockStartTime-rateOfSpeed*time);

    minutes = Math.floor(clockTimeNumber/60);
    seconds = clockTimeNumber%60;
    addZero(minutes) + ":"+ addZero(seconds);

    Oleg Pirogov replied 7 years, 1 month ago 2 Members · 1 Reply
  • 1 Reply
  • Oleg Pirogov

    June 21, 2019 at 7:38 am

    Depending on how much control you want over the colors you may or may not settle on this:

    1) Add a text animator for Fill Color -> Hue
    2) Set Fill Hue to =1x 0.0
    3) Delete Range Selector
    4) Add Expression Selector
    5) Add this code to the Amount expression:
    colors = [0,10,20,30,40,50,60,70,80,90];
    N=Number(text.sourceText[textIndex-1])
    if (!isNaN(N)) {colors[N]}
    else {30}

    And get this:

    This allows you to define 10 colors for 10 digits plus 1 additional color for non-digit characters (dot “.” is evaluated as “0” digit). A color is specified with a number from 0 to 100 corresponding to hue scale: 0 for 0, 100 for 360 degrees. Not a full RGB range but still. Digit colors are specified in array [0,10,20,30,40,50,60,70,80,90] : 1st element is for digit “0”, 2nd for “1” etc. Value in else {…} is for non-digits.

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