color

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const ExpectedHash = Error("Parse Error: expected # as first character for color reference")
View Source
const InvalidLength = Error("Parse Error: color reference does not have a valid length")
View Source
const InvalidPattern = Error("Parse Error: color reference does not match pattern #rrggbbaa or #rrggbb")

Variables

View Source
var (
	// White is a shortcut for the white color
	White = Color{1.0, 1.0, 1.0, 1.0}

	// Grey is a shortcut for the grey color.
	Grey = Color{0.5, 0.5, 0.5, 1.0}

	// Black is a shortcut for the black color.
	Black = Color{0.0, 0.0, 0.0, 1.0}
)

Functions

This section is empty.

Types

type Color

type Color struct {
	R, G, B, A float64
}

Color objects store RGB and Alpha values with components in range [0..1]

func ColorHSL

func ColorHSL(h, s, l, a float64) Color

ColorHSL creates a new `Color` using the supplied hue, saturation, and lightness (HSL) values. Each value must be in the range [0.0, 1.0].

func ColorWithString

func ColorWithString(s string) (c Color, err error)

ColorWithString creates a color based on a string pattern #rgb, #rgba, #rrggbb or #rrggbbaa where the color components are hexadecimal values between 0 and 0xff. e.g. #ffffffff is white fully opaque.

func (Color) AddChannels

func (l Color) AddChannels(r Color) Color

AddChannels adds the channels of the current Color with each respective channel from the supplied Color object.

func (Color) Clamp

func (l Color) Clamp(min, max float64) Color

Clamp clamps each rgb channel to the supplied minimum and maximum scalar values.

func (Color) Equal

func (l Color) Equal(r Color) bool

Equal returns true when the colors have both equal color components as well as equal alpha value.

func (Color) Hex

func (c Color) Hex() string

Hex returns a color string according to the following pattern #rrggbb Where the components are hexadecimal values between 0 and 0xff. The alpha component is left out of the string.

func (Color) MinChannels

func (l Color) MinChannels(r Color) Color

MinChannels takes the minimum between each channel of the current Color and the supplied Color object.

func (Color) MultiplyChannels

func (l Color) MultiplyChannels(r Color) Color

MultiplyChannels multiplies the channels of the current Color with each respective channel from the supplied Color object.

func (Color) NRGBA

func (c Color) NRGBA() color.NRGBA

NRGBA returns the color as an NRGBA value.

func (Color) Scale

func (c Color) Scale(s float64) Color

Scale returns a Color with the rgb channels scaled by the supplied scalar value.

type Drift

type Drift float64

Drift default is 0.03

func (Drift) Value

func (v Drift) Value() float64

type DriftingSource

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

DriftingSource is a source of colors where each newly returned color has a slightly different Hue w.r.t. the previously generated color. The Drift (default 0.03) inidicates how much the hue is allowed to drift from the previous value. The Sat (default 0.5) and Lit (default 0.4) indicate the saturation and lightness of the generated colors. The Opacity (default 1.0) indicates the opacity of the generated colors. The initial hue is randomly generated.

func NewDriftingSource

func NewDriftingSource() *DriftingSource

NewDriftingSource creates a color source that returns a sequence of colors where the hue of each color is slightly different from the previous color. The color source's options are by default:

Drift(0.03)
Hue(rand.Float64())
Sat(0.5)
Lit(0.4)
Opacity(1.0)

func NewDriftingSourceWith

func NewDriftingSourceWith(options ...SourceOption) *DriftingSource

NewDriftingSourceWith createsa a color source that returns a sequence of colors where the hue of each color is slightly different from the previous color. The options of the color source can be set by passing in options to the function. The default options are as follows:

Drift(0.03)
Hue(rand.Float64())
Sat(0.5)
Lit(0.4)
Opacity(1.0)

func (*DriftingSource) Read

func (c *DriftingSource) Read() Color

type Error

type Error string

func (Error) Error

func (e Error) Error() string

type Hue

type Hue float64

Hue default is a random value in the range [0-1]

func (Hue) Value

func (v Hue) Value() float64

type Lit

type Lit float64

Lit default is 0.4

func (Lit) Value

func (v Lit) Value() float64

type Opacity

type Opacity float64

Opacity default is 1.0

func (Opacity) Value

func (v Opacity) Value() float64

type RandomSource

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

RandomSource generates a new random color every time it is called.

func NewRandomSource

func NewRandomSource() *RandomSource

NewRandomSource generates a random hue every time a Color is read. It uses the default values Sat: 0.5, Lit: 0.4 and Opacity: 1.0 as parameters for the `ColorHsl()“ function.

func NewRandomSourceWith

func NewRandomSourceWith(options ...SourceOption) *RandomSource

NewRandomSourceWith is used to intialize the instance of a RandomColorSource with options.

func (*RandomSource) Read

func (c *RandomSource) Read() Color

type Sat

type Sat float64

Sat default is 0.5

func (Sat) Value

func (v Sat) Value() float64

type Source

type Source interface {
	Read() Color
}

Source is an interface to a color source. It is used for generating a sequence of random colors that are slightly different.

type SourceOption

type SourceOption interface {
	Value() float64
}

SourceOption is the interface type for passing in color options to a source creation function.

Jump to

Keyboard shortcuts

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