colorutil

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: May 16, 2025 License: MIT Imports: 9 Imported by: 4

Documentation

Overview

Utilities for parsing and manipulating colors.

Index

Constants

View Source
const (
	Invalid lmodel = iota
	HSI
	HSL
	HSV
)

Variables

View Source
var ColorNames = map[string]string{}/* 139 elements not displayed */

Functions

func Equals

func Equals(first any, second any) bool

Return whether two colors are equivalent in the 24-bit RGB (RGB255) color space.

func HslToRgb

func HslToRgb(hue float64, saturation float64, lightness float64) (uint8, uint8, uint8)

Given HSL values (where hue is given in degrees (out of 360°), saturation and lightness are [0, 1]), return the corresponding RGB values (where each value is [0, 255]).

func HsvToRgb

func HsvToRgb(hue float64, saturation float64, value float64) (uint8, uint8, uint8)

Given HSL values (where hue is given in degrees (out of 360°), saturation and value are [0, 1]), return the corresponding RGB values (where each value is [0, 255]).

func RgbToHsl

func RgbToHsl(r float64, g float64, b float64) (float64, float64, float64)

Given RGB values (where each value is [0, 255]), return the hue (in degrees), saturation, and lightness (where each is [0, 1]).

Types

type Color

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

func AdjustHue

func AdjustHue(in any, degrees float64) (Color, error)

Adjust the hue of the given color by the specified number of degrees.

func Darken

func Darken(in any, percent int) (Color, error)

Darken the given color by a certain percent. Consistent with the results of the Sass darken() function.

func Desaturate added in v1.7.48

func Desaturate(in any, percent int) (Color, error)

Desaturate the given color by a certain percent. Consistent with the results of the Sass desaturate() function.

func KelvinToColor added in v1.8.13

func KelvinToColor(kelvin int) (color Color)

Takes a color temperature in degrees Kelvin and returns a valid Color for that temperature. This function works best between 1000K and 40000K.

func Lighten

func Lighten(in any, percent int) (Color, error)

Lighten the given color by a certain percent. Consistent with the results of the Sass lighten() function.

func Mix added in v1.7.48

func Mix(first any, second any) (Color, error)

Mix two colors in equal parts, producing a third.

func MixN added in v1.7.48

func MixN(first any, second any, weight float64) (Color, error)

Mix two colors, producing a third. The weight value specifies how much of the first color should be included. Consistent with the results of the Sass mix() function.

func MustParse

func MustParse(value any) Color

Parse the given value into a Color or panic.

func Parse

func Parse(value any) (Color, error)

Parse the given value into a Color or return an error.

func Saturate added in v1.7.48

func Saturate(in any, percent int) (Color, error)

Saturate the given color by a certain percent. Consistent with the results of the Sass saturate() function.

func (Color) Equals

func (self Color) Equals(other any) bool

Return whether the given color is equal to this one in the 24-bit RGB (RGB255) color space

func (Color) HSI

func (self Color) HSI() (float64, float64, float64)

Return the current color as hue (out of 360°), saturation [0, 1], and intensity [0, 1].

func (Color) HSL

func (self Color) HSL() (float64, float64, float64)

Return the current color as hue (out of 360°), saturation [0, 1], and lightness [0, 1].

func (Color) HSV

func (self Color) HSV() (float64, float64, float64)

Return the current color as hue (out of 360°), saturation [0, 1], and value [0, 1].

func (Color) IsZero added in v1.11.1

func (self Color) IsZero() bool

func (Color) MarshalJSON added in v1.8.74

func (self Color) MarshalJSON() ([]byte, error)

func (Color) NativeRGBA added in v1.8.73

func (self Color) NativeRGBA() (c color.RGBA)

Return the color as a color.RGBA struct.

func (Color) RGBA

func (self Color) RGBA() (uint32, uint32, uint32, uint32)

Return the current color as a 32-bit uint quad, implementing the color.Color interface.

func (Color) RGBA255

func (self Color) RGBA255() (uint8, uint8, uint8, uint8)

Return the current color as 4x 8-bit RGB values, each [0, 255].

func (Color) String

func (self Color) String() string

func (Color) StringHSLA

func (self Color) StringHSLA() string

func (Color) StringRGBA

func (self Color) StringRGBA() string

Jump to

Keyboard shortcuts

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