colorhash

package
v0.0.24 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// FNVHasher is the alternative hasher for color hashing.
	FNVHasher = func() hash.Hash32 { return fnv.New32a() }
	// DJB2Hasher is the string hasher used for color hashing.
	DJB2Hasher = newDJB32
)

Functions

func RGBHex

func RGBHex(c color.RGBA) string

RGBHex converts the given color to a HTML hex color string. The alpha value is ignored.

func SetDefaultHasher

func SetDefaultHasher(hasher Hasher)

SetDefaultHasher sets the default hasher that the package uses.

Types

type HSVHasher

type HSVHasher struct {
	H func() hash.Hash32 // hashing function
	S [2]float64         // saturation
	V [2]float64         // value
}

HSVHasher describes a color hasher that accepts saturation and value parameters in the HSV color space.

func (HSVHasher) Hash

func (h HSVHasher) Hash(name string) color.RGBA

Hash hashes the given name using the parameters inside HSVHasher.

type Hasher

type Hasher interface {
	Hash(name string) color.RGBA
}

Hasher describes a string hasher that outputs a color.

var (
	// LightColorHasher generates a pastel color name for use with a dark
	// background.
	LightColorHasher Hasher = HSVHasher{
		FNVHasher,
		[2]float64{0.3, 0.4},
		[2]float64{0.9, 1.0},
	}
	// DarkColorHasher generates a darker, stronger color name for use with a
	// light background.
	DarkColorHasher Hasher = HSVHasher{
		FNVHasher,
		[2]float64{0.9, 1.0},
		[2]float64{0.6, 0.7},
	}
)

func DefaultHasher

func DefaultHasher() Hasher

DefaultHasher returns the default color hasher.

Jump to

Keyboard shortcuts

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