Functional PostScript Tutorial

Functional PostScript Tutorial


Color

In FPS, color can be specified in four modes:

RGB Red Blue Green
HSB Hue Saturation Brightness
CMYK Cyan Magenta Yellow Black
Gray Just Gray (monocolor)

FPS's view of color is simple: The four modes are equivelant. you can create a color in any of the four modes. Once you create a color, you can find out its component values in any of the four modes.

To create a color in FPS, you first select the mode you wish to work in, and then specify how much (from 0 to 1) of each component in the mode you want. For example, RGB has three color components. To create a color in RGB, simply specify how much red, blue, and green you want. 1 is the maximum amount, 0 is none.

	(define red (rgb 1 0 0))
We can extract the component value of a color:

	(rgb:r red) --> 1
Once we have created a color, we can make new colors from it in other modes. In the following example we reduce the brightness of 'red' by half by creating another red in the HSB mode:

	(define less-bright-red (hsb (hsb:h red)
			 	     (hsb:s red)
				     (/ (hsb:b red) 2)))
Once we have created these colors, we can use them to specify how paths are painted to make pictures.

	(stroke triangle-path (:color just-red)))
	(fill   triangle-path (:color less-bright-red)))
You can do lots of neat color tricks in FPS because it is so easy to build new colors from exisiting ones. See the sun program in fps-examples.scm for a more extended example.

Related procedures in this section:
rgb, hsb, cmyk, gray.

FPS Home | Prev Section | Next Section

FPS Tutorial Content: Intro and The Idea | Getting Started | Paths and Pictures | Show and Channels | Transformation | Composition | Glyphpaths | Style | Color | Colormap | Clipping | Glyphnames | Other Topics