FORUMS: list search recent posts

I need to assign specific colors to specific characters in a text layer

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Lauren Roundy
I need to assign specific colors to specific characters in a text layer
on Aug 28, 2015 at 4:36:47 pm

I have a wall of text that looks something like this: "ACGTGTCATCTAGACGT" only with TONS of different sequences like that for lines and lines and lines of text in a text box. I need the A's to all be green, the C's to all be blue, the T's to all be yellow, and the G's to all be red. Really, the actual colors don't matter. I want to be able to change the color, but always keep the same letters matching with the same color.

Is there an expression that I can use that basically assigns a specific hex # or RGB value to specific characters within a long block of text?

I plan on copying and pasting different non-random strings of those same four letters into various parts of the project, but I always need the A's to be green, etc...

Thanks!

Lauren


Return to posts index

Dan Ebberts
Re: I need to assign specific colors to specific characters in a text layer
on Aug 28, 2015 at 5:37:49 pm

Try this.

Add a fill color animator.
Set the color to white.
Add an expression selector.
Add this expression to the Amount property of expression selector:


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



Dan



Return to posts index

Lauren Roundy
Re: I need to assign specific colors to specific characters in a text layer
on Aug 28, 2015 at 6:03:42 pm

Worked like a charm. Thank you so much!


Return to posts index


Lauren Roundy
Re: I need to assign specific colors to specific characters in a text layer
on Aug 28, 2015 at 6:09:55 pm

Wait, I changed my mind. I'm confused as to how to change the colors to any RGB value I want. What is the "color*100" line doing exactly?


Return to posts index

Dan Ebberts
Re: I need to assign specific colors to specific characters in a text layer
on Aug 28, 2015 at 6:24:58 pm
Last Edited By Dan Ebberts on Aug 28, 2015 at 6:25:41 pm

The expression selector is expecting values between 0 and 100 for each color channel. I just used values between 0 and 1 for the arrays because expressions expect color channel values between 0 and 1, but I could just have easily done it this way for red:

color = [100,0,0]

and leave off the *100 at the end.

If you wanted to use values between 0 and 255, you could do it like this:

color = [255,0,0];

and have this at the end:

color*100/255

Dan



Return to posts index

Lauren Roundy
Re: I need to assign specific colors to specific characters in a text layer
on Aug 28, 2015 at 6:26:37 pm

Awesome, thanks! We figured it out a slightly different way, but it worked out. The thing that was confusing was that to make it work fully, the original text layer color has to be set to black. Ours was set to grey, so it was giving us less saturated colors than we wanted.

Thanks again for your help!


Return to posts index


Dan Ebberts
Re: I need to assign specific colors to specific characters in a text layer
on Aug 28, 2015 at 6:31:37 pm

Ah yes, sorry--I forgot to mention that the text has to be black. Glad you got it worked out.

Dan



Return to posts index

Lauren Roundy
Re: I need to assign specific colors to specific characters in a text layer
on Aug 28, 2015 at 6:43:46 pm

Two more things:

I tried it with and without the "color*100/255" and I'm getting the same result, which tells me that it isn't necessary and is redundant code.

Second, I want to take this one step further and use a "master control" layer that has four fill effects (or some equivalent color effect with a color picker color option) and then use the pick whip to link the RGB arrays in the expression to the master control layer. This way, I can easily change, using the color eye drop picker in AE, the color that the expression is referencing without having to type in RGB numbers. How would this be accomplished?

You're the best!


Return to posts index

Dan Ebberts
Re: I need to assign specific colors to specific characters in a text layer
on Aug 28, 2015 at 6:52:51 pm

Like this:


txt = text.sourceText;
switch(txt[textIndex-1]){
case "A":
color = thisComp.layer("master control").effect("Color Control 1")("Color");
break;
case "C":
color = thisComp.layer("master control").effect("Color Control 2")("Color");
break;
case "T":
color = thisComp.layer("master control").effect("Color Control 3")("Color");
break;
case "G":
color = thisComp.layer("master control").effect("Color Control 4")("Color");
break;
default:
color = [0,0,0,1];
break;
}
[color[0],color[1],color[2]]*100


Dan



Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]