COCO (Color Converter) is a color conversion library for Go.

COCO (Color Converter) for Go

COCO (Color Converter) is a color conversion library for Go. Heavily inspired by NPM's color-convert. It converts all ways between rgb, hsl, hsv, hwb, cmyk, and hex strings.

Install

Just run this:

go get github.com/hisamafahri/coco

Usage

  • RGB Base

You can change an RGB base value to other types of value. To use it:

import (
	"github.com/hisamafahri/coco"
)

// RGB to CMYK
coco.Rgb2Cmyk(140, 200, 100) // Output [4]float64: [30 0 50 22]

// RGB to HSL
coco.Rgb2Hsl(140, 200, 100) // Output [3]float64: [96 48 59]

// RGB to HSV
coco.Rgb2Hsv(140, 200, 100) // Output [3]float64: [96 50 78]

// RGB to HWB
coco.Rgb2Hwb(140, 200, 100) // Output [3]float64: [96 39 22]

// RGB to LAB
coco.Rgb2Lab(140, 200, 100) // Output [3]float64: [75 -37 44]

// RGB to XYZ
coco.Rgb2Hwb(140, 200, 100) // Output [3]float64: [34 48 20]

// RGB to HEX
coco.Rgb2Hex(140, 200, 100) // Output string: 8CC864

// RGB to HCG
coco.Rgb2Hcg(140, 200, 100) // Output [3]float64: [96 39 65]

// RGB to Apple
coco.Rgb2Apple(140, 200, 100) // Output [3]float64: [29041 54998 7710]

// RGB to Gray
coco.Rgb2Apple(140, 200, 100) // Output [1]float64: [58]
  • HSL Base

You can change an HSL base value to other types of value. To use it:

import (
	"github.com/hisamafahri/coco"
)

// HSL to RGB
coco.Hsl2Rgb(136, 54, 43) // Output [3]float64: [50 169 82]

// HSL to HSV
coco.Hsl2Hsv(136, 54, 43) // Output [3]float64: [136 70 66]

// HSL to HCG
coco.Hsl2Hsv(136, 54, 43) // Output [3]float64: [136 46 37]
  • HSV Base

You can change an HSV base value to other types of value. To use it:

import (
	"github.com/hisamafahri/coco"
)

// HSV to RGB
coco.Hsv2Rgb(4, 78, 92) // Output [3]float64: [235 64 52]

// HSV to HSL
coco.Hsv2Hsl(4, 78, 92) // Output [3]float64: [4 82 56]

// HSV to HCG
coco.Hsv2Hcg(4, 78, 92) // Output [3]float64: [4 72 72]
  • HWB Base

You can change an HWB base value to other types of value. To use it:

import (
	"github.com/hisamafahri/coco"
)

// HWB to RGB
coco.Hwb2Rgb(136, 0, 43) // Output [3]float64: [0 145 107]

// HWB to HCG
coco.Hwb2Hcg(136, 0, 43) // Output [3]float64: [136 57 0]
  • CMYK Base

You can change an CMYK base value to other types of value. To use it:

import (
	"github.com/hisamafahri/coco"
)

// CMYK to RGB
coco.Cmyk2Rgb(70, 0, 51, 34) // Output [3]float64: [50 168 82]
  • XYZ Base

You can change an XYZ base value to other types of value. To use it:

import (
	"github.com/hisamafahri/coco"
)

// XYZ to RGB
coco.Xyz2Rgb(21, 18, 5) // Output [3]float64: [166 103 46]

// XYZ to LAB
coco.Xyz2Lab(21, 18, 5) // Output [3]float64: [49 20 41]
  • LAB Base

You can change an LAB base value to other types of value. To use it:

import (
	"github.com/hisamafahri/coco"
)

// LAB to XYZ
coco.Lab2Xyz(50, 21, 38) // Output [3]float64: [22 18 6]

// LAB to LCH
coco.Lab2Lch(50, 21, 38) // Output [3]float64: [50 43 61]
  • LCH Base

You can change an LCH base value to other types of value. To use it:

import (
	"github.com/hisamafahri/coco"
)

// LCH to LAB
coco.Lab2Xyz(30, 79, 50) // Output [3]float64: [30 51 61]
  • HEX Base

You can change an HEX base value to other types of value. To use it:

import (
	"github.com/hisamafahri/coco"
)

// HEX to RGB
coco.Hex2Rgb("4287F5") // Output [3]uint8: [66 135 245]
  • HCG Base

You can change an HCG base value to other types of value. To use it:

import (
	"github.com/hisamafahri/coco"
)

// HCG to RGB
coco.Hcg2Rgb(44, 98, 50) // Output [3]float64: [252 186 3]

// HCG to HSV
coco.Hcg2Hsv(44, 98, 50) // Output [3]float64: [44 99 99]

// HCG to HSL
coco.Hcg2Hsl(44, 98, 50) // Output [3]float64: [44 98 50]

// HCG to HWB
coco.Hcg2Hwb(44, 98, 50) // Output [3]float64: [44 1 1]
  • Apple Base

You can change an Apple base value to other types of value. To use it:

import (
	"github.com/hisamafahri/coco"
)

// Apple to RGB
coco.Apple2Rgb(64764, 47802, 771) // Output [3]float64: [252 186 3]
  • Gray Base

You can change an Gray base value to other types of value. To use it:

import (
	"github.com/hisamafahri/coco"
)

// Gray to RGB
coco.Gray2Rgb(46) // Output [3]float64: [117 117 117]

// Gray to CMYK
coco.Gray2Cmyk(46) // Output [4]float64: [0 0 0 46]

// Gray to HEX
coco.Gray2Lab(46) // Output string: 757575

// Gray to HSL
coco.Gray2Hsl(46) // Output [3]float64: [0 0 46]

// Gray to HSV
coco.Gray2Hsv(46) // Output [3]float64: [0 0 46]

// Gray to HWB
coco.Gray2Hwb(46) // Output [3]float64: [0 100 46]

// Gray to LAB
coco.Gray2Lab(46) // Output [3]float64: [46 0 0]

Pending Implementation

  1. RGB to keyword
  2. Keyword to RGB
  3. Ansi16 & Ansi256

Author

Hisam A Fahri: @hisamafahri

License

MIT

Owner
Hisam Fahri
Attempting to make the world a better place, even just a little.
Hisam Fahri
Similar Resources

Maintain a lower-bitrate copy of a music library in sync with the main copy.

msync Maintain a lower-bitrate copy of your music library, in sync with the main copy.

Mar 6, 2022

Golang library to act on structure fields at runtime. Similar to Python getattr(), setattr(), hasattr() APIs.

go-attr Golang library to act on structure fields at runtime. Similar to Python getattr(), setattr(), hasattr() APIs. This package provides user frien

Dec 16, 2022

Go library for HTTP content type negotiation

Content-Type support library for Go This library can be used to parse the value Content-Type header (if one is present) and select an acceptable media

Jul 10, 2022

A tool and library for using structural regular expressions.

Structural Regular Expressions sregx is a package and tool for using structural regular expressions as described by Rob Pike (link).

Dec 7, 2022

A super simple Lodash like utility library with essential functions that empowers the development in Go

A super simple Lodash like utility library with essential functions that empowers the development in Go

A simple Utility library for Go Go does not provide many essential built in functions when it comes to the data structure such as slice and map. This

Jan 4, 2023

go-sysinfo is a library for collecting system information.

go-sysinfo go-sysinfo is a library for collecting system information. This includes information about the host machine and processes running on the ho

Dec 26, 2022

Molecule is a Go library for parsing protobufs in an efficient and zero-allocation manner

Molecule Molecule is a Go library for parsing protobufs in an efficient and zero-allocation manner. The API is loosely based on this excellent Go JSON

Jan 5, 2023

A Go (golang) library for parsing and verifying versions and version constraints.

go-version is a library for parsing versions and version constraints, and verifying versions against a set of constraints. go-version can sort a collection of versions properly, handles prerelease/beta versions, can increment versions, etc.

Jan 9, 2023

A library for parsing ANSI encoded strings

 A library for parsing ANSI encoded strings

Go ANSI Parser converts strings with ANSI escape codes into a slice of structs that represent styled text

Sep 20, 2022
Comments
  • Want help creating tests?

    Want help creating tests?

    Hey there!

    I need this package for a personal project, but it makes me nervous that it's not tested. I could just copy your code over into mine and test it there, but I'd much rather give back if possible. Would you like me to write up some tests along with a GitHub Action to run them?

efaceconv - Code generation tool for high performance conversion from interface{} to immutable type without allocations.

efaceconv High performance conversion from interface{} to immutable types without additional allocations This is tool for go generate and common lib (

May 14, 2022
Slice conversion between primitive types

sliceconv Sliceconv implements conversions to and from string representations of primitive types on entire slices. The package supports types int, flo

Sep 27, 2022
Highly configurable struct to map converter.

Mapify Highly configurable struct to map converter. Will convert maps into other maps as well (work in progress). Features configuration outside the s

Jul 30, 2022
Simple library to handle ANSI functions and parsing of color formatting strings

Emerald A basic color library for use in my Go projects, built on top of mgutz/ansi. Package ansi is a small, fast library to create ANSI colored stri

Oct 28, 2022
Go package to generate and manage color palettes & schemes 🎨
Go package to generate and manage color palettes & schemes 🎨

Go package to generate and manage color palettes & schemes

Dec 29, 2022
Color generator with golang
Color generator with golang

color-generator How to use this repo <img src="https://color-pallete-gen.herokuapp.com/hexCode" /> Like this: Getting Started Copy sample.env to .env

Oct 22, 2021
Wl-gammarelay - Wayland utility for changing color temperature using hotkeys

wl-gammarelay This utility was developed from gammastep, a fork of redshift as w

Nov 20, 2022
Color lets you use colorized outputs in terms of ANSI Escape Codes in Go (Golang)
Color lets you use colorized outputs in terms of ANSI Escape Codes in Go (Golang)

Color lets you use colorized outputs in terms of ANSI Escape Codes in Go (Golang). It has support for Windows too! The API can be used in several ways, pick one that suits you.

Feb 5, 2022
Easy to use open source hardware to drive WS2811 LEDs with high-quality color

STOP DOING FADECANDY LEDs were not supposed to be given data pins YEARS of "temporal dithering" but no real-world use found for having more than three

Dec 29, 2022
Govalid is a data validation library that can validate most data types supported by golang

Govalid is a data validation library that can validate most data types supported by golang. Custom validators can be used where the supplied ones are not enough.

Apr 22, 2022