Activity › Forums › Adobe After Effects Expressions › How to randomly change color of characters
-
Christian Hopkins
September 23, 2013 at 12:47 pmJust 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: https://andylangton.co.uk/tools/colour-converter.
Hope this helps.
-
Daniel Blokland
October 2, 2015 at 2:14 pmHi 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 effectpalette = [[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]
-
Daniel Blokland
October 2, 2015 at 4:30 pmAt 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!
-
Dan Ebberts
October 2, 2015 at 4:44 pmLike 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
-
Daniel Blokland
October 5, 2015 at 2:09 pmThank 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. -
Nikki Van onna
March 25, 2016 at 12:28 pmHello 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
-
Fernando Huezo
May 20, 2016 at 11:55 pmSorry for my question and my english.
Where I have to write the expression, in what parameter?
which animator he its using in te text?.
-
Marissa Joyner
March 30, 2018 at 7:23 pmHi 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!
Marissax=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/
Reply to this Discussion! Login or Sign Up