File: depart\math\maple\misc\colors.mws Date: 20-apr-1999 By: bob jantzen
<Text-field style="Heading 1" layout="Heading 1">the MUG email contribution of Klaus Volpert</Text-field> From: SMTP%"maple-list@daisy.uwaterloo.ca" 16-APR-1999 19:10:14.26 To: maple-list@daisy.uwaterloo.ca CC: Subj: [MUG] Re: RGB, Hue and HSV. >> From: kvolpert <kvolpert@email.vill.edu> > >> From: "Eddie Saudrais" <eddie.saudrais@wanadoo.fr> > > Dear mugers, > > I wonder how the spectrum is describe with the HUE (or HSV) function. > > The HUE colour specification cycles through the colours of the spectrum. > But how does it work ? Does Maple convert the HUE specification to RGB value > ? > It's not so easy : in ordre to describe the spectrum using RGB > specification, you need to knows > three mixing functions (R(x), G(x) and B(x), where x is the parameters used > to describe the spectrum). > A complete answer to your question and a comprehensive treatment of Maple's graphing capabilities can be found in the excellent book by Klimek and Klimek: Discovering Curves and Surfaces with Maple. (Springer 1997) Here is a summary: The RGB-model is based on the fact that by combining varying intensities of the colors Red, Green and Blue one can create a tremendous spectrum of colors. For example, Maple's predefined color `gold` corresponds to the triple (.8,.5,.2). In three-dimensional plotting, Maple allows us great flexibility to color our plots by the command color=[R,G,B], where R,G, and B, can be any functions of the underlying variables. This is great for coloring a surface by intrinsic properties, such as its gaussian curvature. If you are looking for a specific color, it is rather difficult to find the right intensities for R, G and B. It helps to plot the following 3-dimensional representation of the available spectrum: with(plots): pallette:=z->plot3d(z, x=0..1, y=0..1, grid=[2,2],color=[x,y,z]): display([pallette(0), pallette(.25), pallette(.5), pallette(.75), pallette(1)], orientation=[45,45], axes=boxed); this is basically a stack of colored plates, where the x, y, and z coordinates correspond to the intensity of R,G, and B respectively. (for example, on pallette(.2), near x=.8, y=.5 you will find gold.) ---------- The HSV-model is based on the three parameters Hue, Saturation and Value. This model is considered more intuitive than the RGB-model as it makes it easier to `hunt' for the right color. The relationship between an RGB-triple and the HSV-triple is as follows: The Value V is the maximum of the three intensities R,G and B. It measures how much the color differs from black. The Saturation S=(V-m)/V, where m is the minimum of R,G and B. It can be interpreted as measuring the `vividness' of the color. Finally, the Hue H is calculated by a case-by-case formula depending on S and V (see Klimek and Klimek, page 80). For example, if V=R and m=B, the formula is H=(1-(V-G)/(V-m))/6. So in the case of Maple's gold, the color's HSV values calculate to (1/12, 3/4, 4/5). Unfortunately, MapleR5 makes it difficult to work with the HSV-model. In 2-D graphics, one can specify a color by the option color=COLOR(HSV, h,s,v), but h,s,v have to be constants. In 3-D graphing, due to a bug, this command is read as color=COLOR(RGB, h,s,v) and will not give you the intended color. Maple does use the HSV-model when you specify color by a single value (or function), i.e., color=H. In this case Maple fixes the saturation S at 0.9 and the value V at 1, and understands H as a hue. As this value increases from 0 to 1, the resulting color goes through red-orange-yellow-green-blue-indigo-violet-magenta-red with red corresponding to the hue 0 and 1, green to 0.33 and blue to 0.66. By definition these colors are all vivid and bright, if not gaudy. The variety of possible colors is far more limited than the RGB-spectrum. For example, the color gold does not occur here. To see the available spectrum, look at plot3d(0, x=0..1, y=0..1, color=x, style=patchnogrid, orientation=[-90,0], axes=normal); So to summarize: the call color=.5 yields the color with the hue=.5, saturation=.9 and value=1, while the call color=[.5,.5,.5] is interpreted as the corresponding RGB-color. Finally, I would like to note that further refinements of the appearance of a plot can be made with the commands light and ambientlight, both of which can be colored. a fine example of what can be achieved is the following plot from the book by Klimek and Klimek: with(plots): setoptions3d(style=patchnogrid, scaling=constrained, projection=.5): f:=[cos(x)*sin(y),-2*sin(x)*cos(y),sin(x)+cos(y)]: a:=plot3d(f,x=0..2*Pi,y=0..Pi, color=[cos(x)^2,cos(x),-cos(x)], light=[120,70,.8,.2,.2],ambientlight=[.5,.5,.5], grid=[50,50]): b:=sphereplot(.4,x=0..2*Pi,y=0..Pi, color=[(sin(2*y))^2,-(cos(y))^3,.4],grid=[30,30]): display3d({a,b},orientation=[-15,98]); Klaus Volpert Department of Mathematical Sciences Villanova University