(*********************************************************************

	Copyright 1989 by Roman E. Maeder
	
	Adapted from
	Roman E. Maeder: Programming in Mathematica, Addison-Wesley, 1989.

	Permission is hereby granted to make copies of this file for
	any purpose other than direct profit, or as part of a
	commercial product, provided this copyright notice is left
	intact.  Sale, other than for the cost of media, is prohibited.
	
	Permission is hereby granted to reproduce part or all of
	this file, provided that the source is acknowledged.

 *********************************************************************)


BeginPackage["Utilities`PlotUtilities`", "Graphics`Colors`"]

ArgColor::usage = "ArgColor[z] gives a color value whose hue is proportional
	to the argument of the complex number z."
ArgShade::usage = "ArgShade[z] gives a gray level proportional
	to the argument of the complex number z."

ColorCircle::usage = "ColorCircle[r, (light:1)] gives a color value whose hue
	is proportional to r (mod 2Pi) with lightness light."

Begin["`Private`"]

ArgColor[z_] := RGBColor[1,1,1]	/; z == 0.0
ArgColor[z_] := HSBColor[ N[(Pi + Arg[z])/(2Pi)], 1, 1 ]

ArgShade[z_] := GrayLevel[1]	/; z == 0.0
ArgShade[z_] := GrayLevel[N[(Pi + Arg[z])/(2Pi)] ]

ColorCircle[arg_, light_:1.0] :=
	Block[{ mh = 3.0 Mod[N[arg / Pi], 2.0], ind, frac, frac1, scale },
		ind = Floor[mh]; frac = mh - ind;
		scale = Max[ Min[light, 1.0], 0.0 ];
		frac1 = scale(1.0-frac); frac *= scale;
		Switch[ind,
			0,	RGBColor[scale, frac,   0.0],
			1,	RGBColor[frac1, scale,  0.0],
			2,	RGBColor[0.0,   scale,  frac],
			3,	RGBColor[0.0,   frac1,  scale],
			4,	RGBColor[frac,  0.0,    scale],
			5,	RGBColor[scale, 0.0,    frac1],
			6,	RGBColor[scale, frac,   0.0]
		]
	] /; NumberQ[N[arg]]

ColorCircle[_, light_:1.0] := RGBColor[light, light, light]

End[]

Protect[ArgColor, ArgShade, ColorCircle]

EndPackage[]
