Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #24331 > unrolled thread
| Started by | "Joey@still_Learning.invalid" <Joey@still_Learning.invalid> |
|---|---|
| First post | 2014-05-21 17:17 -0700 |
| Last post | 2014-05-21 19:57 -0700 |
| Articles | 4 — 2 participants |
Back to article view | Back to comp.lang.javascript
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
| From | "Joey@still_Learning.invalid" <Joey@still_Learning.invalid> |
|---|---|
| Date | 2014-05-21 17:17 -0700 |
| Subject | Specifying rgba colors as variables |
| Message-ID | <n2gqn95hpq0p7ic4sukel3mnbjcm7naq1q@4ax.com> |
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,
--
Joey
[toc] | [next] | [standalone]
| From | JJ <duh@nah.meh> |
|---|---|
| Date | 2014-05-22 08:07 +0700 |
| Message-ID | <89sea4gt79qi.1c3inz5fxuiax.dlg@40tude.net> |
| In reply to | #24331 |
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];
[toc] | [prev] | [next] | [standalone]
| From | "Joey@still_Learning.invalid" <Joey@still_Learning.invalid> |
|---|---|
| Date | 2014-05-21 19:56 -0700 |
| Message-ID | <kipqn9phi090b3c307nosc4h7dlcos0kc2@4ax.com> |
| In reply to | #24333 |
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
[toc] | [prev] | [next] | [standalone]
| From | "Joey@still_Learning.invalid" <Joey@still_Learning.invalid> |
|---|---|
| Date | 2014-05-21 19:57 -0700 |
| Message-ID | <7qpqn953sccjs8laekocdj90e0r7kemm5e@4ax.com> |
| In reply to | #24331 |
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?
>
Alternative method employed. Issue resolved
--
Joey
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web