Module

Color.Scale

Package
purescript-colors
Repository
sharkdp/purescript-colors

This module defines color scales. A color scale is a continuum of colors that is defined on the closed interval [0, 1]. It is defined by the two colors at each endpoint (0 and 1) and possibly additional color stops in between. If a color scale is sampled between two color stops, the specified color space is used for linear interpolation (see mix).

#ColorStop Source

data ColorStop

A point on the color scale.

#colorStop Source

colorStop :: Color -> Number -> ColorStop

Create a color stop from a given Color and a number between 0 and 1. If the number is outside this range, it is clamped.

#ColorScale Source

data ColorScale

A color scale.

#colorScale Source

colorScale :: ColorSpace -> Color -> List ColorStop -> Color -> ColorScale

Create a color scale. The color space is used for interpolation between different stops. The first Color defines the left end (color at ratio 0.0), the list of stops defines possible intermediate steps and the second Color argument defines the right end point (color at ratio 1.0).

#uniformScale Source

uniformScale :: forall f. Foldable f => ColorSpace -> Color -> f Color -> Color -> ColorScale

Create a uniform color scale from a list of colors that will be evenly spaced on the scale.

#addStop Source

addStop :: ColorScale -> Color -> Number -> ColorScale

Add a stop to a color scale.

#sample Source

sample :: ColorScale -> Number -> Color

Get the color at a specific point on the color scale (number between 0 and 1). If the number is smaller than 0, the color at 0 is returned. If the number is larger than 1, the color at 1 is returned.

#colors Source

colors :: ColorScale -> Int -> List Color

A list of colors that is sampled from a color scale. The number of colors can be specified.

#modify Source

modify :: (Number -> Color -> Color) -> ColorScale -> ColorScale

Modify the color scale by applying the given function to each color stop. The first argument is the position of the color stop.

#grayscale Source

grayscale :: ColorScale

A scale of colors from black to white.

#spectrum Source

spectrum :: ColorScale

A spectrum of fully saturated hues (HSL color space).

#spectrumLCh Source

spectrumLCh :: ColorScale

A perceptually-uniform spectrum of all hues (LCh color space).

#blueToRed Source

blueToRed :: ColorScale

A perceptually-uniform, diverging color scale from blue to red, similar to the ColorBrewer scale 'RdBu'.

#yellowToRed Source

yellowToRed :: ColorScale

A perceptually-uniform, multi-hue color scale from yellow to red, similar to the ColorBrewer scale YlOrRd.

#hot Source

hot :: ColorScale

A color scale that represents 'hot' colors.

#cool Source

cool :: ColorScale

A color scale that represents 'cool' colors.

#cssColorStops Source

cssColorStops :: ColorScale -> String

A CSS representation of the color scale in the form of a comma-separated list of color stops. This list can be used in a linear-gradient or a similar construct.

Note that CSS uses the RGB space for color interpolation. Consequently, if the color scale is in RGB mode, this is just a list of all defined color stops.

For other color spaces, the color scale is sampled at (at least) 10 different points. This should give a reasonable approximation to the true gradient in the specified color space.