# How to extract RGB arguments as a list

Although the following lines of code work fine they are very awkward.

My questions are below

a = RGBColor[1, 0, 0]
b = RGBColor[0, 1, 0]


Is there a more compact way to construct ab?

Can the three entries of RGBColor[u,v,w] be extracted as a list?

Can the RGBColor argument be entered as a list RGB[{list}]?

ab = RGBColor[a[[1]] + b[[1]], a[[2]] + b[[2]], a[[3]] + b[[3]]]
Graphics[{{a, Disk[{0, .5}, .5]}, {b, Disk[{.25, .5}, .5]}, {ab,
Disk[{.5, .5}, .5]}}]

-
Try RGBColor[u,v,w] /. RGBColor->List. – b.gatessucks Oct 14 '12 at 11:27
This RGBColor[{r,g,b}] works. In general f@@{1,2,3} is equivalent to f[1,2,3]. – swish Oct 14 '12 at 11:34
Converting between RGBColor and List can be done in both directions with @@. If you want to convert several of them in a list, you can use @@@. For example: ab = RGBColor@@Total[List@@@{a,b}]. However note that for the most common colour calculations there already exist Blend, Lighter and Darker. – celtschk Oct 14 '12 at 12:06

Just use Apply (short form @@):

RGBColor @@ {1, 0, 0}

RGBColor[1, 0, 0]

List @@ RGBColor[1, 0, 0]

{1, 0, 0}


Okay, I actually missed the crux of your question because of the lack of formatting in the original.

You could get ab using Thread[a + b, RGBColor] -- see Thread.

-
Unfortunately I don't know how to add a formatted worksheet to a question. Sorry about the formatting. The built in functions like Blend do not combine. RGDColor(1,0,0) and. RGB(0.1.0) to. RGB(1,1,0). Using the above lists this is straightforward. THANKS TO ALL – PeterP Oct 14 '12 at 12:55

To make all the assignments on one line:

colors = {{0, 0, 0}, {1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
{black, red, green, blue} = RGB @@@ colors

red => RGB[1, 0, 0]

-
RGBColor rather than RGB? – cormullion Oct 17 '12 at 13:42