home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / e / e032 / 3.ddi / FILES / GRAPHICS.PAK / COLORS.M < prev    next >
Encoding:
Text File  |  1992-07-29  |  5.0 KB  |  169 lines

  1.  
  2. (* Copyright 1988 Wolfram Research Inc. *)
  3.  
  4. (*:Title: Colors *)
  5.  
  6. (*:Author: Wolfram Research, Inc. *)
  7.  
  8. (*:Version: Mathematica 2.0 *)
  9.  
  10. (*:Keywords:
  11.        CMYColor, YIQColor, HLSColor
  12. *)
  13.  
  14. (*:Sources: none. *)
  15.  
  16. (*:Requirements: none. *)
  17.  
  18. (*:Warnings: none. *)
  19.  
  20. (*:Summary: This package contains functions that convert from various
  21. color systems into an RGBColor. It also allows you to give a color name
  22. (such as Blue) and the appropriate RGBColor is produced.
  23. *)
  24.  
  25. BeginPackage["Graphics`Colors`"]
  26.  
  27. CMYColor::usage = "CMYColor[c,m,y] represents a color in the CMY 
  28.     (cyan-magenta-yellow) system."
  29.  
  30. YIQColor::usage = "YIQColor[y,i,q] represents a color in the YIQ 
  31.     (NTSC video form) system."
  32.  
  33. HSBColor::usage = "HSBColor[h,s,b] is obsolete. See Hue[]." 
  34.  
  35. HLSColor::usage = "HLSColor[h,l,s] represents a color in the HLS 
  36.     (hue-lightness-saturation) system." 
  37.  
  38. Map[(#::"usage" = 
  39.     StringJoin[ToString[#]," is a color given in the RGBColor system."
  40.    ])&,
  41.    { Aquamarine, Black, Blue, BlueViolet, Brown, CadetBlue, Coral,
  42.      CornflowerBlue, Cyan, DarkGreen, DarkOliveGreen, DarkOrchid,
  43.      DarkSlateBlue, DarkSlateGray, DarkTurquoise, DimGray, Firebrick,
  44.      ForestGreen, Gold, Goldenrod, Gray, Green, GreenYellow,
  45.      IndianRed, Khaki, LightBlue, LightGray, LightSteelBlue, LimeGreen,
  46.      Magenta, Maroon, MidnightBlue, Navy, NavyBlue, Orange, OrangeRed,
  47.      Orchid, PaleGreen, Peach, Pink, Plum, PrussianBlue, Purple, Red, Salmon,
  48.      SandyBrown, SeaGreen, Sienna, SkyBlue, SlateBlue, SpringGreen,
  49.      SteelBlue, Thistle, Turquoise, Violet, VioletRed, Wheat, White,
  50.      Yellow, YellowBrown, YellowGreen }]
  51.  
  52. Begin["`Private`"]
  53.  
  54. CMYColor[c_, m_, y_] := RGBColor[1 - c, 1 - m, 1 - y]
  55.  
  56. YIQColor[y_, i_, q_] := 
  57.     Apply[RGBColor,
  58.           {{1, .95, .625}, {1, -.28, -.64}, {1, -1.11, 1.73}} . {y, i, q}
  59.          ]
  60.  
  61. HSBColor[h_, s_, b_] := RGBColor[b, b, b] /; s == 0
  62.  
  63. HSBColor[h_?NumberQ, s_, b_] := 
  64.     Block[{mh = 6 Mod[h, 1.], i, f, p, q, t},
  65.         i = Floor[mh] ;
  66.         f = mh - i ;
  67.         p = b (1. - s) ;
  68.         q = b (1. - s f) ;
  69.         t = b (1. - s (1. - f)) ;
  70.         {RGBColor[b, t, p] ,
  71.          RGBColor[q, b, p] ,
  72.          RGBColor[p, b, t] ,
  73.          RGBColor[p, q, b] ,
  74.          RGBColor[t, p, b] ,
  75.          RGBColor[b, p, q]
  76.         } [[i + 1]]
  77.     ] 
  78.  
  79. HLSColor[h_, l_, s_] := RGBColor[l, l, l] /; s == 0
  80.  
  81. HLSColor[h_?NumberQ, l_?NumberQ, s_] :=
  82.     Block[{m1, m2},
  83.     m2 = If[l <= 0.5 , l (1 + s) ,l + s - l s] ;
  84.     m1 = 2 l - m2 ;
  85.     RGBColor[HLSValue[m1, m2, h+1/3] ,
  86.              HLSValue[m1, m2, h] ,
  87.              HLSValue[m1, m2, h-1/3]
  88.     ]
  89.     ]
  90.  
  91. HLSValue[n1_, n2_, hue_] :=
  92.     Block[{ hv = 6 Mod[hue, 1] } ,
  93.     {n1 + (n2 - n1) hv,
  94.      n2,
  95.      n2,
  96.      n1 + (n2 - n1)(4 - hv),
  97.      n1,
  98.      n1
  99.     } [[ 1 + Floor[hv] ]]
  100.     ]
  101.  
  102.         (* Colors *)
  103.  
  104. Aquamarine    = RGBColor[0.44, 0.86, 0.58]
  105. Black        = RGBColor[0., 0., 0.]
  106. Blue        = RGBColor[0., 0., 1.]
  107. BlueViolet    = RGBColor[0.62, 0.37, 0.62]
  108. Brown        = RGBColor[0.65, 0.16, 0.16]
  109. CadetBlue    = RGBColor[0.37, 0.62, 0.62]
  110. Coral        = RGBColor[1., 0.5, 0.]
  111. CornflowerBlue    = RGBColor[0.26, 0.26, 0.44]
  112. Cyan        = RGBColor[0., 1., 1.]
  113. DarkGreen    = RGBColor[0.18, 0.31, 0.18]
  114. DarkOliveGreen    = RGBColor[0.31, 0.31, 0.18]
  115. DarkOrchid    = RGBColor[0.6, 0.2, 0.8]
  116. DarkSlateBlue    = RGBColor[0.42, 0.14, 0.56]
  117. DarkSlateGray    = RGBColor[0.18, 0.31, 0.31]
  118. DarkTurquoise    = RGBColor[0.44, 0.58, 0.86]
  119. DimGray        = RGBColor[0.33, 0.33, 0.33]
  120. Firebrick    = RGBColor[0.56, 0.14, 0.14]
  121. ForestGreen    = RGBColor[0.14, 0.56, 0.14]
  122. Gold        = RGBColor[0.8, 0.5, 0.2]
  123. Goldenrod    = RGBColor[0.86, 0.86, 0.44]
  124. Gray        = RGBColor[0.75, 0.75, 0.75]
  125. Green        = RGBColor[0., 1., 0.]
  126. GreenYellow    = RGBColor[0.58, 0.86, 0.44]
  127. IndianRed    = RGBColor[0.31, 0.18, 0.18]
  128. Khaki        = RGBColor[0.62, 0.62, 0.37]
  129. LightBlue    = RGBColor[0.75, 0.85, 0.85]
  130. LightGray    = RGBColor[0.66, 0.66, 0.66]
  131. LightSteelBlue    = RGBColor[0.56, 0.56, 0.74]
  132. LimeGreen    = RGBColor[0.2, 0.8, 0.2]
  133. Magenta        = RGBColor[1., 0., 1.]
  134. Maroon        = RGBColor[0.56, 0.14, 0.42]
  135. MidnightBlue    = RGBColor[0.18, 0.18, 0.31]
  136. Navy        = RGBColor[0.14, 0.14, 0.56]
  137. NavyBlue    = RGBColor[0.14, 0.14, 0.56]
  138. Orange        = RGBColor[0.8, 0.2, 0.2]
  139. OrangeRed    = RGBColor[1., 0., 0.5]
  140. Orchid        = RGBColor[0.86, 0.44, 0.86]
  141. PaleGreen    = RGBColor[0.56, 0.74, 0.56]
  142. Peach        = RGBColor[0.44, 0.26, 0.26]
  143. Pink        = RGBColor[0.74, 0.56, 0.56]
  144. Plum        = RGBColor[0.92, 0.68, 0.92]
  145. PrussianBlue    = RGBColor[0.18, 0.18, 0.31]
  146. Purple        = RGBColor[0.31, 0.18, 0.31]
  147. Red        = RGBColor[1., 0., 0.]
  148. Salmon        = RGBColor[0.44, 0.26, 0.26]
  149. SandyBrown    = RGBColor[0.96, 0.64, 0.38]
  150. SeaGreen    = RGBColor[0.14, 0.56, 0.42]
  151. Sienna        = RGBColor[0.56, 0.42, 0.14]
  152. SkyBlue        = RGBColor[0.2, 0.6, 0.8]
  153. SlateBlue    = RGBColor[0., 0.5, 1.]
  154. SpringGreen    = RGBColor[0., 1., 0.5]
  155. SteelBlue    = RGBColor[0.14, 0.42, 0.56]
  156. Thistle        = RGBColor[0.85, 0.75, 0.85]
  157. Turquoise    = RGBColor[0.68, 0.92, 0.92]
  158. Violet        = RGBColor[0.31, 0.18, 0.31]
  159. VioletRed    = RGBColor[0.8, 0.2, 0.6]
  160. Wheat        = RGBColor[0.85, 0.85, 0.75]
  161. White        = RGBColor[1., 1., 1.]
  162. Yellow        = RGBColor[1., 1., 0.]
  163. YellowBrown    = RGBColor[0.86, 0.58, 0.44]
  164. YellowGreen    = RGBColor[0.6, 0.8, 0.2]
  165.  
  166. End[]
  167.  
  168. EndPackage[]
  169.