
(* Copyright 1988 Wolfram Research Inc. *)

(*:Title: Colors *)

(*:Author: Wolfram Research, Inc. *)

(*:Version: Mathematica 2.0 *)

(*:Keywords:
       CMYColor, YIQColor, HLSColor
*)

(*:Sources: none. *)

(*:Requirements: none. *)

(*:Warnings: none. *)

(*:Summary: This package contains functions that convert from various
color systems into an RGBColor. It also allows you to give a color name
(such as Blue) and the appropriate RGBColor is produced.
*)

BeginPackage["Graphics`Colors`"]

CMYColor::usage = "CMYColor[c,m,y] represents a color in the CMY 
	(cyan-magenta-yellow) system."

YIQColor::usage = "YIQColor[y,i,q] represents a color in the YIQ 
	(NTSC video form) system."

HSBColor::usage = "HSBColor[h,s,b] is obsolete. See Hue[]." 
 
HLSColor::usage = "HLSColor[h,l,s] represents a color in the HLS 
	(hue-lightness-saturation) system." 
 
Map[(#::"usage" = 
	StringJoin[ToString[#]," is a color given in the RGBColor system."
   ])&,
   { Aquamarine, Black, Blue, BlueViolet, Brown, CadetBlue, Coral,
     CornflowerBlue, Cyan, DarkGreen, DarkOliveGreen, DarkOrchid,
     DarkSlateBlue, DarkSlateGray, DarkTurquoise, DimGray, Firebrick,
     ForestGreen, Gold, Goldenrod, Gray, Green, GreenYellow,
     IndianRed, Khaki, LightBlue, LightGray, LightSteelBlue, LimeGreen,
     Magenta, Maroon, MidnightBlue, Navy, NavyBlue, Orange, OrangeRed,
     Orchid, PaleGreen, Peach, Pink, Plum, PrussianBlue, Purple, Red, Salmon,
     SandyBrown, SeaGreen, Sienna, SkyBlue, SlateBlue, SpringGreen,
     SteelBlue, Thistle, Turquoise, Violet, VioletRed, Wheat, White,
     Yellow, YellowBrown, YellowGreen }]

Begin["`Private`"]

CMYColor[c_, m_, y_] := RGBColor[1 - c, 1 - m, 1 - y]

YIQColor[y_, i_, q_] := 
	Apply[RGBColor,
	      {{1, .95, .625}, {1, -.28, -.64}, {1, -1.11, 1.73}} . {y, i, q}
	     ]

HSBColor[h_, s_, b_] := RGBColor[b, b, b] /; s == 0

HSBColor[h_?NumberQ, s_, b_] := 
	Block[{mh = 6 Mod[h, 1.], i, f, p, q, t},
		i = Floor[mh] ;
		f = mh - i ;
		p = b (1. - s) ;
		q = b (1. - s f) ;
		t = b (1. - s (1. - f)) ;
		{RGBColor[b, t, p] ,
		 RGBColor[q, b, p] ,
		 RGBColor[p, b, t] ,
		 RGBColor[p, q, b] ,
		 RGBColor[t, p, b] ,
		 RGBColor[b, p, q]
		} [[i + 1]]
	] 

HLSColor[h_, l_, s_] := RGBColor[l, l, l] /; s == 0

HLSColor[h_?NumberQ, l_?NumberQ, s_] :=
    Block[{m1, m2},
	m2 = If[l <= 0.5 , l (1 + s) ,l + s - l s] ;
	m1 = 2 l - m2 ;
	RGBColor[HLSValue[m1, m2, h+1/3] ,
	         HLSValue[m1, m2, h] ,
	         HLSValue[m1, m2, h-1/3]
	]
    ]

HLSValue[n1_, n2_, hue_] :=
    Block[{ hv = 6 Mod[hue, 1] } ,
	{n1 + (n2 - n1) hv,
	 n2,
	 n2,
	 n1 + (n2 - n1)(4 - hv),
	 n1,
	 n1
	} [[ 1 + Floor[hv] ]]
    ]

		(* Colors *)

Aquamarine	= RGBColor[0.44, 0.86, 0.58]
Black		= RGBColor[0., 0., 0.]
Blue		= RGBColor[0., 0., 1.]
BlueViolet	= RGBColor[0.62, 0.37, 0.62]
Brown		= RGBColor[0.65, 0.16, 0.16]
CadetBlue	= RGBColor[0.37, 0.62, 0.62]
Coral		= RGBColor[1., 0.5, 0.]
CornflowerBlue	= RGBColor[0.26, 0.26, 0.44]
Cyan		= RGBColor[0., 1., 1.]
DarkGreen	= RGBColor[0.18, 0.31, 0.18]
DarkOliveGreen	= RGBColor[0.31, 0.31, 0.18]
DarkOrchid	= RGBColor[0.6, 0.2, 0.8]
DarkSlateBlue	= RGBColor[0.42, 0.14, 0.56]
DarkSlateGray	= RGBColor[0.18, 0.31, 0.31]
DarkTurquoise	= RGBColor[0.44, 0.58, 0.86]
DimGray		= RGBColor[0.33, 0.33, 0.33]
Firebrick	= RGBColor[0.56, 0.14, 0.14]
ForestGreen	= RGBColor[0.14, 0.56, 0.14]
Gold		= RGBColor[0.8, 0.5, 0.2]
Goldenrod	= RGBColor[0.86, 0.86, 0.44]
Gray		= RGBColor[0.75, 0.75, 0.75]
Green		= RGBColor[0., 1., 0.]
GreenYellow	= RGBColor[0.58, 0.86, 0.44]
IndianRed	= RGBColor[0.31, 0.18, 0.18]
Khaki		= RGBColor[0.62, 0.62, 0.37]
LightBlue	= RGBColor[0.75, 0.85, 0.85]
LightGray	= RGBColor[0.66, 0.66, 0.66]
LightSteelBlue	= RGBColor[0.56, 0.56, 0.74]
LimeGreen	= RGBColor[0.2, 0.8, 0.2]
Magenta		= RGBColor[1., 0., 1.]
Maroon		= RGBColor[0.56, 0.14, 0.42]
MidnightBlue	= RGBColor[0.18, 0.18, 0.31]
Navy		= RGBColor[0.14, 0.14, 0.56]
NavyBlue	= RGBColor[0.14, 0.14, 0.56]
Orange		= RGBColor[0.8, 0.2, 0.2]
OrangeRed	= RGBColor[1., 0., 0.5]
Orchid		= RGBColor[0.86, 0.44, 0.86]
PaleGreen	= RGBColor[0.56, 0.74, 0.56]
Peach		= RGBColor[0.44, 0.26, 0.26]
Pink		= RGBColor[0.74, 0.56, 0.56]
Plum		= RGBColor[0.92, 0.68, 0.92]
PrussianBlue	= RGBColor[0.18, 0.18, 0.31]
Purple		= RGBColor[0.31, 0.18, 0.31]
Red		= RGBColor[1., 0., 0.]
Salmon		= RGBColor[0.44, 0.26, 0.26]
SandyBrown	= RGBColor[0.96, 0.64, 0.38]
SeaGreen	= RGBColor[0.14, 0.56, 0.42]
Sienna		= RGBColor[0.56, 0.42, 0.14]
SkyBlue		= RGBColor[0.2, 0.6, 0.8]
SlateBlue	= RGBColor[0., 0.5, 1.]
SpringGreen	= RGBColor[0., 1., 0.5]
SteelBlue	= RGBColor[0.14, 0.42, 0.56]
Thistle		= RGBColor[0.85, 0.75, 0.85]
Turquoise	= RGBColor[0.68, 0.92, 0.92]
Violet		= RGBColor[0.31, 0.18, 0.31]
VioletRed	= RGBColor[0.8, 0.2, 0.6]
Wheat		= RGBColor[0.85, 0.85, 0.75]
White		= RGBColor[1., 1., 1.]
Yellow		= RGBColor[1., 1., 0.]
YellowBrown	= RGBColor[0.86, 0.58, 0.44]
YellowGreen	= RGBColor[0.6, 0.8, 0.2]

End[]

EndPackage[]
