# 6.6 Colors

Most of Pyxplot’s graph plotting and vector graphics commands have settings for specifying colors. A selection of widely-used colors may be specified by name, for example `red` and `blue`. However, greater freedom in choice of color is available by passing these commands objects of type `color`.

Several functions are available for making color objects:

- `gray(x)` returns a shade of gray. The argument should be in the range 0–1. If , black is returned; if , white is returned.

- `rgb(r,g,b)` returns a color with the specified RGB components, which should be in the range 0–1.

- `cmyk(c,m,y,k)` returns a color with the specified CMYK components, which should be in the range 0–1.

- `hsb(h,s,b)` returns a color with the specified coordinates in hue–saturation–brightness color space, which should be in the range 0–1.

In addition, color objects corresponding to all of Pyxplot’s built-in named colors can be found in the `colors` module.

    a = colors.red
    b = rgb(0,0.5,0)
    box from 0,0 to 3,3 with color a fillcolor b lw 5

Once a color object has been made, various operations are supported. Multiplying or dividing a color by a number changes the brightness of the color. When two colors are compared, brighter colors are greater than darker colors. When two colors are added together, they are additively mixed in RGB space, so that adding red and green together produces yellow. When one color is subtracted from another, the opposite happens, so that yellow minus green is red.

The methods available on `color` objects are listed in Section 3.3.

- 6.6.1 Color representations of the electromagnetic spectrum