Color

The color module provides support for working with color. Colors are represented in morpho by Color objects. The module predefines some colors including Red, Green, Blue, Black, White.

To use the module, use import as usual:

import color

Create a Color object from an RGB pair:

var col = Color(0.5,0.5,0.5) // A 50% gray

The color module also provides ColorMaps, which are give a sequence of colors as a function of a parameter; these are useful for plotting the values of a Field for example.

RGB

Gets the rgb components of a Color or ColorMap object as a list. Takes a single argument in the range 0 to 1, although the result will only depend on this argument if the object is a ColorMap.

var col = Color(0.1,0.5,0.7)
print col.rgb(0)

Red

Built in Color object for use with the graphics and plot modules.

Green

Built in Color object for use with the graphics and plot modules.

Blue

Built in Color object for use with the graphics and plot modules.

White

Built in Color object for use with the graphics and plot modules.

Black

Built in Color object for use with the graphics and plot modules.

Cyan

Built in Color object for use with the graphics and plot modules.

Magenta

Built in Color object for use with the graphics and plot modules.

Yellow

Built in Color object for use with the graphics and plot modules.

Brown

Built in Color object for use with the graphics and plot modules.

Orange

Built in Color object for use with the graphics and plot modules.

Pink

Built in Color object for use with the graphics and plot modules.

Purple

Built in Color object for use with the graphics and plot modules.

Colormap

The color module provides ColorMaps which are subclasses of Color that map a single parameter in the range 0 to 1 onto a continuum of colors. Colors and Colormaps have the same interface.

Get the red, green or blue components of a color or colormap:

var col = HueMap()
print col.red(0.5) // argument can be in range 0 to 1

Get all three components as a list:

col.rgb(0)

Create a grayscale:

var c = Gray(0.2) // 20% gray

Available ColorMaps: GradientMap, GrayMap, HueMap, ViridisMap, MagmaMap, InfernoMap and PlasmaMap.

GradientMap

GradientMap is a Colormap that displays a white-green-purple sequence.

GrayMap

GrayMap is a Colormap that displays grayscales.

HueMap

HueMap is a Colormap that displays vivid colors. It is periodic on the interval 0 to 1.

ViridisMap

ViridisMap is a Colormap that displays a purple-green-yellow sequence. It is perceptually uniform and intended to be improve the accessibility of visualizations for viewers with color vision deficiency.

MagmaMap

MagmaMap is a Colormap that displays a black-red-yellow sequence. It is perceptually uniform and intended to be improve the accessibility of visualizations for viewers with color vision deficiency.

InfernoMap

InfernoMap is a Colormap that displays a black-red-yellow sequence. It is perceptually uniform and intended to be improve the accessibility of visualizations for viewers with color vision deficiency.

PlasmaMap

InfernoMap is a Colormap that displays a blue-red-yellow sequence. It is perceptually uniform and intended to be improve the accessibility of visualizations for viewers with color vision deficiency.