Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expression to assign a color to a letter?

  • Expression to assign a color to a letter?

    Posted by Ari Grunzeweig on June 9, 2019 at 12:47 am

    Hi,

    I found the following expression on CC to assign a color to letters in a block of text.

    However, even though I have the letter ‘a’ associated with a specific color value, different ‘a’s in my text and appearing as different colors.

    txt = text.sourceText;
    switch(txt[textIndex-1]){
    case "A":
    color = [0,1,0];
    break;
    case "C":
    color = [0,0,1];
    break;
    case "T":
    color = [1,1,0];
    break;
    case "G":
    color = [1,0,0];
    break;
    default:
    color = [0,0,0];
    break;
    }
    color*100

    See attached image.

    Any ideas how to ensure each letter is always the same color?

    Thanks,
    Ari

    Filip Vandueren replied 6 years, 1 month ago 4 Members · 16 Replies
  • 16 Replies
  • Kalleheikki Kannisto

    June 9, 2019 at 3:04 pm

    How do you have this set up and what property are you applying this expression to?

    Kalleheikki Kannisto
    Senior Graphic Designer

  • Ari Grunzeweig

    June 9, 2019 at 9:26 pm

    Thanks so much for your reply. Please see the attached screenshot. Does that help clarify?

    Thanks gain!

    Thanks,
    Ari

  • Kalleheikki Kannisto

    June 10, 2019 at 3:37 am

    Ok, I see. That should work, as long as the original color of the type is black. You are adding a percentage of white to each of the RGB channels to the existing color. If the original color is something else, the target color gets added to the original color, resulting in something else.

    If you want to use colored lettering to start with, you’ll need two color animators with expression selector. The first color expression would add 100% black to any letters that you want to subsequently color. The second would be the same you currently have.

    Kalleheikki Kannisto
    Senior Graphic Designer

  • Ari Grunzeweig

    June 10, 2019 at 11:48 am

    Hi,

    Thanks very much, but I’m still not getting the result. My source text is black as is the ‘base color’ in the expression.
    I tried adding an animator before the one I had with color set to black, and the result is the same. This is the full code on the second animator:

    txt = text.sourceText;
    switch(txt[textIndex-1]){
    case "a":
    color = [255,128,0];
    break;
    case "b":
    color = [0,102,0];
    break;
    case "c":
    color = [0,102,102];
    break;
    case "d":
    color = [0,76,153];
    break;
    case "e":
    color = [76,0,153];
    break;
    case "f":
    color = [153,0,153];
    break;
    case "g":
    color = [204,0,102];
    break;
    case "h":
    color = [50,75,75];
    break;
    case "i":
    color = [153,0,0];
    break;
    case "j":
    color = [0,102,0];
    break;
    case "k":
    color = [0,102,102];
    break;
    case "l":
    color = [0,76,153];
    break;
    case "m":
    color = [0,153,153];
    break;
    case "n":
    color = [153,0,153];
    break;
    case "o":
    color = [204,0,102];
    break;
    case "p":
    color = [50,75,75];
    break;
    case "q":
    color = [153,0,0];
    break;
    case "r":
    color = [0,102,0];
    break;
    case "s":
    color = [0,102,102];
    break;
    case "t":
    color = [0,76,153];
    break;
    case "u":
    color = [76,0,153];
    break;
    case "v":
    color = [153,0,153];
    break;
    case "w":
    color = [204,0,102];
    break;
    case "x":
    color = [50,75,75];
    break;
    case "y":
    color = [204,0,102];
    break;
    case "z":
    color = [50,75,75];
    break;
    default:
    color = [22,40,69];
    break;
    }
    color*100/255

    Also attached is a new screenshot trying your suggested setup:

    Thanks!!

    Thanks,
    Ari

  • Kalleheikki Kannisto

    June 10, 2019 at 1:22 pm

    Works just fine for me.

    Kalleheikki Kannisto
    Senior Graphic Designer

  • Ari Grunzeweig

    June 10, 2019 at 1:47 pm

    Amazing!

    I can’t figure out what I am doing differently 🙁

    Thanks,
    Ari

  • Kalleheikki Kannisto

    June 11, 2019 at 4:20 am

    Here’s my file.

    13421_colorletters.aep.zip

    Kalleheikki Kannisto
    Senior Graphic Designer

  • Ari Grunzeweig

    June 12, 2019 at 2:20 am

    Thank you!

    Thanks,
    Ari

  • Kalleheikki Kannisto

    June 12, 2019 at 6:16 am

    Did you figure out what the difference was?

    Kalleheikki Kannisto
    Senior Graphic Designer

  • Ari Grunzeweig

    June 18, 2019 at 1:44 pm

    Thanks so much for your help. Unfortunately I’m totally at a loss.

    My structure and code looks just like yours, but still not working!

    Maybe there is something small I’m missing…

    My project is attached in case you are able to spot the problem.

    13446_ssorenschuldinertest.aep.zip

    Thanks again!

    Thanks,
    Ari

Page 1 of 2

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