Activity › Forums › Adobe After Effects Expressions › Changing colour based on another layers colour
-
Changing colour based on another layers colour
Posted by Chris Craig on August 7, 2008 at 5:20 amHi guys
I have a solid layer, used as a background, with a fill effect applied. When this fill colour is changed, to any one of the 6 limited colours in the pallet, I need to change the colour of some text, nested inside a comp, again to a limited pallet.
Eg, when my BG’s fill effect is 170,181,29, the text needs to be 155,10,181, if the BGs fill colour is 80,163,186, the text colour needs to be 155,10,181.
Thanks to all
Chris
Chris Craig replied 17 years, 9 months ago 2 Members · 7 Replies -
7 Replies
-
Chris Craig
August 7, 2008 at 6:13 amThis is what i thin i need to do, but its not working for me.
color1 = [0.6667, 0.7098, 0.1137, 1];
color2 = [0.6078, 0.0392, 0.3176, 1];
color3 = [0.3137, 0.6392, 0.7294, 1];n = thisComp.layer(“Controller”).effect(“BG Colour”)(“Color”);
if (n==color1) {
color2
} else if (n==color2) {
color1
} else if (n==color3) {
color2
} else {
0
}Thanks
Chris -
Dan Ebberts
August 7, 2008 at 1:22 pmTo make that work, you’ll have to test each of the r,g,b components of the color array like this:
if (n[0]==color1[0] && n[1]==color1[1] && n[2]==color1[2]) {
… and the numbers will have to match exactly. How do your background colors get decided? It might be simpler to use that same decision to drive both colors.
Dan
-
Chris Craig
August 7, 2008 at 8:51 pmHi Dan
I have a guide layer with a strict colour pallet, that the user will choose with the eye dropper. This effect is on a null, acting as the Master controller, and also on the BG and Text comp layers. The latter is expressed to the master controller Null.
Each BG colour has a correspsonding colour to it, which i wanted to make automatic.
There are about 8-10 different BG colours to choose from.
Thanks once again
Chris
-
Dan Ebberts
August 7, 2008 at 9:37 pmI think you’ll need to add a tolerance value to your comparisons, like this:
function colorMatch(a,b){
tolerance = .001;
for (i = 0; i < a.length; i++){ if (Math.abs(a[i] - b[i]) > tolerance) return false;
}
return true;
}color1 = [0.6667, 0.7098, 0.1137, 1];
color2 = [0.6078, 0.0392, 0.3176, 1];
color3 = [0.3137, 0.6392, 0.7294, 1];n = thisComp.layer(“Controller”).effect(“BG Colour”)(“Color”).value;
if (colorMatch(n,color1) ){
color2
} else if (colorMatch(n,color2)) {
color1
} else if (colorMatch(n,color3)) {
color2
} else {
[0,0,0,1]
}Dan
-
Chris Craig
August 7, 2008 at 11:37 pmThank you so much Dan. That is working perfectly.
Can you please tell me what you mean by tolerance though and what it is doing?
Thank you again
Chris -
Dan Ebberts
August 8, 2008 at 12:23 amSure. Looking at your color1 value, it was pretty clear that in the Fill effect that color is represented as [170,181,29]. When those values are retreived by an expression, they get normalized so they are between 0.0 and 1.0. So, for example, the 170 becomes 0.66666666…., which is clearly never going to exactly match your comparison value of 0.6667. So I just set up a little routine that says if the value retrieved from the Fill effect is within a tolerance of .001 from the value in your array, that’s close enough and is considered a match.
Dan
Reply to this Discussion! Login or Sign Up