5.2 SolidColor

A solid color is specified relative to some color space. In Bifrost, three color spaces are supported, namely RGB, CMY and HSV. These are the color spaces that seems to have the most widespread use in computer graphics (cf., e.g. [Bifrost 92], [Foley 90]). The HSV color space is probably the most intuitive of these, since defining a color in it resembles the way an artist do it. In order to ease the job of the programmer, colors can also be specified using a simple naming model. Of course, it will be possible to extend the color support in Bifrost for other color spaces too, if needed.

The number of colors available at the same time depends on the device used. If no more colors are available, a default color is used.

5.2.1 Defining Solid Colors

The following three operations are used to manipulate the attributes of a SolidColor. All three operations can be used to both set and get the values of the solid color in the respective color models:

RGBvalues.
Enters three integers representing red, green, and blue values, and changes the SolidColor accordingly. Exits the current red, green, and blue values. Red, green, and blue values ranges from zero to the value determined by the constant MaxRGB.
HSVvalues.
Like RGBvalues this operation enters three integers. These are interpreted as hue, saturation and value of the solid color. HSVvalues exits the hue, saturation, and value of the SolidColor. HSVvalues has three attributes MaxHue, MaxSat and MaxVal determining the ranges of hue, saturation and value. MaxHue, MaxSat and MaxVal is DefaultMaxHue, DefaultMaxSat, and DefaultMaxVal, respectively, by default, but may be changed by the application programmer.
CMYvalues
This is like RGBvalues except that the three values entered and exited constitute the cyan-magenta-yellow representation of the SolidColor.

5.2.2 Examples

The following example illustrates how a column with the complete color spectrum, can be drawn using the HSV color model. This is done by stacking thin lines upon each other, having hues 1, 2, ..., MaxHue respectively (that is MaxHue number of lines in all). Full saturation and values are used.

(for h:DefaultMaxHue repeat
     &Line[] -> aLine[];
     aLine.init;
     1 -> aLine.width;
     ((0,h), (100,h)) -> aLine.Coordinates;

     &SolidColor[] -> aSolidColor[] -> aLine.SetPaint;
     (h, MaxSat, MaxVal) -> aSolidColor.HSVvalues;

     aLine[] -> aCanvas.draw;
for);
[45 bytes 50x5 GIF]

A Color Scale:

[2kb 50x181 GIF]

Notice that it would not suffice to instantiate just one line object and change the color of this one object, because in Bifrost each part of an image must correspond to some graphical object that is inserted into the canvas picture (by the canvas operation Draw). Changing the color of one line object would result in one line with changing colors being shown. Also notice that an instance of the predefined graphical object class Line is used. Predefined graphical objects are defined in Predefined Shapes and Graphical Objects.

By combining the different color spaces interesting effects can be achieved. The following example is an elaboration of the previous one. The example draws the complementary color spectrum in a column adjacent to the column described in the previous example.

(for h:DefaultMaxHue repeat
     &Line[] -> aLine[];
     aLine.init;
     1 -> aLine.width;
     ((0,h), (100,h)) -> aLine.Coordinates;
     &SolidColor[] -> aSolidColor[] -> aLine.SetPaint;
     (h, MaxSat, MaxVal) -> aSolidColor.HSVvalues;
     aLine[] -> aCanvas.draw;

     (* draw the line with complementary color *)
     &Line[] -> aLine[];
     aLine.init;
     1 -> aLine.width;
     ((110,h), (210,h)) -> aLine.Coordinates;
     &SolidColor[] -> anotherSolidColor -> aLine.SetPaint;
     aSolidColor.RGBvalues -> anotherSolidColor.CMYvalues;
     aLine[] -> aCanvas.draw;
for);

The result of the last program is illustrated in the Figure below.

Figure 13: A Color Scale and its Complementary

[4kb 115x190 GIF]

5.2.3 Name Color Model

An even more intuitive 'color space' than RGB, HSV and CMY is the one used in everyday life: defining the colors simply by naming them. Bifrost support the possibility of specifying a solid color by name by means of a large number of patterns exiting RGB values corresponding to different color names. These patterns are located in the file ~beta/bifrost/ColorNames.

Name.
Enters the new RGB values, and is hence just an alias for setting the color using RGBvalues. Useful when evaluating one of the color defining patterns, which exits RGB values corresponding to a given color name.

The following example illustrates how to draw a circle with center in (10,10) and radius 25 and filled with solid pink color, using the simple naming color model.

&Ellipse[] -> anEllipse[];
anEllipse.init;
((10,10),25,25) -> anEllipse.geometry;
&SolidColor[] -> aSolidColor[] -> anEllipse.SetPaint;
pink -> aSolidColor.Name;
anEllipse[] -> aCanvas.draw;

5.2.4 TiledSolidColor

A tiled solid color is a solid color extended with a BitMap. The BitMap will be tiled in the shape before the SolidColor is applied, and only where the pixel values of the BitMap is true the SolidColor will be visible. This is the normal tiling approach. As mentioned in Raster the hotspots of the BitMap and of the shape being filled, determine the position of the BitMap within the shape.

Example:

A Shape:

[1kb 94x130 GIF]

The Shape filled with a TiledSolidColor using the BitMap as tile:

[1kb 92x128 GIF]

A Bitmap:

[863 bytes 14x15 GIF]


The Bifrost Graphics System - Reference Manual
© 1991-2002 Mjølner Informatics
[Modified: Tuesday October 24th 2000 at 15:02]