ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

How to randomly change color of characters

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Sabri Liefert
How to randomly change color of characters
on Mar 16, 2013 at 12:40:46 am

Hello,

i want randomly animate the colors of individual characters in a word
and after a few seconds the colors should transform to white.

I tried the text animator "hue" with randomize order and seed.
But that has the drawback that i have to use a fill color before. If i use white text the hue setting doesnt apply.
The hue setting is also very limited. If applied it doesnt change all letters. Aprox. 20% keep the fill color.

I think i have to apply an expression selector to the fill color. But i dont know how to define?

It would be ideal if i could define a color palette for the random colors.

Thank you very much!


Return to posts index

Dan Ebberts
Re: How to randomly change color of characters
on Mar 16, 2013 at 12:50:48 am

What do you mean by "randomly animate"?

Dan



Return to posts index

Sabri Liefert
Re: How to randomly change color of characters
on Mar 16, 2013 at 1:01:33 am

Hello Dan,

the individual characters should change colors randomly over time.


Return to posts index


Sabri Liefert
Re: How to randomly change color of characters
on Mar 16, 2013 at 1:11:46 am

This is a screen shot of my amateurish attempt to write the expression.
The code was only copied from an other project.
But miraculously worked half way.
I really dont understand the syntax for expression selectors.




Return to posts index


Dan Ebberts
Re: How to randomly change color of characters
on Mar 16, 2013 at 2:30:43 am

Try this:

text color = white;
Fill animator color = black;
Expression Selector Amount = 50%,50%,50%;
Expression Selector Amount expression:

seedRandom(textIndex,true);
w = wiggle(1,50);
linear(time,0,5,w,[0,0,0])


Dan



Return to posts index

Sabri Liefert
Re: How to randomly change color of characters
on Mar 16, 2013 at 3:31:36 am

That works!
Thank you very much!

Is it also possible to take colors from a palette for the random colors.
Like i have 5 defined colors which rotates randomly at each character?


Return to posts index


Dan Ebberts
Re: How to randomly change color of characters
on Mar 16, 2013 at 4:09:35 am

If you change the text color to black and the fill color to white, this will give you random colors for each character from a palette:

seedRandom(textIndex,true);
palette = [[100,0,0],[0,100,0],[0,0,100],[0,100,100],[100,0,100],[100,100,0],[100,50,0]];
// [red,blue,green,cyan,magenta,yellow,orange]
idx = Math.floor(random(palette.length));
palette[idx]


Dan



Return to posts index

Sabri Liefert
Re: How to randomly change color of characters
on Mar 16, 2013 at 1:10:07 pm

Thank you very much. That gives me a lot more control for the colors.

How can i rotate/random change the colors for the letters? The color palette should stay the same.


Return to posts index


Dan Ebberts
Re: How to randomly change color of characters
on Mar 16, 2013 at 3:05:12 pm

dur = .25; // length of time to hold each color
seedRandom(textIndex,true);
seg = Math.floor((time+random(999))/dur);
seedRandom(seg,true);
palette = [[100,0,0],[0,100,0],[0,0,100],[0,100,100],[100,0,100],[100,100,0],[100,50,0]];
// [red,blue,green,cyan,magenta,yellow,orange]
idx = Math.floor(random(palette.length));
palette[idx]


Dan



Return to posts index


Sabri Liefert
Re: How to randomly change color of characters
on Mar 16, 2013 at 3:44:40 pm

Thank you! Exactly what i wanted.

[But i can produce only the basic 6 colors. Doesnt matter which rgb values i enter in the brackets?]`
edit: I can produce rgb colors. It hasnĀ“t worked because i had another effect on the layer. sorry for that!


Return to posts index


Christian Hopkins
Re: How to randomly change color of characters
on Sep 23, 2013 at 12:47:27 pm

Just came across this thread - I realise it's old, might be useful to others.

I used Dan's code, which works perfectly, but you need to use RGB percentages (0-100), rather than the standard RGB values (0-255), there's a great convertor I found here: http://andylangton.co.uk/tools/colour-converter.

Hope this helps.


Return to posts index

David Cabestany
Re: How to randomly change color of characters
on Jun 21, 2016 at 4:02:46 pm

Thank you, thank you thank you.


Return to posts index


Daniel Blokland
Re: How to randomly change color of characters
on Oct 2, 2015 at 2:14:52 pm

Hi Dan,
I'm trying to do the same sort of thing but have specific colours for each letter (image basically a rainbow, each letter one colour), don't suppose you know how?

I tried altering you code but couldn't get the desired effect.
I was trying to combine it with "selectorValue * textIndex/textTotal" but couldn't get it to work.

I guess its the "idx = Math.floor(random(palette.length));" that needs changing but I haven't a clue to what.

seedOffset = effect("Slider Control")("Slider");
seedRandom (seedOffset+textIndex, true);
//seedRandom(index*textIndex, timeless=true); //works but not desired effect

palette = [[86,0,0],[100,38,18],[100,96,0],[0,73,0],[0,80,100],[39,40,99]];

idx = Math.floor(random(palette.length));
//idx = textIndex/textTotal;

palette[idx]




Return to posts index

Dan Ebberts
Re: How to randomly change color of characters
on Oct 2, 2015 at 4:10:29 pm

In what way is it not working?

Dan



Return to posts index

Daniel Blokland
Re: How to randomly change color of characters
on Oct 2, 2015 at 4:30:52 pm

At the moment each letter picks a random colour - that works.
But what I want is for each letter to pick the next colour in the array and then possibly loop around again?

The reason I'm trying to get this too work is that I kept getting instances where two or more letters next to each other had the same colour.

So I thought what might be useful is to have greater control - have each letter match the next colour in the aray.

Sure, there less dynamic ways of doing this but I have some scripts that allow me to replace text in AE so that I can easily localise/translate the text (something I have to do in my job a lot).
(A lot like variables in photoshop if you are familiar with those).

At the moment I'm having to translate a line of text that basically has rainbow colours - each letter follows on to the next colour in the rainbow and then loops, and doing it by hand is going to take a long time in all the languages :(

This script makes me feel so close yet so far :(
Anyway if you've got any ideas I'd really appreciate it!!

Thanks!


Return to posts index


Dan Ebberts
Re: How to randomly change color of characters
on Oct 2, 2015 at 4:44:41 pm

Like this maybe (with black text and white fill color animator):

palette = [[86,0,0],[100,38,18],[100,96,0],[0,73,0],[0,80,100],[39,40,99]];
idx = (textIndex-1)%palette.length;
palette[idx]


Dan



Return to posts index

Daniel Blokland
Re: How to randomly change color of characters
on Oct 5, 2015 at 2:09:37 pm

Thank you very much! Works perfectly for the rainbow.

I'm having a play around to see if I can get some other uses out of the code for future projects.
I was thinking of setting up a slider to highlight a single word in a paragraph - if I get it working I'll post it.

Anyway thanks again!!
D.


Return to posts index

Nikki van Onna
Re: How to randomly change color of characters
on Mar 25, 2016 at 12:28:18 pm

Hello Dan and Daniel,

I'm trying to get this working too, only I think I'm missing something, cause it's not really working.
So far I set everything up the way it's described earlier in this post:

dur = 1; // length of time to hold each color
seedRandom(textIndex,true);
seg = Math.floor((time+random(999))/dur);
seedRandom(seg,true);
palette = [[0,33,65],[93,11,14],[100,83,0]];
idx = Math.floor(random(palette.length));
palette[idx]

Now I also want to have a version where you never have the same color in a character next to each other.

When I change the palette like Dan suggested:

palette = [[0,33,65],[93,11,14],[100,83,0],[0,33,65],[93,11,14],[100,83,0]];
idx = (textIndex-1)%palette.length;
palette[idx]

It's not animating anymore, not jumping to other colors over time.

Do you maybe know a solution? That would be great.

In short:
I want letters to jump from one color to another, in a range of 3 colors over time.
But I never want the same color in characters that are next to each other.

Would be great if you could help me out.

Thanks in advance!

Nikki


Return to posts index


Marissa Joyner
Re: How to randomly change color of characters
on Mar 30, 2018 at 7:23:12 pm

Hi Dan,
What if I wanted to define the colors in the palette arrays with a few color pickers instead of numerical values? I tried this:
x=effect("Color Control")("Color");
x2=rgbToHsl(x);
y=effect("Color Control 2")("Color");
y2=rgbToHsl(y);
palette = [x2[0], x2[1], x2[2], x2[3]],[y2[0], y2[1], y2[2], y2[3]];
idx = (textIndex-1)%palette.length;
palette[idx]


I don't get an error but the color reverts to the original text color (black), I know I'm missing a piece here...

Thanks!
Marissa

x=effect("Color Control")("Color");
x2=rgbToHsl(x);
y=effect("Color Control 2")("Color");
y2=rgbToHsl(y);
palette = [x2[0], x2[1], x2[2], x2[3]],[y2[0], y2[1], y2[2], y2[3]];
idx = (textIndex-1)%palette.length;
palette[idx]


After Effects template maniac
https://www.fluxvfx.com/


Return to posts index

Dan Ebberts
Re: How to randomly change color of characters
on Mar 30, 2018 at 7:51:33 pm

Try it this way:

x=effect("Color Control")("Color");
y=effect("Color Control 2")("Color");
palette = [[x[0],x[1],x[2]]*100, [y[0],y[1],y[2]]*100];
idx = (textIndex-1)%palette.length;
palette[idx]


Dan



Return to posts index

Marissa Joyner
Re: How to randomly change color of characters
on Mar 30, 2018 at 8:59:50 pm

gosh darnit I knew it was something small, lol!

Thank you Dan!!!!!

After Effects template maniac
https://www.fluxvfx.com/


Return to posts index


Riccardo Sinti
Re: How to randomly change color of characters
on Jul 26, 2013 at 6:22:35 pm

When I apply this expression to Fill Color RGB I get the warning:

Class 'global' has no property or method named 'textIndex'

Am I not applying it to the right parameter?


Return to posts index

Dan Ebberts
Re: How to randomly change color of characters
on Jul 26, 2013 at 6:32:17 pm

That expression is for the Amount parameter of the Expression Selector. You should read the whole thread (if you haven't already).

Dan



Return to posts index

Riccardo Sinti
Re: How to randomly change color of characters
on Jul 26, 2013 at 6:55:23 pm

I still get "no property or method named 'text index'"


Return to posts index


Dan Ebberts
Re: How to randomly change color of characters
on Jul 26, 2013 at 6:59:09 pm

You should be using textIndex



Return to posts index

Riccardo Sinti
Re: How to randomly change color of characters
on Jul 26, 2013 at 7:01:23 pm

I am. My typo was in the post not the expression.


Return to posts index

Dan Ebberts
Re: How to randomly change color of characters
on Jul 26, 2013 at 7:08:03 pm

How about posting the entire expression?



Return to posts index


Riccardo Sinti
Re: How to randomly change color of characters
on Jul 26, 2013 at 7:55:59 pm

Its this, from the thread:

seedRandom(textIndex,true);
palette = [[100,0,0],[0,100,0],[0,0,100],[0,100,100],[100,0,100],[100,100,0],[100,50,0]];
// [red,blue,green,cyan,magenta,yellow,orange]
idx = Math.floor(random(palette.length));
palette[idx]


Return to posts index

Dan Ebberts
Re: How to randomly change color of characters
on Jul 26, 2013 at 8:02:05 pm

Hmm... I guess I'm stumped. If you have that pasted into the Amount property of your Expression Selector, you shouldn't get that message. I just pasted in what you posted and it works for me.

You will get that error though if you past an expression containing textIndex into any other property besides the Amount property.

Dan



Return to posts index

Riccardo Sinti
Re: How to randomly change color of characters
on Jul 26, 2013 at 8:05:53 pm

Oh Well, thanks for your help today, always appreciated always a pleasure.


Return to posts index


Gary txeusd
Re: How to randomly change color of characters
on Mar 26, 2013 at 4:05:41 am

Hi Dan,

Does this effect applies to CS6 ? I can't seem get it work ?


Return to posts index

Dan Ebberts
Re: How to randomly change color of characters
on Mar 26, 2013 at 3:13:10 pm

It should work fine in CS6 (in fact, I'm almost sure that's where I tested it).

Dan



Return to posts index

Fernando Huezo
Re: How to randomly change color of characters
on May 20, 2016 at 11:55:08 pm

Sorry for my question and my english.

Where I have to write the expression, in what parameter?

which animator he its using in te text?.


Return to posts index

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