Re: Convert Hue[] to RGBColor[] and backwards
- To: mathgroup at smc.vnet.net
- Subject: [mg103468] Re: Convert Hue[] to RGBColor[] and backwards
- From: "Alexey Popkov" <lehin.p at gmail.com>
- Date: Wed, 23 Sep 2009 07:25:33 -0400 (EDT)
- References: <BLU0-SMTP4514449534FFC9FA25CF7EADC0@phx.gbl>
- Reply-to: "Alexey Popkov" <lehin.p at gmail.com>
Thank you. It is just that I need. ----- Original Message ----- From: "Alexander Elkins" <alexander_elkins at hotmail.com> To: <hanlonr at cox.net>; <lehin.p at gmail.com> Sent: Wednesday, September 23, 2009 2:32 AM Subject: [mg103468] Re: Convert Hue[] to RGBColor[] and backwards > ?ToColor > > ToColor[color, form] converts color to form if form is GrayLevel, RGBColor > or CMYKColor. > Otherwise form[color] is evaluated and the result is expected to be a > valid > color directive. > > In both v6 and v7 form can also be Hue. For example: > In[1]:= ToColor[Hue[0.1333333, 0.625, 0.8], RGBColor] > Out[1]= RGBColor[0.8, 0.7, 0.3] > > In[2]:= ToColor[RGBColor[0.8, 0.7, 0.3], Hue] > Out[2]= Hue[0.133333, 0.625, 0.8] > > Of course it is possible to roll one's own ToHue function: > > In[3]:= ToHue[color_RGBColor] := Module[{rgb, m, n}, rgb = Clip[#, {0, 1}] > & > /@ color; > m = Max @@ rgb + 0.; n = Min @@ rgb; > If[m == n, Hue[0., 0., m], > Hue[Function[{r, g, b}, > Which[r == m, Mod[(g - b)/(m - n), 6], g == m, (b - r)/(m - n) + 2, > True, (r - g)/(m - n) + 4]/6] @@ rgb, 1 - n/m, m]]]; > > In[4]:= ToHue[RGBColor[0.8, 0.7, 0.3]] > Out[4]= Hue[0.133333, 0.625, 0.8] > > - Alexander Elkins > > "Bob Hanlon" <hanlonr at cox.net> wrote in message > news:h97msg$7fi$1 at smc.vnet.net... >> >> In v7 there is ColorConvert >> >> Table[ColorConvert[Hue[h], "RGBColor"], {h, 0, 1, 0.1}] >> >> > {RGBColor[1.,0.,0.],RGBColor[1.,0.6,0.],RGBColor[0.8,1.,0.],RGBColor[0.2,1., > 0.],RGBColor[0.,1.,0.4],RGBColor[0.,1.,1.],RGBColor[0.,0.4,1.],RGBColor[0.2, > 0.,1.],RGBColor[0.8,0.,1.],RGBColor[1.,0.,0.6],RGBColor[1.,0.,0.]} >> >> ColorConvert[#, "Hue"] & /@ % >> >> > {Hue[0.,1.,1.],Hue[0.1,1.,1.],Hue[0.2,1.,1.],Hue[0.3,1.,1.],Hue[0.4,1.,1.],H > ue[0.5,1.,1.],Hue[0.6,1.,1.],Hue[0.7,1.,1.],Hue[0.8,1.,1.],Hue[0.9,1.,1.],Hu > e[0.,1.,1.]} >> >> As can be seen, the conversions are somewhat approximate. >> >> >> Bob Hanlon >> >> ---- Alexey Popkov <lehin.p at gmail.com> wrote: >> >> ============= >> Hello, >> I have not found in the Documentation any information on relation >> between Hue[] and RGBColor[] representations of color. How can I >> convert one to another? >> >> >> >> >> -- >> >> Bob Hanlon >> >> > > >