color

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2022 License: Apache-2.0 Imports: 7 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Black       = &Named{"black", blackRGB}
	DarkBlue    = &Named{"dark_blue", darkBlueRGB}
	DarkGreen   = &Named{"dark_green", darkGreenRGB}
	DarkAqua    = &Named{"dark_aqua", darkAquaRGB}
	DarkRed     = &Named{"dark_red", darkRedRGB}
	DarkPurple  = &Named{"dark_purple", darkPurpleRGB}
	Gold        = &Named{"gold", goldRGB}
	Gray        = &Named{"gray", grayRGB}
	DarkGray    = &Named{"dark_gray", darkGrayRGB}
	Blue        = &Named{"blue", blueRGB}
	Green       = &Named{"green", greenRGB}
	Aqua        = &Named{"aqua", aquaRGB}
	Red         = &Named{"red", redRGB}
	LightPurple = &Named{"light_purple", lightPurpleRGB}
	Yellow      = &Named{"yellow", yellowRGB}
	White       = &Named{"white", whiteRGB}

	// NamesOrder is the order of the named colors.
	NamesOrder = []*Named{
		Black,
		DarkBlue,
		DarkGreen,
		DarkAqua,
		DarkRed,
		DarkPurple,
		Gold,
		Gray,
		DarkGray,
		Blue,
		Green,
		Aqua,
		Red,
		LightPurple,
		Yellow,
		White,
	}

	// Names is a map of the named colors.
	Names = func() map[string]*Named {
		m := map[string]*Named{}
		for _, a := range NamesOrder {
			m[a.Name] = a
		}
		return m
	}()
)

Minecraft named color.

View Source
var InvalidFormatErr = errors.New("color.Hex: invalid format")

Functions

This section is empty.

Types

type Color

type Color interface {
	fmt.Stringer
	color.Color
	Hex() string   // Returns the hex "html" representation of the color, as in #ff0080.
	Named() *Named // Returns the exact or nearest Named color.
}

Color is the interface for a Minecraft text color, either Named or RGB (for Hex).

type Named

type Named struct {
	Name string
	*RGB
}

Named is a Minecraft named text color.

func (*Named) Named

func (n *Named) Named() *Named

func (*Named) String

func (n *Named) String() string

String implements Color interface.

type RGB

type RGB colorful.Color

RGB is a Minecraft text color.

func Hex

func Hex(hex string) (col *RGB, err error)

Hex parses a web color given by its hex RGB format. See https://en.wikipedia.org/wiki/Web_colors for input format.

Modified version of https://stackoverflow.com/a/54200713/1705598.

func HexInt

func HexInt(hex int) *RGB

HexInt parses a web color given by its hex RGB format.

func Make

func Make(c color.Color) (*RGB, bool)

Make constructs an RGB from Go's color.Color interface.

func MustHex

func MustHex(hex string) *RGB

MustHex parses a "html" hex color-string, either in the 3 "#f0c" or 6 "#ff1034" digits form. It panics on error.

func (*RGB) Distance

func (c *RGB) Distance(c2 *RGB) float64

Distance computes the distance between two colors in RGB space.

func (*RGB) Hex

func (c *RGB) Hex() string

Hex returns the hex "html" representation of the color, as in #ff0080.

func (*RGB) Named

func (c *RGB) Named() *Named

func (*RGB) NearestNamed

func (c *RGB) NearestNamed() *Named

NearestNamed finds the nearest Named color for to this RGB.

func (*RGB) RGBA

func (c *RGB) RGBA() (r uint32, g uint32, b uint32, a uint32)

RGBA makes RGB implement the Go color.RGB interface.

func (*RGB) String

func (c *RGB) String() string

String implements Color interface.

Jump to

Keyboard shortcuts

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