Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Change text color every word

  • Change text color every word

    Posted by David Schagerström on October 9, 2014 at 9:01 am

    Hi!

    I’m working on some text and this seems fairly easy, but havnt found a way of doing it yet. My text needs to change color every new word. Its goes between 3 colors. So its “Red blue green red blue green red blue”. It shouldnt animate. Any ideas?

    Trevor Asquerthian replied 11 years, 10 months ago 3 Members · 8 Replies
  • 8 Replies
  • David Schagerström

    October 15, 2014 at 8:28 am

    Some stuff has changed. It now needs to change between 3 color like this 1 2 3 2 1 2 3 2 1.
    What I’ve tried to do is to I’ve set the text color to color 1. Then added two fill color expressions. the first one has …

    textIndex%3 ? 0 : 100

    and the second

    textIndex%2 ? 0 : 50

    But it gets messy after the first 3 word as one would expect. was thinking that I could get solved with an “if” expression, but have no idea how to write it.

    Thanks for any help!

  • Dan Ebberts

    October 15, 2014 at 1:36 pm

    I would think one would be like this:

    (textIndex-1)%4 == 1 || (textIndex-1)%4 == 3 ? 100 : 0

    and the other would be like this:

    (textIndex-1)%4 == 2 ? 100 : 0

    Dan

  • Trevor Asquerthian

    October 15, 2014 at 2:33 pm

    I managed this by butchering one of Dan’s other posts:

    Set text colour to white
    Add animator for fill colour RGB – set that colour to black
    Add text selector | expression – set amount to 50%,50%,50%

    then in that amount add the following expression:

    palette = [[0,100,100],[100,0,100],[100,100,0],[0,0,0]];
    // [red,blue,green,white]

    switch (textIndex%4) {

    case 1:
    idx = 0;
    break;

    case 3:
    idx = 2;
    break;

    default:
    idx = 1;
    }
    palette[idx]

  • David Schagerström

    October 15, 2014 at 3:08 pm

    Cheers Dan! Works like a charm!
    Question, I need to make this a color. This only allows me to change the grey scale. how would i change it to RGB?

    Thanks!

  • David Schagerström

    October 15, 2014 at 3:27 pm

    Thanks trevor! It seems to work. I just dont understand the color values? are they in RGB? cant change them into what I need.

    Cheers!

  • Dan Ebberts

    October 15, 2014 at 3:56 pm

    This is for a Fill color animator with an expression selector, correct? One of the choices is RGB. Or maybe I don’t understand what you’re doing.

    Dan

  • David Schagerström

    October 15, 2014 at 4:01 pm

    Ok I understand now how it works! I was being slow.
    Thanks again!

  • Trevor Asquerthian

    October 16, 2014 at 6:17 pm

    I’ve kind of figured out what is going on… 😉

    Adding the fill (RGB) animator allows the change of levels between the ‘text’ colour and the ‘fill’ colour

    The ‘range selector’ doesn’t allow for a per word selection, only a range within the whole text box, so we delete that

    The ‘expression selector’ allows the change to occur based on the index of text within the text box – with the expression disabled you can see the colours generated by using the ‘amount’ values as R G and B. – i.e. at 100,100,100 it is all ‘fill’ at 0,0,0 it is all ‘text’ colour

    It’s less confusing if the text colour is Black and the Fill is white – thus the amount values become RGB rather than 1-R, 1-G, 1-B.

    With the amount expression enabled the default expression does a gradation between black and white over the text box.

    With the expression below the value depends on the index of the word (if ‘words’ is selected for the expression to be based on)

    The palette can be changed accordingly

    I hope this helps, it certainly helped me to think about it (and thanks to Dan for the original)

    palette = [[100,0,0],[0,100,0],[0,0,100],[100,100,100]];
    // [red,blue,green,white]

    switch (textIndex%4) {

    case 1:
    idx = 0;
    break;

    case 3:
    idx = 2;
    break;

    default:
    idx = 1;
    }
    palette[idx]

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