Functional PostScript Tutorial

Functional PostScript Tutorial


Colormap

Colormap is a way to make pictures from other pictures by "remapping" the colors using a color-function. The colormap concept is identical to the ordinary "map" function for list in Scheme:

        (map (lambda (n) (+ n 1)) '(1 2 3))
The map function feeds the elements in the list through the mapping function to create a new list. Similarly, the colormap function feeds every color in the picture through the colormmap function to create a new picture. For example:

	;turn the picture completely green
	(colormap (lambda (c) (rbg 0 1 0)) <picture>) 

	;reduce the brightness of picture by a quarter
	(colormap (lambda (c) (hsb (hsb:hue c)
				   (hsb:sat c)
				   (* (hsb:bri c) .75)))
		  <picture>)
Note that a colormap function is any function that takes a color as an argument, and returns a color.

You can achieve many interesting effects (fading, darkening, etc) by recursively colormap a picture. See the headlines and square-to-circle program in fps-examples.scm for more extended examples.

Related procedures in this section:
colormap

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