Skip to content

Nadim147c/go-chroma

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chroma

GitHub go.mod Go version GitHub Repo stars GitHub License GitHub Tag

Important

🔥 Found this useful? A quick star goes a long way.

An opinionated Go library for working with colors. These color types model color spaces but do not implement color.Color or color.Model.

This is a semi-read-only clone of github.com/Nadim147c/material/v2. This package only contains color models. Files prefixed with zz_* are generated using go run ./generate.

  • ARGB
  • Cam16
  • Hct
  • LCHab
  • LCHuv
  • Lab
  • LinearRGB
  • Luv
  • Model
  • OkLab
  • OkLch
  • XYZ

Install

go get -u github.com/Nadim147c/go-chroma

Usage

Generate 10 shade of a color from a random hue. These colors are perceptually linear.

package main

import (
	"fmt"
	"math/rand"

	"github.com/Nadim147c/go-chroma"
	"github.com/Nadim147c/go-chroma/num"
)

func main() {
	const count = 10.0 // generate 10 colors
	const steps = 100 / (count - 1)
	hue := rand.Float64() * 360 // random hue

	palette := make([]chroma.ARGB, count)
	for i := range palette {
		tc := num.Clamp(5, 95, float64(i)*steps)
		palette[i] = chroma.Hct{Hue: hue, Chroma: tc, Tone: tc}.ToARGB()
		fmt.Println(palette[i].AnsiBg("       "))
	}
}

Preview

License

This code is licensed under the original Apache 2.0.

About

🌈 An opinionated Go library for working with colors.

Topics

Resources

License

Stars

Watchers

Forks

Contributors