Documentation
¶
Index ¶
- Constants
- Variables
- type Color
- func (l Color) AddChannels(r Color) Color
- func (l Color) Clamp(min, max float64) Color
- func (l Color) Equal(r Color) bool
- func (c Color) Hex() string
- func (l Color) MinChannels(r Color) Color
- func (l Color) MultiplyChannels(r Color) Color
- func (c Color) NRGBA() color.NRGBA
- func (c Color) Scale(s float64) Color
- type Drift
- type DriftingSource
- type Error
- type Hue
- type Lit
- type Opacity
- type RandomSource
- type Sat
- type Source
- type SourceOption
Constants ¶
const ExpectedHash = Error("Parse Error: expected # as first character for color reference")
const InvalidLength = Error("Parse Error: color reference does not have a valid length")
const InvalidPattern = Error("Parse Error: color reference does not match pattern #rrggbbaa or #rrggbb")
Variables ¶
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 ¶
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 ¶
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 ¶
AddChannels adds the channels of the current Color with each respective channel from the supplied Color object.
func (Color) Clamp ¶
Clamp clamps each rgb channel to the supplied minimum and maximum scalar values.
func (Color) Equal ¶
Equal returns true when the colors have both equal color components as well as equal alpha value.
func (Color) Hex ¶
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 ¶
MinChannels takes the minimum between each channel of the current Color and the supplied Color object.
func (Color) MultiplyChannels ¶
MultiplyChannels multiplies the channels of the current Color with each respective channel from the supplied Color object.
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 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 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.