palette

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2020 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package palette provides basic color palette handling.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// ErrOverflow is the error returned by ColorMaps when the specified
	// value is greater than the maximum value.
	ErrOverflow = errors.New("palette: specified value > maximum")

	// ErrUnderflow is the error returned by ColorMaps when the specified
	// value is less than the minimum value.
	ErrUnderflow = errors.New("palette: specified value < minimum")

	// ErrNaN is the error returned by ColorMaps when the specified
	// value is NaN.
	ErrNaN = errors.New("palette: specified value == NaN")
)
View Source
var HSVAModel = color.ModelFunc(hsvaModel)

HSVAModel converts any color.Color to an HSVA color.

Functions

This section is empty.

Types

type ColorMap

type ColorMap interface {
	// At returns the color associated with the given value.
	// If the value is not between Max() and Min(), an error is returned.
	At(float64) (color.Color, error)

	// Max returns the current maximum value of the ColorMap.
	Max() float64

	// SetMax sets the maximum value of the ColorMap.
	SetMax(float64)

	// Min returns the current minimum value of the ColorMap.
	Min() float64

	// SetMin sets the minimum value of the ColorMap.
	SetMin(float64)

	// Alpha returns the opacity value of the ColorMap.
	Alpha() float64

	// SetAlpha sets the opacity value of the ColorMap. Zero is transparent
	// and one is completely opaque. The default value of alpha should be
	// expected to be one. The function should be expected to panic
	// if alpha is not between zero and one.
	SetAlpha(float64)

	// Palette creates a Palette with the specified number of colors
	// from the ColorMap.
	Palette(colors int) Palette
}

A ColorMap maps scalar values to colors.

func Reverse

func Reverse(c ColorMap) ColorMap

Reverse reverses the direction of ColorMap c.

Example

This example creates a color bar and a second color bar where the direction of the colors are reversed.

package main

import (
	"log"

	"github.com/elamre/plot"
	"github.com/elamre/plot/palette"
	"github.com/elamre/plot/palette/moreland"
	"github.com/elamre/plot/plotter"
)

func main() {
	p, err := plot.New()
	if err != nil {
		log.Panic(err)
	}
	l := &plotter.ColorBar{ColorMap: moreland.Kindlmann()}
	l2 := &plotter.ColorBar{ColorMap: palette.Reverse(moreland.Kindlmann())}
	l.ColorMap.SetMin(0.5)
	l.ColorMap.SetMax(2.5)
	l2.ColorMap.SetMin(2.5)
	l2.ColorMap.SetMax(4.5)

	p.Add(l, l2)
	p.HideY()
	p.X.Padding = 0
	p.Title.Text = "A ColorMap and its Reverse"

	if err = p.Save(300, 48, "testdata/reverse.png"); err != nil {
		log.Panic(err)
	}
}
Output:

Example (Palette)

This example creates a color palette from a reversed ColorMap.

package main

import (
	"fmt"
	"log"

	"github.com/elamre/plot"
	"github.com/elamre/plot/palette"
	"github.com/elamre/plot/palette/moreland"
	"github.com/elamre/plot/plotter"
)

func main() {
	p, err := plot.New()
	if err != nil {
		log.Panic(err)
	}
	thumbs := plotter.PaletteThumbnailers(palette.Reverse(moreland.Kindlmann()).Palette(10))
	for i, t := range thumbs {
		p.Legend.Add(fmt.Sprint(i), t)
	}
	p.HideAxes()
	p.X.Padding = 0
	p.Y.Padding = 0

	if err = p.Save(35, 120, "testdata/reverse_palette.png"); err != nil {
		log.Panic(err)
	}
}
Output:

type DivergingColorMap

type DivergingColorMap interface {
	ColorMap

	// SetConvergePoint sets the value where the diverging colors
	// should meet. The default value should be expected to be
	// (Min() + Max()) / 2. It should be expected that calling either
	// SetMax() or SetMin() will set a new default value, so for a
	// custom convergence point this function should be called after
	// SetMax() and SetMin(). The function should be expected to panic
	// if the value is not between Min() and Max().
	SetConvergePoint(float64)

	// ConvergePoint returns the value where the diverging colors meet.
	ConvergePoint() float64
}

DivergingColorMap maps scalar values to colors that diverge from a central value.

type DivergingPalette

type DivergingPalette interface {
	Palette

	// CriticalIndex returns the indices of the lightest
	// (median) color or colors in the DivergingPalette.
	// The low and high index values will be equal when
	// there is a single median color.
	CriticalIndex() (low, high int)
}

DivergingPalette is a collection of colors ordered into a palette with a critical class or break in the middle of the color range.

func Radial

func Radial(colors int, start, end Hue, alpha float64) DivergingPalette

Radial return a diverging palette across the specified range, through white and with the specified alpha.

type HSVA

type HSVA struct {
	H, S, V, A float64
}

HSVA represents a Hue/Saturation/Value/Alpha color. H, S, V and A are valid within [0, 1].

func (HSVA) RGBA

func (c HSVA) RGBA() (r, g, b, a uint32)

RGBA allows HSVAColor to satisfy the color.Color interface.

type Hue

type Hue float64

Hue represents a hue in HSV color space. Valid Hues are within [0, 1].

const (
	Red Hue = Hue(iota) / 6
	Yellow
	Green
	Cyan
	Blue
	Magenta
)

func (Hue) Complement

func (h Hue) Complement() Hue

Complement returns the complementary hue of a Hue.

type Palette

type Palette interface {
	Colors() []color.Color
}

Palette is a collection of colors ordered into a palette.

func Heat

func Heat(colors int, alpha float64) Palette

Heat returns a red to yellow palette with the specified number of colors and alpha.

func Rainbow

func Rainbow(colors int, start, end Hue, sat, val, alpha float64) Palette

Rainbow returns a rainbow palette with the specified number of colors, saturation value and alpha, and hues in the specified range.

Directories

Path Synopsis
Package brewer provides Brewer Palettes for informative graphics.
Package brewer provides Brewer Palettes for informative graphics.
Package moreland provides color maps for pseudocoloring scalar fields.
Package moreland provides color maps for pseudocoloring scalar fields.

Jump to

Keyboard shortcuts

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