Activity › Forums › Adobe After Effects Expressions › Expression for color control
-
Expression for color control
Posted by Pierre-alexis Tremblay on March 15, 2009 at 2:02 pmHi, I like to use expressions but am not very good at programming.
I’m trying to figure out a way to randomly assign a color from a custom color palette (few colors, let’s say maximum 12) to a shape layer. Thanks for helping.Andy Teel replied 6 years, 10 months ago 15 Members · 25 Replies -
25 Replies
-
Filip Vandueren
March 15, 2009 at 3:38 pmFor versatility and easy tweaking, we’ll store the colors in a control layer:
Create a Null object called ‘Colors’
Add as many “Expression Controls -> Color Controls” to that as you need.Add this expression to the color you want to control (probably the fill of your shape layer):
l=thisComp.layer("Colors");// retrieve colors stored in the color controls
i=1;
colors=[];try {
while(l.effect(i)) {
// an effect exists, but is it a color control ?
// We'll check if it's first parameter is called "Color"
if (l.effect(i)(1).name=="Color") {
colors.push(l.effect(i)(1).value); // store the color in a list
}
i++;
}
} catch (e) {}// Now if the list of colors contains any elements
// we will get a random value from the list.if (colors.length) {
r=Math.floor(random(colors.length)); // a random integer
colors[r]; // return the color} else {
// the list of colors is empty, so we use the existing color value.
value;
}
This expression will change the color every frame.
Perhaps not what you need, so let us know what you want to do with the random values. -
Gabriel Netto
March 10, 2010 at 4:44 pmI’m an expressions newby so…
Could someone help me with this question?I’m working on a CARD project based on 4 variables (CS3). As you will see they are on an external txt and code is located on a text layer. I’m using “Hoyle Playing Cards” font symbols and that’s why they need to change: s = “q” (s for spades is q character, etc.)
My problem is that I need to alternate between red and black font colors. (spades and hearts have to be red, spades and clubs have to be black) but I just can’t figure out how to change this colors using expressions… I’ve tried to use fill but I don’t know how to set it’s color property via expressions.
Maybe a Color Control or a sampleImage() effect?
Any help is really appreciated!!!
Thanks in advance!Gabriel Netto
//Here's my code:s = "q";
c = "w";
d = "e";
h = "r";
eval(thisComp.layer("LER_TXT").text.sourceText.value);
myPath = "/MyHD/Prog1.txt";
try{
$.evalFile (myPath);
eval(thisComp.name)[1];
}catch (err){
"not found"
} -
James Hawkins
February 1, 2011 at 10:50 pmThis is a great technique! But what would one need change in order to have it hold the chosen color for the duration? Rather then change every frame.
-
Dan Ebberts
February 1, 2011 at 11:30 pmJust make this the first line of the expression:
seedRandom(index,true);
Dan
-
Jarek Borzecki
January 29, 2013 at 10:39 pmHi All,
i’m completelty green with svripting, really appreciate if you can help me as well.In main comp i’ve created null object with expression control>color controll, and there are two effects ‘fill’ for example ‘font1’ and ‘font2’
i want to change color for font1 in this comp – this is working fine for me, but i have problem when i’m trying to controll color for font2 inside another compostition..is it possible or can i only controll colors/effects by expressions inside the same composition?thank you for your help
J -
Dan Ebberts
January 29, 2013 at 10:46 pmYou have an expression for Fill effect Color in the other comp linked to the color control in the main comp, is that correct? That should work just fine.
Dan
-
Jarek Borzecki
January 29, 2013 at 11:12 pmhi Dan,
correct,!Main_Composition with Colour Control layer (my null object) and Artwork Colour – my fill effect
and another comp ‘WMan’ with fill effect
I’m receiving this error:
Error occured at line1.
Comp: ‘Wman’
layer: 2 (w1_ai)
Property: ‘Color’comp("!Main_Composition").layer("Colour Control").effect("Artwork Colour")("Color") -
Jarek Borzecki
January 29, 2013 at 11:20 pmhi Dan,
correct,!Main_Composition with Colour Control layer (my null object) and Artwork Colour – my fill effect
and another comp ‘WMan’ with fill effect
I’m receiving this error:
Error occured at line1.
Comp: ‘Wman’
layer: 2 (w1_ai)
Property: ‘Color’comp("!Main_Composition").layer("Colour Control").effect("Artwork Colour")("Color") -
Dan Ebberts
January 29, 2013 at 11:35 pmI just tried it with your comp, layer, and effect names, and it works fine for me. I have no idea what it’s not working for you.
Dan
Reply to this Discussion! Login or Sign Up