Skip to content

Go package for working with colours, principally colour extraction and "snap to grid"

License

Notifications You must be signed in to change notification settings

aaronland/go-colours

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-colours

Go package for working with colours, principally colour extraction and "snap to grid"

Install

You will need to have both Go (specifically version 1.12 or higher because we're using Go modules) and the make programs installed on your computer. Assuming you do just type:

make tools

All of this package's dependencies are bundled with the code in the vendor directory.

Important

This is work in progress. Eventually it will be a complete port of the py-cooperhewitt-swatchbook and py-cooperhewitt-roboteyes-colors (and by extension RoyGBiv) packages, but today it is only a partial implementation.

Also, this documentation is incomplete.

Example

package main

import (
	"flag"
	"github.com/aaronland/go-colours/extruder"
	"github.com/aaronland/go-colours/grid"
	"github.com/aaronland/go-colours/palette"
	"image"
	_ "image/jpeg"
	"log"
	"os"
)

func main() {

	flag.Parse()

	ex, _ := extruder.NewNamedExtruder("vibrant")

	gr, _ := grid.NewNamedGrid("euclidian")

	p, _ := palette.NewNamedPalette("css4")

	for _, path := range flag.Args() {

		fh, _ := os.Open(path)
		im, _, _ := image.Decode(fh)

		colours, _ := ex.Colours(im, 5)

		for _, c := range colours {

			closest, _ := gr.Closest(c, p)

			for _, cl := range closest {
				log.Println(c, cl)
			}
		}

	}
}

Note that error handling has been removed for the sake of brevity.

Interfaces

Colour

type Colour interface {
	Name() string
	Hex() string
	Reference() string
	Closest() []Colour
	AppendClosest(Colour) error // I don't love this... (20180605/thisisaaronland)
	String() string
}

Extruder

type Extruder interface {
	Colours(image.Image, int) ([]Colour, error)
}

Grid

type Grid interface {
	Closest(Colour, Palette) (Colour, error)
}

Palette

type Palette interface {
	Reference() string
	Colours() []Colour
}

Extruders

Extruders are the things that generate a palette of colours for an image.Image.

vibrant

This returns colours using the vibrant package but rather than ranking colours using a particular metric it returns specific named "swatches" that are recast as colours.Colour interfaces. They are: VibrantSwatch, LightVibrantSwatch, DarkVibrantSwatch, MutedSwatch, LightMutedSwatch, DarkMutedSwatch.

Grids

Grids are the things that perform operations or compare colours.

euclidian

Palettes

Palettes are a fixed set of colours.

crayola

css3

css4

See also

About

Go package for working with colours, principally colour extraction and "snap to grid"

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published