gamut

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2020 License: MIT Imports: 8 Imported by: 54

README

gamut

Latest Release Build Status Coverage Status Go ReportCard GoDoc

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Analogous

func Analogous(c color.Color) []color.Color

Analogous returns the analogous values for any given color

func Blends

func Blends(c1, c2 color.Color, count int) []color.Color

Blends returns a slice of interpolated colors, blended between two colors

func Complementary

func Complementary(c color.Color) color.Color

Complementary returns the complementary value for any given color

func Contrast

func Contrast(c color.Color) color.Color

Contrast returns the color with the most contrast (hence either black or white)

func Cool

func Cool(c color.Color) bool

Cool returns whether a color is considered to have a cool temperature

func Darker

func Darker(c color.Color, percent float64) color.Color

Darker returns a darker version of the specified color

func Generate

func Generate(count int, generator ColorGenerator) ([]color.Color, error)

Generate returns a slice with the requested amount of colors, generated by the provided ColorGenerator.

func Hex

func Hex(s string) color.Color

Hex returns the color encoded by a hex-string, e.g. "#ABCDEF"

func HueOffset

func HueOffset(c color.Color, degrees int) color.Color

HueOffset returns color with a different hue angle

func Lighter

func Lighter(c color.Color, percent float64) color.Color

Lighter returns a lighter version of the specified color

func Monochromatic

func Monochromatic(c color.Color, count int) []color.Color

Monochromatic returns the specified amount of monochromatic colors based on a given color's hues

func Quadratic

func Quadratic(c color.Color) []color.Color

Quadratic returns the quadratic values for any given color

func Shades

func Shades(c color.Color, count int) []color.Color

Shades returns the specified amount of a color's shades

func SplitComplementary

func SplitComplementary(c color.Color) []color.Color

SplitComplementary returns the split complementary values for any given color

func Tetradic

func Tetradic(c1 color.Color, c2 color.Color) []color.Color

Tetradic returns the tetradic values for any given color

func Tints

func Tints(c color.Color, count int) []color.Color

Tints returns the specified amount of a color's tints

func Tones

func Tones(c color.Color, count int) []color.Color

Tones returns the specified amount of a color's tone

func Triadic

func Triadic(c color.Color) []color.Color

Triadic returns the triadic values for any given color

func Warm

func Warm(c color.Color) bool

Warm returns whether a color is considered to have a warm temperature

Types

type BroadGranularity

type BroadGranularity struct {
}

BroadGranularity is used for wider color spaces, e.g. by the PastelGenerator

func (BroadGranularity) Granularity

func (g BroadGranularity) Granularity() (l, c float64)

Granularity returns BroadGranularity's default values

type Color

type Color struct {
	Name      string
	Color     color.Color
	Reference string
}

A Color is a color including its name and reference URL

type ColorGenerator

type ColorGenerator interface {
	Valid(col colorful.Color) bool
	Granularity() (l, c float64)
}

A ColorGenerator checks whether a point in the three dimensional CIELab space is suitable for color generation.

type ColorObservation

type ColorObservation struct {
	colorful.Color
}

ColorObservation is a wrapper around colorful.Color, implementing the clusters.Observation interface

func (ColorObservation) Coordinates

func (c ColorObservation) Coordinates() clusters.Coordinates

Coordinates returns the data points of a Lab color value

func (ColorObservation) Distance

func (c ColorObservation) Distance(pos clusters.Coordinates) float64

Distance calculates the distance between two ColorObservations in the Lab color space

type Colors

type Colors []Color

Colors is a slice of colors

type FineGranularity

type FineGranularity struct {
}

FineGranularity is used for tighter color spaces, e.g. by the SimilarHueGenerator

func (FineGranularity) Granularity

func (g FineGranularity) Granularity() (l, c float64)

Granularity returns FineGranularity's default values

type HappyGenerator

type HappyGenerator struct {
	BroadGranularity
}

HappyGenerator produces "happy" colors

func (HappyGenerator) Valid

func (cc HappyGenerator) Valid(col colorful.Color) bool

Valid returns true if the color is considered a "happy" color

type Palette

type Palette struct {
	// contains filtered or unexported fields
}

A Palette is a collection of colors

func (*Palette) AddColors

func (g *Palette) AddColors(cc Colors)

AddColors adds colors to the palette

func (Palette) Clamped

func (g Palette) Clamped(cc []color.Color) Colors

Clamped expects a slice of colors and returns a slice of the nearest matching colors from the palette

func (Palette) Colors

func (g Palette) Colors() Colors

Colors returns the Palette's colors

func (Palette) Filter

func (g Palette) Filter(name string) Colors

Filter returns colors matching name

func (Palette) MixedWith

func (g Palette) MixedWith(p Palette) Palette

MixedWith mixes two palettes

func (Palette) Name

func (g Palette) Name(color color.Color) (Colors, float64)

Name returns the name of the closest matching color

type PastelGenerator

type PastelGenerator struct {
	BroadGranularity
}

PastelGenerator produces "pastel" colors

func (PastelGenerator) Valid

func (cc PastelGenerator) Valid(col colorful.Color) bool

Valid returns true if the color is considered a "pastel" color

type SimilarHueGenerator

type SimilarHueGenerator struct {
	FineGranularity
	Color color.Color
}

SimilarHueGenerator produces colors with a similar hue as the given color

func (SimilarHueGenerator) Valid

func (gen SimilarHueGenerator) Valid(col colorful.Color) bool

Valid returns true if the given color has a similar hue as the original color

type WarmGenerator

type WarmGenerator struct {
	BroadGranularity
}

WarmGenerator produces "warm" colors

func (WarmGenerator) Valid

func (cc WarmGenerator) Valid(col colorful.Color) bool

Valid returns true if the color is considered a "warm" color

Directories

Path Synopsis
examples
analysis command
generator command
palettes command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL