Go package to generate and manage color palettes & schemes
Switch branches/tags
Clone or download
Latest commit 79507eb Oct 28, 2018

README.md

gamut

Go package to generate and manage color palettes & schemes

import "github.com/muesli/gamut"
import "github.com/muesli/gamut/palette"
import "github.com/muesli/gamut/theme"

Colors

Around the Color Wheel

The Darker and Lighter functions darken and lighten respectively a given color value by a specified percentage, without changing the color's hue:

gamut.Darker(color, 0.1) // => color.Color
// returns a 10% darker version of color
gamut.Lighter(color, 0.3) // => color.Color
// returns a 30% lighter version of color

Complementary returns the complementary color for a given color:

gamut.Complementary(color) // => color.Color

Contrast returns the color with the highest contrast to a given color, either black or white:

gamut.Contrast(color) // => color.Color

All the following functions return colors of a different hue, but with the same lightness and saturation as the given colors:

gamut.Triadic(color)            // => []color.Color{...}
gamut.Quadratic(color)          // => []color.Color{...}
gamut.Tetradic(color1, color2)  // => []color.Color{...}
gamut.Analogous(color)          // => []color.Color{...}
gamut.SplitComplementary(color) // => []color.Color{...}

Warm/Cool Colors

gamut.Warm(color) // => bool
gamut.Cool(color) // => bool

Shades, Tints & Tones

Monochromatic returns colors of the same hue, but with a different saturation/lightness:

gamut.Monochromatic(color, 8) // => []color.Color{...}

Monochromatic Palette

Shades returns colors blended from the given color to black:

gamut.Shades(color, 8) // => []color.Color{...}

Shades Palette

Tints returns colors blended from the given color to white:

gamut.Tints(color, 8) // => []color.Color{...}

Tints Palette

Tones returns colors blended from the given color to gray:

gamut.Tones(color, 8) // => []color.Color{...}

Tones Palette

Blending Colors

Blends returns interpolated colors by blending two colors:

gamut.Blends(color1, color2, 8) // => []color.Color{...}

Blends Palette

Palettes

Name Colors Source
Wikipedia 1609 https://en.wikipedia.org/wiki/List_of_colors_(compact)
Crayola 180 https://en.wikipedia.org/wiki/List_of_Crayola_crayon_colors
Resene 759 http://www.resene.co.nz
Monokai 17

Generating Color Palettes

Color Generators, like the provided PastelGenerator, WarmGenerator or HappyGenerator can produce random (within the color space constraits of the generator) color palettes:

gamut.Generate(8, gamut.PastelGenerator{})
// => ([]color.Color{...}, error)

Pastel Palette

The SimilarHueGenerator produces colors with a hue similar to a given color:

gamut.Generate(8, gamut.SimilarHueGenerator{Color: gamut.Hex("#2F1B82")})
// => ([]color.Color{...}, error)

Similar Hue Palette

Using the ColorGenerator interface, you can also write your own color generators.

Name A Color

palette.Wikipedia.Name(color) // => (name string, distance float64)
// name = "Baby blue"
// distance between 0.0 and 1.0

Retrieving Colors

palette.Crayola.Filter("Red") // => []color.Color{...}
// returns a slice of all "Red" colors in the Crayola palette
palette.Resene.Colors() // => []color.Color{...}
// returns a slice of all colors in the Resene palette
palette.Monokai.Clamped(colors) // => []color.Color{...}
// returns a slice of the nearest matching colors in the Monokai palette

Mixing Palettes

You can combine all colors of two palettes by mixing them:

palette.Crayola.MixedWith(palette.Monokai) // => gamut.Palette

Themes

Name Colors
Monokai 7

Roles

theme.MonokaiTheme.Role(theme.Foreground) // => color.Color

Available roles are Foreground, Background, Base, AlternateBase, Text, Selection, Highlight.

Development

GoDoc Build Status Coverage Status Go ReportCard