hexer

package module
v0.0.0-...-3d62f7a Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2023 License: MIT Imports: 5 Imported by: 0

README

Hexer

Go version Go Report Card Build Tests Coverage License

A command line tool and Go library to inspect and manipulate hex colors.

Installation

go install github.com/devkvlt/hexer/cmd/hexer@latest

Usage

Run hexer or hexer help to get a list of available commands.

Run hexer help <cmd> to get detailed help about the command <cmd>.

Here are some examples of usage:

# Mix red and green
hexer mix "#ff0000" "#008000"

# Darken red by 10
hexer darken "#ff0000" 10

# Get the contrast ratio between red and green
hexer contratio "#ff0000" "#008000"

# Make 5 colors representing gradient colors between red and green
hexer grad "#ff0000" "#008000" 5

Usage as a library

go get github.com/devkvlt/hexer
package main

import (
	"fmt"
	"log"

	"github.com/devkvlt/hexer"
)

func main() {
	red := "#ff0000"
	green := "#008000"

	mix, err := hexer.Mix(red, green, 0.3)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(mix)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var WebColors = map[string]string{}/* 148 elements not displayed */

Functions

func AdjustToContrastRatio

func AdjustToContrastRatio(c1, c2 string, cr0 float64) (string, error)

AdjustToContrastRatio adjusts the lightness of the color c1 so that the contrast ratio between c1 and c2 is as close as possible to the given contrast ratio cr0.

func Blue

func Blue(hex string) (float64, error)

Blue returns the blue channel of a color and an error.

func ContrastRatio

func ContrastRatio(c1, c2 string) (float64, error)

ContrastRatio returns the CR of 2 colors.

func DarkPalette

func DarkPalette(c string, n int) ([]string, error)

DarkPalette

func Darken

func Darken(hex string, a float64) (string, error)

Darken darkens a color by subtracting the provided value from its lightness channel and returns the result and an error.

func Desaturate

func Desaturate(hex string, a float64) (string, error)

Desaturate unsaturates a color by subtracting the provided value from its saturation channel and returns the result and an error.

func Green

func Green(hex string) (float64, error)

Green returns the green channel of a color and an error.

func Hue

func Hue(hex string) (float64, error)

Hue returns the hue channel of a color and an error.

func Invert

func Invert(hex string) (string, error)

Invert returns the inverse of a color and an error.

func LightPalette

func LightPalette(c string, n int) ([]string, error)

LightPalette

func Lighten

func Lighten(hex string, a float64) (string, error)

Lighten lightens a color by adding the provided value to its lightness channel and returns the result and an error.

func Lightness

func Lightness(hex string) (float64, error)

Lightness returns the lightness channel of a color and an error.

func Luminance

func Luminance(c string) (float64, error)

Luminance returns the relative Luminance of a color. https://en.wikipedia.org/wiki/Relative_luminance

func Mix

func Mix(c1, c2 string, w float64) (string, error)

Mix mixes two colors using the given weight (of the first color) and returns the result and an error.

func MixPalette

func MixPalette(c1, c2 string, n int) ([]string, error)

MixPalette makes a slice of colors representing a palette of n equally distanced colors between c1 and c2 (c1 and c2 included) and returns it with an error.

func Red

func Red(hex string) (float64, error)

Red returns the red channel of a color and an error.

func Saturate

func Saturate(hex string, a float64) (string, error)

Saturate saturates a color by adding the provided value to its saturation channel and returns the result and an error.

func Saturation

func Saturation(hex string) (float64, error)

Saturation returns the saturation channel of a color and an error.

func SetBlue

func SetBlue(hex string, b float64) (string, error)

SetBlue sets the blue channel of a color to the provided value and returns the result and an error.

func SetGreen

func SetGreen(hex string, g float64) (string, error)

SetGreen sets the green channel of a color to the provided value and returns the result and an error.

func SetHue

func SetHue(hex string, h float64) (string, error)

SetHue sets the hue channel of a color to the provided value and returns the result and an error.

func SetLightness

func SetLightness(hex string, l float64) (string, error)

SetLightness sets the lightness channel of a color to the provided value and returns the result and an error.

func SetRed

func SetRed(hex string, r float64) (string, error)

SetRed sets the red channel of a color to the provided value and returns the result and an error.

func SetSaturation

func SetSaturation(hex string, s float64) (string, error)

SetSaturation sets the saturation channel of a color to the provided value and returns the result and an error.

Types

This section is empty.

Directories

Path Synopsis
cli
gen
cmd
hexer command

Jump to

Keyboard shortcuts

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