Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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]}}]
share|improve this question
1  
Try RGBColor[u,v,w] /. RGBColor->List. –  b.gatessucks Oct 14 '12 at 11:27
1  
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
2  
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
add comment

2 Answers

Just use Apply (short form @@):

RGBColor @@ {1, 0, 0}
RGBColor[1, 0, 0]
List @@ RGBColor[1, 0, 0]
{1, 0, 0}

See: Applying Functions to Lists and Other Expressions


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.

share|improve this answer
    
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
add comment

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]
share|improve this answer
    
RGBColor rather than RGB? –  cormullion Oct 17 '12 at 13:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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