• Stars
    star
    510
  • Rank 86,627 (Top 2 %)
  • Language
    Go
  • License
    MIT License
  • Created over 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Go package to generate and manage color palettes & schemes ๐ŸŽจ

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

gamut operates on various color spaces internally, but all color values you pass in as parameters and all return values will match Goโ€™s color.Color interface.

Letโ€™s start with the basics. Just for convenience thereโ€™s a hex-value parser:

color = gamut.Hex("#333")
color = gamut.Hex("#ABCDEF")

Both the short and standard formats are supported.

Conversely you can retrieve the hex encoding of any color.Color value:

hex = gamut.ToHex(color)

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:

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

Complementary returns the complementary color for a given color:

color = gamut.Complementary(color)

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

color = gamut.Contrast(color)

To retrieve a color with the same lightness and saturation, but a different angle on the color wheel, you can use the HueOffset function:

color = gamut.HueOffset(color, 90)

You can also go in the opposite direction by using negative values.

Schemes

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

Triadic schemes are made up of three hues equally spaced around the color wheel:

colors = gamut.Triadic(color)

Quadratic schemes are made up of four hues equally spaced around the color wheel:

colors = gamut.Quadratic(color)

Tetradic schemes are made up by two colors and their complementary values:

colors = gamut.Tetradic(color1, color2)

Analogous schemes are created by using colors that are next to each other on the color wheel:

colors = gamut.Analogous(color)

SplitComplementary schemes are created by using colors next to the complementary value of a given color:

colors = gamut.SplitComplementary(color)

Warm/Cool Colors

ok = gamut.Warm(color)
ok = gamut.Cool(color)

Shades, Tints & Tones

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

colors = gamut.Monochromatic(color, 8)

Monochromatic Palette

Shades returns colors blended from the given color to black:

colors = gamut.Shades(color, 8)

Shades Palette

Tints returns colors blended from the given color to white:

colors = gamut.Tints(color, 8)

Tints Palette

Tones returns colors blended from the given color to gray:

colors = gamut.Tones(color, 8)

Tones Palette

Blending Colors

Blends returns interpolated colors by blending two colors:

colors = gamut.Blends(color1, color2, 8)

Blends Palette

Palettes

Gamut comes with six curated color palettes: Wikipedia, Crayola, CSS, RAL, Resene, and Monokai. The Wikipedia palette is an import of common colors from Wikipediaโ€™s List of Colors. New curated palettes and importers are welcome. Send me a pull request!

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
CSS 147 https://developer.mozilla.org/en-US/docs/Web/CSS/color_value
RAL 213 https://en.wikipedia.org/wiki/List_of_RAL_colors
Resene 759 http://www.resene.co.nz
Monokai 17

The function Colors lets you retrieve all colors in a palette:

for _, c := range palette.Wikipedia.Colors() {
    fmt.Println(c.Name, c.Color)
}

This will print out a list of 1609 color names, as defined by Wikipedia.

Creating Your Own Palettes

var p gamut.Palette
p.AddColors(
    gamut.Colors{
        {"Name", gamut.Hex("#123456"), "Reference"},
        ...
    }
)

Name and Reference are optional when creating your own palettes.

Names

Each color in the curated palettes comes with an โ€œofficialโ€ name. You can filter palettes by colors with specific names. This code snippet will return a list of all โ€œblueโ€ colors in the Wikipedia palette:

colors = palette.Wikipedia.Filter("blue")

You can access a color with a specific name using the Color function:

color, ok = palette.Wikipedia.Color("Pastel blue")

Calling a paletteโ€™s Name function with a given color returns the name & distance of the closest (perceptually) matching color in it:

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

Mixing Palettes

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

p = palette.Crayola.MixedWith(palette.Monokai)

Perception

Sometimes you got a slice of colors, but you have a limited color palette to work with. The Clamped function returns a slice of the closest perceptually matching colors in a palette, maintaining the same order as the original slice you provided. Finally you can remix your favorite wallpapers in Crayola-style!

colors = palette.Crayola.Clamped(colors)

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:

colors, err = gamut.Generate(8, gamut.PastelGenerator{})

Pastel Palette

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

colors, err = gamut.Generate(8, gamut.SimilarHueGenerator{Color: gamut.Hex("#2F1B82")})

Similar Hue Palette

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

type BrightGenerator struct {
	BroadGranularity
}

func (cc BrightGenerator) Valid(col colorful.Color) bool {
	_, _, l := col.Lab()
	return 0.7 <= l && l <= 1.0
}

...
colors, err := gamut.Generate(8, BrightGenerator{})

Only colors with a lightness between 0.7 and 1.0 will be accepted by this generator.

Themes

Name Colors
Monokai 7

Roles

color = theme.MonokaiTheme.Role(theme.Foreground)

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

Feedback

Got some feedback or suggestions? Please open an issue or drop me a note!

More Repositories

1

duf

Disk Usage/Free Utility - a better 'df' alternative
Go
10,935
star
2

beehive

A flexible event/agent & automation system with lots of bees ๐Ÿ
Go
6,298
star
3

cache2go

Concurrency-safe Go caching library with expiration capabilities and access counters
Go
2,009
star
4

smartcrop

smartcrop finds good image crops for arbitrary crop sizes
Go
1,808
star
5

termenv

Advanced ANSI style & color support for your terminal applications
Go
1,712
star
6

gitomatic

A tool to monitor git repositories and automatically pull & push changes
Go
1,014
star
7

reflow

A collection of (ANSI-sequence aware) text reflow operations & algorithms
Go
450
star
8

gitty

Contextual information about your git projects, right on the command-line
Go
447
star
9

kmeans

k-means clustering algorithm implementation written in Go
Go
418
star
10

readme-scribe

A GitHub Action that automatically generates & updates markdown content (like your README.md)
396
star
11

crunchy

Finds common flaws in passwords. Like cracklib, but written in Go.
Go
378
star
12

obs-cli

OBS-cli is a command-line remote control for OBS
Go
306
star
13

regommend

Recommendation engine for Go
Go
303
star
14

markscribe

Your personal markdown scribe with template-engine and Git(Hub) & RSS powers ๐Ÿ“œ
Go
286
star
15

mango

mango is a man-page generator for the Go flag, pflag, cobra, coral, and kong packages
Go
229
star
16

docker-backup

A tool to create & restore complete, self-contained backups of Docker containers
Go
201
star
17

telephant

A lightweight but modern Mastodon client for the desktop
QML
193
star
18

go-app-paths

Lets you retrieve platform-specific paths (like directories for app-data, cache, config, and logs)
Go
175
star
19

deckmaster

An application to control your Elgato Stream Deck on Linux
Go
169
star
20

prism

An RTMP stream recaster / splitter
Go
150
star
21

asciicam

Displays your webcam... on the terminal
Go
124
star
22

gitflux

Track your GitHub projects in InfluxDB and create beautiful graphs with Grafana
Go
117
star
23

cancelreader

A cancelable reader for Go
Go
102
star
24

service-tools

A growing collection of convenient little tools to work with systemd services
Go
91
star
25

mastotool

A collection of command-line tools to work with your Mastodon account
Go
89
star
26

thunder

BoltDB's Interactive Shell
Go
80
star
27

sticker

A Golang lib to generate placeholder images with text
Go
79
star
28

toktok

Typo/error resilient, human-readable token generator
Go
67
star
29

sasquatch

A simple data encryption library
Go
56
star
30

combinator

Generates a slice of all possible value combinations for any given struct and a set of its potential member values
Go
48
star
31

lighthouse

A fully modular, parametric, and customizable case design. Built with OpenSCAD.
OpenSCAD
43
star
32

roff

roff lets you write roff documents in Go
Go
42
star
33

pam-beacon

PAM module for multi-factor authentication with Bluetooth Devices & Beacons
Go
41
star
34

streamdeck

An application and Go library to control your Elgato Stream Deck on Linux
Go
41
star
35

marky

Generate markdown programmatically
Go
40
star
36

sync3c

A little tool to sync/download media from https://media.ccc.de
Go
36
star
37

muesli

My secret muesli repo
33
star
38

huephp

PHP library to control the Philips Hue lighting system
PHP
33
star
39

obs-scene-switcher

Tracks your active window and switches OBS scenes accordingly
Go
32
star
40

mango-cobra

cobra adapter for mango
Go
31
star
41

scratchy

Quickly bootstrap a Linux distro in a (non-Docker) container and interactively execute something in it
Go
27
star
42

gitcha

Go helpers to work with git repositories
Go
25
star
43

ansi

Raw ANSI sequence helpers
Go
19
star
44

goprogressbar

Print progress bars on the console with Go
Go
19
star
45

ircflu

ircflu is an IRC bot written in Go
Go
19
star
46

go-razer

Go library to control Razer (Chroma) devices
Go
18
star
47

magicwand

MagicWand makes your input devices context sensitive
Go
17
star
48

gotable

Go helper to print a table of data to stdout
Go
15
star
49

goefa

A Go client for EFA APIs (Elektronische Fahrplan Auskunft)
Go
15
star
50

ydl

A simple youtube-dl library for Go
Go
15
star
51

xray

xray compares media files by their perceptual hash and identifies dupes
C++
15
star
52

clusters

Data structs and algorithms for clustering data observations and basic computations in n-dimensional spaces
Go
14
star
53

dotfiles

My dotfiles
Shell
14
star
54

saloon

Saloon, an Arduino/ESP-based Information Monitor
C++
13
star
55

cap-generator

OpenSCAD cap with thread generator
OpenSCAD
13
star
56

elvish-libs

Libs / Themes for elvish
13
star
57

ms-pacman

Handy scripts for Arch Linux users
Shell
12
star
58

silhouette

Silhouette cluster analysis implementation in Go
Go
11
star
59

penpal

A Linux daemon to sync Wacom Bamboo devices
Go
10
star
60

code-server

My code-server Docker image
Dockerfile
10
star
61

beehive-admin

Admin interface to Beehive - https://github.com/muesli/beehive
JavaScript
9
star
62

smolder

smolder makes it easy to write restful Golang JSON APIs
Go
9
star
63

mango-coral

coral adapter for mango
Go
8
star
64

deckmaster-emojis

A deck of emojis for Deckmaster
8
star
65

configaro

The Marriage of (Con)Figaro - A small but flexible config system that's XDG-compliant
6
star
66

smartcrop-samples

Sample images to test the smartcrop algorithm with
6
star
67

gominatim

Go library to access nominatim geocoding services
Go
5
star
68

go-pkg-rss

go-pkg-rss
Go
5
star
69

go-crashcourse

A Crash-Course in Learning Go
Go
5
star
70

homebrew-tap

muesli's Homebrew tap
Ruby
4
star
71

bones

A Golang Code Doctor
Go
4
star
72

mango-pflag

pflag adapter for mango
Go
3
star
73

polly

Polly wants a cracker
Go
3
star
74

maker-coin

A simple Maker Coin designed in OpenSCAD
Python
3
star
75

quaint

Image & static content HTTP server written in Go
Go
3
star
76

videowall

An interactive wall of live videos
C++
2
star
77

filament-swatch

Parameterized Filament Swatch / Sample Tag in OpenSCAD
OpenSCAD
2
star
78

flipdots

Go library to access OpenLab's flipdot matrix
Go
2
star
79

pkgbuilds

My collection of Arch Linux PKGBUILDs
Shell
2
star
80

beehive-vendor

Vendor files for Beehive
Go
2
star
81

QtGaugeWidget

Gauge widget for Qt
C++
1
star
82

go-pkg-xmlx

go-pkg-xmlx
Go
1
star
83

jigo

A set of #golang jigs
1
star
84

nibbler

Network logging daemon written in Go
Go
1
star
85

comunit

PASCAL interface to access serial COM ports
Pascal
1
star
86

tomahawk-iOS

Tomahawk iOS Player
Objective-C
1
star