FORUMS: list search recent posts

Link to another color and adjust it

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Nate Vander Plas
Link to another color and adjust it
on Jun 14, 2010 at 8:17:00 pm

I'm trying to figure out a way to link one color to another and then adjust that original color with an expression. Obviously it's easy to link one color property to another color property with the pick whip, but I then want to adjust the hue (and maybe the lightness, saturation, and alpha) of that original color. For instance, if the original color is blue, I'd like to automatically transform the new color to something complimentary, like orange. I've seen some stuff on hslToRgb, but was unsuccessful with adapting that to my situation. I'm working in CS3, if that matters.

Thanks,
Nate


Return to posts index

Dan Ebberts
Re: Link to another color and adjust it
on Jun 14, 2010 at 9:01:50 pm

I'm not quite sure what you're after, but this example would invert the color of the fill effect applied to another layer (named "master" in this example):

c = thisComp.layer("master").effect("Fill")("Color");
[1-c[0],1-c[1],1-c[2],c[3]]


Dan



Return to posts index

Filip Vandueren
Re: Link to another color and adjust it
on Jun 15, 2010 at 1:02:08 am

Or, if you just want to invert the hue:


c = thisComp.layer("master").effect("Fill")("Color");
hsl = rgbToHsl(c);
hue = (hsl[0]+0.5)%1;

compl = [hue, hsl[1], hsl[2], hsl[3]];
hslToRgb(compl);


this will get the color that is 0.5 or 180° across on the color wheel, but with the same saturation, brightness and alpha as the master.



Return to posts index


Nate Vander Plas
Re: Link to another color and adjust it
on Jun 17, 2010 at 7:01:18 pm

Thanks guys! That's what I was looking for Filip!



Return to posts index

Stephen Botting
Re: Link to another color and adjust it
on Sep 22, 2010 at 8:25:17 pm

Hi there,

I'm trying to do a similar thing but through extendscript, when I try to run it says that "Function hslToRgb is undefined"

Thanks,
Stephen

var inRgb = hslToRgb([0.5,0.5,0.5,0]);

http://www.43south.co.nz


Return to posts index

Dan Ebberts
Re: Link to another color and adjust it
on Sep 22, 2010 at 8:32:57 pm

Scripting doesn't have that function. I've seen the algorithm around somewhere -- it shouldn't be too hard to implement your own conversion function. Or, you could create a temporary layer, apply an expression that does the conversion, harvest the result, and delete the layer.


Dan



Return to posts index


Stephen Botting
Re: Link to another color and adjust it
on Sep 22, 2010 at 10:00:05 pm

Thanks Dan,

As you suggested I found a page with an algorithm to make the conversion.

When I try to run the script I wrote I get returned the error "| is undefined" with the line "if (S == 0) {" highlighted, if I comment out that "if" structure, I get the same error but on the "var rgb = new Array(3);"

Any suggestions?

Thanks,
Stephen

For some reason all my < symbols are appearing as < tried to fix it and it changes back.

function hslToRGB(H,S,L) {
//http://130.116.54.154/~monger/hsl-rgb.html

var rgb = new Array(3);
if (S == 0) {
rgb[0] = L;
rgb[1] = L;
rgb[2] = L;
return rgb;
}

if (L &lt; 0.5) var temp2 = L * (1.0+S);
if (l >= 0.5) var temp2 = L+S-L*S;

var temp1 = 2.0*L - temp2;
H = H/360;


var temp3 = new Array(3);
temp3[0] = H+1.0/3.0;
temp3[1] = H;
temp3[2] = H-1.0/3.0;

for (i=0; i &lt; temp3.length; i++) {
if (temp3[i] &lt; 0) temp3[i] = temp3[i] + 1.0;
if (temp3[i] > 1) temp3[i] = temp3[i] - 1.0;

if (6.0 * temp3[i] &lt; 1) {
rgb[i] = temp1 +(temp2-temp1) * 6.0 * temp3[i];
} else if (2.0*temp3[i] &lt; 1) {
rgb[i] = temp2;
} else if (3.0*temp3[i] &lt; 2) {
rgb[i] = temp1+(temp2-temp1)*((2.0/3.0)-temp3[i])*6.0;
} else {
rgb[i] = temp1;
}
}
return rgb;
}


http://www.43south.co.nz


Return to posts index

Dan Ebberts
Re: Link to another color and adjust it
on Sep 22, 2010 at 10:53:35 pm

This line is causing the problem:

if (l >= 0.5) var temp2 = L+S-L*S;

It should be

if (L >= 0.5) var temp2 = L+S-L*S;


Dan



Return to posts index

Ivan Zornic
Re: Link to another color and adjust it
on May 5, 2017 at 3:17:35 pm

Hi there,
I know that this tread is bit old but I couldn't find inverse function: RgbToHsl().
I have created JS copy of function provided here:
http://wiki.secondlife.com/wiki/Color_conversion_scripts#RGB_to_HSL
but it returns some strange values.

Any help will be appreciated.

function RgbToHsl(rgb){

var r = rgb[0] / 255;
var g = rgb[1] / 255;
var b = rgb[2] / 255;

var h;
var s;
var l;

var max;
var min;

// Looking for the max value among r, g and b
if (r > g && r > b) max= r;
else if (g > b) max = g;
else max = b;

// Looking for the min value among r, g and b
if (r &lt; g && r &lt; b) min = r;
else if (g &lt; b) min = g;
else min = b;

l = (max + min) / 2;

if (max == min){
h = 0.0;
s = 0.0;
}else{

var d = max - min;

if (l > 0.5) s = d / (2 - max - min);
else s = d / (max + min);

if (max == r) {
if (g &lt; b) h = (g - b) / d + 6;
else h = (g - b) / d;
}
else if (max == g)
h = (b - r) / d + 2;
else
h = (r - g) / d + 4;

h /= 6;
}

return [h, s, l];
}


Return to posts index

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