ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Expression to color specific numbers

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Richard Clayton
Expression to color specific numbers
on Jun 20, 2019 at 3:44:54 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&lt;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);

Return to posts index

Oleg Pirogov
Re: Expression to color specific numbers
on Jun 21, 2019 at 7:38:45 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];
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.

Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 All Rights Reserved