colour

package
v0.0.0-...-59476ba Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2018 License: MIT Imports: 6 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Black   = RGB{Red: 0.0, Green: 0.0, Blue: 0.0}
	White   = RGB{Red: 1.0, Green: 1.0, Blue: 1.0}
	Red     = RGB{Red: 1.0, Green: 0.0, Blue: 0.0}
	Green   = RGB{Red: 0.0, Green: 1.0, Blue: 0.0}
	Blue    = RGB{Red: 0.0, Green: 0.0, Blue: 1.0}
	Yellow  = RGB{Red: 1.0, Green: 1.0, Blue: 0.0}
	Magenta = RGB{Red: 1.0, Green: 0.0, Blue: 1.0}
	Cyan    = RGB{Red: 0.0, Green: 1.0, Blue: 1.0}
	Orange  = RGB{Red: 1.0, Green: 0.5, Blue: 0.0}
)

Functions

func RGBDistance

func RGBDistance(c1 RGB, c2 RGB) float64

RGBDistance quantifies the value difference between two RGB structs, returning a floating-point ratio from 0.0 to 1.0. Multiply the returned value by100 for a percentage. NOTE: this is a distinct concept from the distance between them as 3D vectors, as there would be 2 other RGB for any RGB with an identical magnitude. e.g. [1.0 0 0] [0 1.0 0] [0 0 1.0] will all have the same magnitude, but are pure Red, pure Blue, pure Green respectively!

Types

type RGB

type RGB struct {
	Red   float64 `json:"red"`
	Green float64 `json:"green"`
	Blue  float64 `json:"blue"`
}

RGB stores a floating-point representation of 3 colour channel RGB colour (Red Green Blue), where each value is in range [0,1] Colours live in a form of vector space.

func RandRGB

func RandRGB() RGB

RandRGB will return a random valid RGB object within the complete range of all possible RGB values.

func RandRGBClamped

func RandRGBClamped(col RGB, diff float64) RGB

RandRGBClamped will return a random valid RGB object within some differential of `col`

func (RGB) Invert

func (rgb RGB) Invert() (inv RGB)

Invert the value for each channel

func (*RGB) MarshalJSON

func (mj *RGB) MarshalJSON() ([]byte, error)

func (*RGB) MarshalJSONBuf

func (mj *RGB) MarshalJSONBuf(buf fflib.EncodingBuffer) error

func (*RGB) To256

func (rgb *RGB) To256() (conv RGB256)

To256 returns the conversion from floating point ranged RGB values to those in range [0,256)

func (*RGB) UnmarshalJSON

func (uj *RGB) UnmarshalJSON(input []byte) error

func (*RGB) UnmarshalJSONFFLexer

func (uj *RGB) UnmarshalJSONFFLexer(fs *fflib.FFLexer, state fflib.FFParseState) error

type RGB256

type RGB256 struct {
	Red   byte `json:"red"`
	Green byte `json:"green"`
	Blue  byte `json:"blue"`
}

RGB256 stores a integer representation of 3 colour channel RGB colour (Red Green Blue), where each value is in range [0,256)

func RandRGB256

func RandRGB256() RGB256

RandRGB256 will return a random colour value

func (*RGB256) MarshalJSON

func (mj *RGB256) MarshalJSON() ([]byte, error)

func (*RGB256) MarshalJSONBuf

func (mj *RGB256) MarshalJSONBuf(buf fflib.EncodingBuffer) error

func (*RGB256) UnmarshalJSON

func (uj *RGB256) UnmarshalJSON(input []byte) error

func (*RGB256) UnmarshalJSONFFLexer

func (uj *RGB256) UnmarshalJSONFFLexer(fs *fflib.FFLexer, state fflib.FFParseState) error

Jump to

Keyboard shortcuts

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