Activity › Forums › Adobe After Effects Expressions › Expression to randomly change color of individual characters of a text layer
-
Expression to randomly change color of individual characters of a text layer
Posted by Vlad Mecne on March 11, 2025 at 4:57 pmHi there,
Have the text layer attached. Trying to find an expression that would randomly change the color of the individual characters, among a set of predetermined colors, every number of frames (say 5).</font>
Using an expression from Andy Ford (https://www.youtube.com/watch?v=TK8eFx8IAYA) to randomly change the color of the whole text but not for the characters.
If you have any idea 🙂 Danke!
G.
Some contents or functionalities here are not available due to your cookie preferences!This happens because the functionality/content marked as “Google Youtube” uses cookies that you choosed to keep disabled. In order to view this content or use this functionality, please enable cookies: click here to open your cookie preferences.
Dan Ebberts replied 1 year, 4 months ago 3 Members · 8 Replies -
8 Replies
-
Yoan Boisjoli
March 11, 2025 at 6:20 pmGuttentag Vlad!
I managed to do it via multiple text fill color (RGB) animators (one for each color).
Then I added an expression selector that goes like this to aim at each character:
(textIndex % 5 == 0) ? 100 : 0; //5 is the amount of color choices and 0 is the char indexThe zero here is the one I’m changing on each animators.
Then I’m having the colors changing every 5 frames via an expression on the color property of the color animator.seedRandom(index, true); // Ensures each layer has a unique random sequence
var colors = [
effect("Color Control")(1),
effect("Color Control 2")(1),
effect("Color Control 3")(1),
effect("Color Control 4")(1),
effect("Color Control 5")(1)
];
colors[Math.floor(timeToFrames(time) / 5 + random(0, 5)) % colors.length]I’m uploading the after effects file. Hope it helps !
-
Dan Ebberts
March 11, 2025 at 6:52 pmThis Source Text expression appears to work:
numFrames = 5; // change colors every 5 frames
c1 = effect("Color Control 1")("Color");
c2 = effect("Color Control 2")("Color");
c3 = effect("Color Control 3")("Color");
c4 = effect("Color Control 4")("Color");
c5 = effect("Color Control 5")("Color");
colors = [c1,c2,c3,c4,c5];
f = timeToFrames(time);
seed = Math.floor(f/numFrames);
seedRandom(seed,true);
myExpr = "style";
for (i = 0; i < value.length; i++){
myExpr += ".setFillColor(colors[Math.floor(random(colors.length))]," + i + ",1)";
}
eval(myExpr) -
Yoan Boisjoli
March 11, 2025 at 7:51 pmGeez Dan! I took the complicated route ! hahaha yeah that works perfectly.
Is this using the new Per Character expression in 2025?
-
Vlad Mecne
March 11, 2025 at 8:46 pmHi Dan, Yoan,
Both killing it. Wasn’t to make Dan’s expression work but may need to take a second stab at it.
Yoan – yours work fine but somehow the frequency of change isn’t applying the same to every character. Some letters change every other frames or around, others fine. AE file is attached if helpful.
Keeping at it and letting you know once something works well.
Danke!
-
Vlad Mecne
March 13, 2025 at 6:29 pm@Dan tried yours again – working really well. Many thanks!
Is there a way for the next color pick of each letter to not repeat the color it’s already using. Something like Color N+1 not equal to Color N?
Again thanks so much for helping out 🙂
-
Dan Ebberts
March 13, 2025 at 7:04 pmDo you mean so that each letter has a color different than the one next to it, or so that a letter doesn’t get the same color for two consecutive periods?
-
Vlad Mecne
March 13, 2025 at 7:10 pmSo that a letter doesn’t get the same color for two consecutive periods.
-
Dan Ebberts
March 13, 2025 at 7:51 pmThat’s considerably more complicated and will bog down in a longer comp because of the additional processing that needs to happen at each successive frame. Try this:
numFrames = 5; // change colors every 5 frames
c1 = effect("Color Control 1")("Color");
c2 = effect("Color Control 2")("Color");
c3 = effect("Color Control 3")("Color");
c4 = effect("Color Control 4")("Color");
c5 = effect("Color Control 5")("Color");
colors = [c1,c2,c3,c4,c5];
f = timeToFrames(time);
curPeriod = Math.floor(f/numFrames);
colorIdx = [];
seedRandom(0,true);
for (i = 0; i < value.length; i++){
colorIdx.push(Math.floor(random(colors.length)));
}
i = 1;
while (i <= curPeriod){
seedRandom(i,true);
for (j = 0; j < value.length; j++){
temp = colorIdx[j] + Math.floor(random(colors.length-1)) + 1;
colorIdx[j] = temp%colors.length;
}
i++;
}
myExpr = "style";
for (i = 0; i < value.length; i++){
myExpr += ".setFillColor(colors[colorIdx[" + i + "]]," + i + ",1)";
}
eval(myExpr)
Reply to this Discussion! Login or Sign Up