Module

Color.Scale

Package
purescript-colors
Repository
purescript-contrib/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 is represented by a list of ColorStops and a ColorSpace that is used for interpolation between the stops.

#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).

#ColorStops Source

data ColorStops

Represents all ColorStops in a color scale. 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).

Constructors

#combineStops' Source

combineStops' :: Number -> Number -> ColorStops -> ColorStops -> ColorStops

Like combineStops, but the width of the "transition zone" can be specified as the first argument.

Example:

redToBlue `combineStops epsilon x` orangeToGray

Here, the color at x will be orange and color at x - epsilon will be blue. If we want the color at x to be blue, combineStops' epsilon (x + epsilon) could be used.

#combineStops Source

combineStops :: Number -> ColorStops -> ColorStops -> ColorStops

Concatenates two color scales. The first argument specifies the transition point as a number between zero and one. The color right at the transition point is the first color of the second color scale.

Example:

redToBlue `combineStops 0.4` orangeToGray

#reverseStops Source

reverseStops :: ColorStops -> ColorStops

Takes ColorStops and returns reverses it

#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.

#uniformScale' Source

uniformScale' :: forall f. Foldable f => Color -> f Color -> Color -> ColorStops

Create ColorStops from a list of colors such that they will be evenly spaced on the scale.

#addStop Source

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

Add a stop to a color scale.

#addStop' Source

addStop' :: ColorStops -> Color -> Number -> ColorStops

Add a stop to a list of ColorStops.

#sample Source

sample :: ColorScale -> Number -> Color

Get the color at a specific point on the color scale by linearly interpolating between its colors (see mix and mkSimpleSampler).

#cubehelixSample Source

cubehelixSample :: ColorStops -> Number -> Color

Get the color at a specific point on the color scale, using the cubehelix interpolation (see mixCubehelix and mkSimpleSampler).

#mkSimpleSampler Source

mkSimpleSampler :: Interpolator -> ColorStops -> 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.

#colors' Source

colors' :: (Number -> Color) -> Int -> List Color

Takes a sampling function and returns a list of colors that is sampled via that function. 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.

#modify' Source

modify' :: (Number -> Color -> Color) -> ColorStops -> ColorStops

Modify a list of ColorStops 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.

#hot Source

hot :: ColorScale

A color scale that represents 'hot' colors.

#cool Source

cool :: ColorScale

A color scale that represents 'cool' colors.

#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.

#cubehelix Source

cubehelix :: ColorScale

The standard cubehelix color scale.

#minColorStops Source

minColorStops :: Int -> (ColorStops -> Number -> Color) -> ColorStops -> ColorStops

Takes number of stops ColorStops should contain, function to generate missing colors and ColorStops itself.

#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.

#cssColorStopsRGB Source

cssColorStopsRGB :: ColorStops -> String

Underling function of cssColorStops.