Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #24335

Re: Specifying rgba colors as variables

From "Joey@still_Learning.invalid" <Joey@still_Learning.invalid>
Newsgroups comp.lang.javascript
Subject Re: Specifying rgba colors as variables
Date 2014-05-21 19:56 -0700
Message-ID <kipqn9phi090b3c307nosc4h7dlcos0kc2@4ax.com> (permalink)
References <n2gqn95hpq0p7ic4sukel3mnbjcm7naq1q@4ax.com> <89sea4gt79qi.1c3inz5fxuiax.dlg@40tude.net>

Show all headers | View raw


JJ wrote:

>On Wed, 21 May 2014 17:17:21 -0700, Joey@still_Learning.invalid wrote:
>> I'm trying to specify a group of colors as RGBa, but I'm lost.
>> 
>> Example code:
>> 
>> highlight_color = new Array(255,0,0);
>> 
>> for (var x = 0; x < width; x++) {
>> for (var y = 0; y < height; y++) {
>> 
>>  gray_avg =  ctx.getImageData(x, y, 1, 1).data[0];
>> 
>> if (gray_avg >= threshold) { gray = highlight_color; }
>> ....
>> } }
>> 
>> This works fine as shown, but I need to add the alpha channel to control
>> opacity. I've tried highlight_color = rgba(255,0,0,n) where 0<n<1, but it
>> throws an error. I've also tried  =new Array(255,0,0,n) to no avail.
>> Please...what is the correct syntax?
>> 
>> Thanks,
>
>The data property is an array of RGBA values. i.e.:
>[RR, GG, BB, AA,   RR, GG, BB, AA,   ...]
> ^ pixel #0        ^ pixel #1
>
>So, data[0] is the first pixel's red channel level, not the alpha channel.
>
>e.g.:
>
>var imgdata = ctx.getImageData(x, y, 1, 1).data;
>var red   = imgdata[0];
>var green = imgdata[1];
>var blue  = imgdata[2];
>var alpha = imgdata[3];

Thanks, JJ. 

I failed to communicate my issue. I was simply looking for syntax, but no
matter. I found a much easier and better workaround using css3 opacity on
the canvas.
-- 
Joey

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Specifying rgba colors as variables "Joey@still_Learning.invalid" <Joey@still_Learning.invalid> - 2014-05-21 17:17 -0700
  Re: Specifying rgba colors as variables JJ <duh@nah.meh> - 2014-05-22 08:07 +0700
    Re: Specifying rgba colors as variables "Joey@still_Learning.invalid" <Joey@still_Learning.invalid> - 2014-05-21 19:56 -0700
  Re: Specifying rgba colors as variables "Joey@still_Learning.invalid" <Joey@still_Learning.invalid> - 2014-05-21 19:57 -0700

csiph-web