6

Using After Effects expressions, I can create a color reference by pick-whipping a color control and the result is:

var rgb = rgbToHsl(effect("Color Control")("Color"));

But, I want to avoid using a color control, and simply instantiate a color through code:

var rgb = rgbToHsl([159,27,41,1]);

...but this doesn't seem to work. Is it possible?

migrated from graphicdesign.stackexchange.com Nov 6 '13 at 18:08

This question came from our site for Graphic Design professionals, students, and enthusiasts.

4

From what I'm reading, it looks like it may just be [R,G,B] where each value is a floating point number between 0 and 1. I'm looking in the Adobe After Effects Scripting Guide. Every method I can find that accepts a color value simply uses an array like that.

Update: While certain scripting methods take a 3 parameter RGB value, other expressions require RGBA or HSLA. In these cases, there will be a forth parameter for Alpha (ie, transparency) where 1 is fully opaque (a good default value) and 0 is fully transparent. If you get an error with one format, I suggest trying the other and if you get unexpected values, check if the input expects HSL or RGB.

  • I believe it needs an array of 4, so you'd need to include the alpha value as well. Thanks for answering. – itsmikem Nov 7 '13 at 19:27
  • 1
    @itsmikem - for rgbToHsl it does appear it takes a rgba value, so if you need the color in hsla, then you would want to do 4 values with the final being the alpha. If you just want an RGB color, it only uses 3, but I'm not sure if rgbToHsl will work with that. – AJ Henderson Nov 7 '13 at 19:52
2

Note: I'm new to this exchange, and I posted this to the graphic design exchange, but my question got migrated here. I thought it had been deleted, so I proceeded to post it on Creative Cow. I got a great answer there, and I'd like to give credit to Kevin Camp, who answered it perfectly:

your rgb values need to be in values 0-1 rather than 0-255. so if you want to stick with entering 0-255 values you just need to divide that array by 255...

var myColor = rgbToHsl([159,27,41,255]/255);

note, i did assume that you wante the alpha component to be full (255) not 1. if i guessed wrong, change the alpha back to 1.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.