ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Expression for color control

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Pierre-Alexis Tremblay
Expression for color control
on Mar 15, 2009 at 2:02:40 pm

Hi, 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.


Return to posts index

Filip Vandueren
Re: Expression for color control
on Mar 15, 2009 at 3:38:40 pm

For 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.




Return to posts index

Pierre-Alexis Tremblay
Re: Expression for color control
on Mar 15, 2009 at 3:58:01 pm

Works fine! Thanks a lot.



Return to posts index


Gabriel Netto
Re: Expression for color control
on Mar 10, 2010 at 4:44:20 pm

I'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"
}


Return to posts index

James Hawkins
Re: Expression for color control
on Feb 1, 2011 at 10:50:02 pm

This 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.


Return to posts index

Dan Ebberts
Re: Expression for color control
on Feb 1, 2011 at 11:30:30 pm

Just make this the first line of the expression:

seedRandom(index,true);


Dan



Return to posts index


Jarek Borzecki
Re: Expression for color control
on Jan 29, 2013 at 10:39:08 pm

Hi 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


Return to posts index

Dan Ebberts
Re: Expression for color control
on Jan 29, 2013 at 10:46:09 pm

You 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



Return to posts index

Jarek Borzecki
Re: Expression for color control
on Jan 29, 2013 at 11:12:08 pm

hi 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")


Return to posts index

Jarek Borzecki
Re: Expression for color control
on Jan 29, 2013 at 11:20:09 pm

hi 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")


Return to posts index

Dan Ebberts
Re: Expression for color control
on Jan 29, 2013 at 11:35:51 pm

I 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



Return to posts index

Jarek Borzecki
Re: Expression for color control
on Jan 29, 2013 at 11:40:20 pm

thanks Dan, I'll check again everything...


Return to posts index

Jarek Borzecki
Re: Expression for color control
on Jan 29, 2013 at 11:52:08 pm

it's working fine now! my fault, dont ask what happened please

thank you again for your help!
J


Return to posts index

Goran Milovanovic
Re: Expression for color control
on Mar 13, 2013 at 12:07:38 pm

This is amazing script. Is it possible that instead of random color I use float values in range from example -25,453 to 25.453. -value is blue and +value would be red like gradient. I have around 700 float values that i want to change into colors per frame.

I am new to scripting so I would appreciate any help
Thanks in advance


Return to posts index

Rob McDougall
Re: Expression for color control
on Jun 12, 2013 at 8:49:12 pm

Hello all,

I'm wanting to control a colour scheme using a slider.

So, if slider = 1

circle = red

square = green

triangle = blue

when the slider value increased to 2 each fill layer would move on to the next object...

circle = blue

square = red

triangle = green

So, I understand that I need to make a range of colour controls, then I want to store them in a list. What I don't understand is how to chose a specific colour (or member of the index) based on the slider value. Any suggestions?


Return to posts index

Dan Ebberts
Re: Expression for color control
on Jun 12, 2013 at 9:02:23 pm

Assuming your colors are stored in an array named "colors", and your slider control value is 'slider', you could calculate an index for each layer like this:

idx = ((index-1) + Math.floor(slider))%colors.length;
colors[idx]


You might have to modify the index-1 if your shape layers aren't at the top of the layer stack.

Dan



Return to posts index

Brandt Weisman
Re: Expression for color control
on Jul 25, 2013 at 8:43:38 pm

This works great. Is there anyway to control the duration of the color cycle. Every frame is a bit fast for my needs. Thanks.


Return to posts index

Matthew Newcomb
Re: Expression for color control
on Aug 22, 2013 at 5:41:28 pm

Hi, Not sure if you ever got an answer to your question, but if you did would you mind sharing it with me? I'm not very good at expressions yet!


Return to posts index

Will McMillian
Re: Expression for color control
on Sep 6, 2016 at 12:32:04 am

To make this last longer than a single frame, this worked for me; pre-comp and enable time-remapping to your new layer. Then apply this expression to the time re-mapping:

framesToTime(Math.floor(timeToFrames()/4));


Return to posts index

Deepak Kumar
Re: Expression for color control
on Oct 4, 2013 at 9:34:02 am

How to use this Scripts. Can you tell me what i have to do.


Return to posts index

Gerri Gut
Re: Expression for color control
on Apr 7, 2017 at 10:06:38 am

Hey,
im using your code just added a little time-tweak. I have this Code on an Adjustment Layer because i have multiple layers that i want to change between the colors - but randomly in time. right know everything is changing together.. i hope you understand what i mean.

i think it could work about the "index"?!

-- thank you --

here the code again (just added this holdTime-lines)

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 "Farbe"
if (l.effect(i)(1).name=="Farbe") {
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) {
holdTime = .5;
seed = Math.floor(time/holdTime);
seedRandom(seed,true);

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;
}


Return to posts index

Dan Ebberts
Re: Expression for color control
on Apr 7, 2017 at 2:13:56 pm

Try changing this part:

holdTime = .5;
seed = Math.floor((time+preRun)/holdTime);

to this:

holdTime = .5;
seedRandom(index,true);
preRun = random(holdTime);
seed = Math.floor((time+preRun)/holdTime);


Dan



Return to posts index

Dan Ebberts
Re: Expression for color control
on Apr 7, 2017 at 2:20:42 pm

Oops, I meant change this part:

holdTime = .5;
seed = Math.floor(time/holdTime);


Dan



Return to posts index

Greta Sennekamp
Re: Expression for color control
on Apr 7, 2017 at 2:44:28 pm

same result as before... maybe is added something in the wrong place?

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 "Farbe"
if (l.effect(i)(1).name=="Farbe") {
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) {
holdTime = .5;
seedRandom(index,true);

preRun = random(holdTime);
seed = Math.floor((time+preRun)/holdTime);

seedRandom(seed,true);

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;
}



Return to posts index

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