<p><strong>Note:</strong> 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 <a href="http://forums.creativecow.net/readpost/227/25506" rel="nofollow">answered it perfectly</a>:</p>

<p>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...</p>

<pre><code>var myColor = rgbToHsl([159,27,41,255]/255);
</code></pre>

<p>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.</p>

CC BY-SA 3.0
2013-11-07T15:03:50.620Z
2013-11-07T15:03:50.620Z
itsmikem
<p>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 <a href="http://blogs.adobe.com/aftereffects/files/2012/06/After-Effects-CS6-Scripting-Guide.pdf?file=2012/06/After-Effects-CS6-Scripting-Guide.pdf" rel="noreferrer">Adobe After Effects Scripting Guide</a>.  Every method I can find that accepts a color value simply uses an array like that.</p>

<p>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.</p>

CC BY-SA 3.0
2013-11-07T19:27:13.437Z
I believe it needs an array of 4, so you'd need to include the alpha value as well.  Thanks for answering.
itsmikem
CC BY-SA 3.0
2013-11-07T19:52:00.903Z
@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
CC BY-SA 3.0
2013-11-07T00:25:47.143Z
2013-11-07T19:56:01.590Z
2013-11-07T19:56:01.590Z
AJ Henderson
<p>Using After Effects expressions, I can create a color reference by pick-whipping a color control and the result is:</p>

<pre><code>var rgb = rgbToHsl(effect("Color Control")("Color"));
</code></pre>

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

<pre><code>var rgb = rgbToHsl([159,27,41,1]);
</code></pre>

<p>...but this doesn't seem to work.  Is it possible?</p>

<after-effects>
After Effects: how to create a color via expressions
itsmikem
# After Effects: how to create a color via expressions

(Asked by: username_0 on 2013-11-06)

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?

**Tags:** after-effects


---

## 2 answers

### Answer by username_1 on 2013-11-07. Score: 6 | Accepted answer

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](http://blogs.adobe.com/aftereffects/files/2012/06/After-Effects-CS6-Scripting-Guide.pdf?file=2012/06/After-Effects-CS6-Scripting-Guide.pdf). 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.

> **Comments:**
> **username_0**: I believe it needs an array of 4, so you'd need to include the alpha value as well.  Thanks for answering.  
> **username_1**: @username_0 - 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.  

---

### Answer by username_0 on 2013-11-07. Score: 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.


---

