Schemes

Module scheme

Color schemes generate a series of colors from one or more base colors.

import colors.scheme
Module scheme
Source schemes/scheme.zirr
Imports colors.maths, colorsColor, ColorLike

Every scheme implements the Scheme attribute: given an index nth, it returns the n-th color of the series. Schemes are infinite — they wrap, alternate or step further with every index — so a consumer decides how many colors it needs.

Declared as Color2

The source declares scheme fields as Color2. This page reproduces the declared types verbatim; Color2 is not defined in colors.

Contents


Attributes

Scheme

`schemes/scheme.zirr:10`
attr Scheme {
  color(s: ColorScheme, nth: Int) -> Color2
}

A color scheme generates a series of colors. Types carrying this attribute supply a color implementation that maps an index to a color.

Members

Member Signature Description
color (s: ColorScheme, nth: Int) -> Color2 Returns the nth color of the series.

Implementors

CustomScheme, ConstantScheme, Complementary, Analogous, Triadic, Tetradic, Monochromatic, Shade, Tint, Tone, Mix, GoldenSpiral, Rainbow


Unions

SchemeLike

`schemes/scheme.zirr:14`
union SchemeLike {
  Scheme
  Array
  ColorLike
}

Everything that can be interpreted as a scheme. Use schemeFrom to normalize a SchemeLike into a @Scheme.

Cases

Case Interpretation
Scheme Used as is.
Array A list of ColorLike values, wrapped in a ConstantScheme.
ColorLike A single color, wrapped in a one-element ConstantScheme.

Functions

schemeFrom

`schemes/scheme.zirr:21`
fn schemeFrom(raw: SchemeLike) -> @Scheme

Normalizes any SchemeLike value into a scheme.

Parameters

Parameter Type Description
raw SchemeLike The value to convert.

Returns

@Scheme

Errors

  • "Invalid scheme type" — the value is not a member of SchemeLike.

prepend

`schemes/scheme.zirr:227`
fn prepend(c: Color2, s: @Scheme) -> @Scheme

Puts a fixed color in front of an existing scheme. Index 0 yields c, every further index nth yields s.color(nth - 1). Useful for layered surfaces and text, where the first color is fixed and the rest is derived.

Parameters

Parameter Type Description
c Color2 The color returned at index 0.
s @Scheme The scheme supplying all remaining colors.

Returns

@Scheme — a CustomScheme wrapping s.


Schemes

CustomScheme

`schemes/scheme.zirr:33`
@Scheme(fn(s, nth) { s.color(nth) })
data CustomScheme {
  color(nth: Int) -> Color2
}

A custom color scheme to define their custom color generation logic. This allows for maximum flexibility in color scheme design.

Fields

Field Type Description
color (nth: Int) -> Color2 The generation function, called directly for every index.

ConstantScheme

`schemes/scheme.zirr:41`
@Scheme(fn(s, nth) { s.colors[nth % s.colors.length] })
data ConstantScheme {
  colors: Array
}

A constant color scheme always returns colors from a predefined list. When the number of requested colors exceeds the number of colors in the list, it wraps around to the beginning of the list.

Fields

Field Type Description
colors Array The colors to cycle through.

Complementary

`schemes/scheme.zirr:58`
@Scheme(fn(s, nth) { … })
data Complementary {
  base: Color2
}

A complementary color scheme alternates between the base color and its complement. This creates a high-contrast color scheme.

Fields

Field Type Description
base Color2 The color returned at even indices.

Series

nth Hue
even base.hue
odd base.hue + 180

Analogous

`schemes/scheme.zirr:82`
@Scheme(fn(s, nth) { … })
data Analogous {
  base: Color2
  distance: maths.Degree
}

An analogous color scheme generates colors adjacent to the base color on the color wheel. The distance parameter controls how far apart the colors are. This creates a harmonious color scheme.

Fields

Field Type Description
base Color2 The center of the series.
distance maths.Degree Hue step between neighbouring colors.

Series

nth Hue
0 base.hue
odd base.hue + distance * nth
even base.hue - distance * nth

Triadic

`schemes/scheme.zirr:106`
@Scheme(fn(s, nth) { … })
data Triadic {
  base: Color2
}

A triadic color scheme uses three colors that are evenly spaced around the color wheel. This creates a vibrant color scheme.

Fields

Field Type Description
base Color2 The first of the three colors.

Series

nth % 3 Hue
0 base.hue
1 base.hue + 120
2 base.hue + 240

Tetradic

`schemes/scheme.zirr:135`
@Scheme(fn(s, nth) { … })
data Tetradic {
  base: Color2
}

A tetradic color scheme uses four colors that are evenly spaced around the color wheel. This creates a rich color scheme with plenty of variety.

Fields

Field Type Description
base Color2 The first of the four colors.

Series

nth % 4 Hue
0 base.hue
1 base.hue + 90
2 base.hue + 180
3 base.hue + 270

Monochromatic

`schemes/scheme.zirr:150`
@Scheme(fn(s, nth) { … })
data Monochromatic {
  base: Color2
  delta: maths.Fraction
}

A monochromatic color scheme generates colors by varying the lightness of a single base color. This creates a cohesive and visually appealing color scheme. Brighter and darker shades are produced alternating.

Fields

Field Type Description
base Color2 The color the series varies around.
delta maths.Fraction Lightness step per index.

Series

nth Lightness
even base.lightness + delta * nth
odd base.lightness - delta * nth

Shade

`schemes/scheme.zirr:160`
@Scheme(fn(s, nth) { shade(s.base, s.delta * nth) })
data Shade {
  base: Color2
  delta: maths.Fraction
}

A shade color scheme generates colors by reducing the lightness of a single base color. This creates a cohesive and visually appealing color scheme with progressively darker shades.

Fields

Field Type Description
base Color2 The starting color, returned at index 0.
delta maths.Fraction Darkening step per index, see shade.

Tint

`schemes/scheme.zirr:170`
@Scheme(fn(s, nth) { tint(s.base, s.delta * nth) })
data Tint {
  base: Color2
  delta: maths.Fraction
}

A tint color scheme generates colors by increasing the lightness of a single base color. This creates a cohesive and visually appealing color scheme with progressively lighter tints.

Fields

Field Type Description
base Color2 The starting color, returned at index 0.
delta maths.Fraction Lightening step per index, see tint.

Tone

`schemes/scheme.zirr:180`
@Scheme(fn(s, nth) { tone(s.base, s.delta * nth) })
data Tone {
  base: Color2
  delta: maths.Fraction
}

A tone color scheme generates colors by adding gray to a single base color. This creates a cohesive and visually appealing color scheme with progressively more muted tones.

Fields

Field Type Description
base Color2 The starting color, returned at index 0.
delta maths.Fraction Desaturation step per index, see tone.

Mix

`schemes/scheme.zirr:192`
@Scheme(fn(s, nth) { mix(s.base, s.target, s.ratio * nth) })
data Mix {
  base: Color2
  target: Color2
  ratio: maths.Fraction
}

A mix color scheme generates colors by blending a base color with a target color. The ratio parameter controls the blend between the two colors. This creates a smooth transition between the base and target colors. This is useful for creating gradients, color transitions or to simulate opacity.

Fields

Field Type Description
base Color2 The starting color, returned at index 0.
target Color2 The color blended towards.
ratio maths.Fraction Blend step per index, see mix.

GoldenSpiral

`schemes/scheme.zirr:209`
@Scheme(fn(s, nth) { … })
data GoldenSpiral {
  base: Color2
  scale: maths.Fraction
}

A golden spiral color scheme generates colors based on the golden angle (approximately 137.5 degrees). This creates a visually appealing and naturally balanced color scheme.

Fields

Field Type Description
base Color2 The color returned at index 0; supplies the saturation for all others.
scale maths.Fraction Controls how quickly the lightness grows along the spiral.

Series

nth Color
0 base
> 0 hue 137.508 * nth, lightness base.lightness + scale * sqrt(nth) / 100

Rainbow

`schemes/scheme.zirr:221`
@Scheme(fn(s, nth) { … })
data Rainbow {
  steps: Int
  saturation: maths.Fraction
  lightness: maths.Fraction
}

A rainbow color scheme generates colors that span the entire spectrum of the color wheel. This creates a vibrant and diverse color scheme. Colors are generated by evenly distributing hues around the color wheel.

Fields

Field Type Description
steps Int Number of colors per full rotation.
saturation maths.Fraction Saturation shared by all colors.
lightness maths.Fraction Lightness shared by all colors.

Series

nth Hue
any nth * 360 / steps

See also

  • Colors — the color model and manipulation primitives.
  • Maths — the Degree and Fraction wrappers used by every scheme.