colours

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2023 License: BSD-3-Clause Imports: 5 Imported by: 6

README

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Colour

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

func NewColour

func NewColour(args ...interface{}) (Colour, error)

type CommonColour

type CommonColour struct {
	Colour          `json:",omitempty"`
	CommonName      string   `json:"name,omitempty"`
	CommonHex       string   `json:"hex"`
	CommonReference string   `json:"reference,omitempty"`
	CommonClosest   []Colour `json:"closest,omitempty"`
}

func (*CommonColour) AppendClosest

func (hc *CommonColour) AppendClosest(c Colour) error

func (*CommonColour) Hex

func (hc *CommonColour) Hex() string

func (*CommonColour) Name

func (hc *CommonColour) Name() string

func (*CommonColour) Reference

func (hc *CommonColour) Reference() string

func (*CommonColour) String

func (hc *CommonColour) String() string

type CommonPalette

type CommonPalette struct {
	Palette         `json:",omitempty"`
	CommonReference string          `json:"reference"`
	CommonColours   []*CommonColour `json:"colours,omitempty"`
}

func (*CommonPalette) Colours

func (p *CommonPalette) Colours() []Colour

func (*CommonPalette) Reference

func (p *CommonPalette) Reference() string

type Extruder

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

type Grid

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

type Palette

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

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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