A Go package for converting RGB and other color formats/colorspaces into DMC thread colors (DMC color name and floss number)

go-c2dmc

A Go package for converting RGB and other color formats/colorspaces into DMC thread colors (DMC color name and floss number). Implemented as a wrapper for a handful of pieces of functionality from the go-colorful package with additional functionality to return DMC thread colors. Supports Go 1.13 onwards.

Why?

When wanting to build a personal project that invloves DMC thread colors, I could only find one pre-written package for converting RGB values into DMC thread colors (and their corresponding floss numbers) or finding the closest match. However, the package I found was written in R and I wanted to build the project I had in mind in Go. I explored methods of using this newly-found R package and found some interesting solutions. One being a "proxy" of sorts between Go and R written in C. While that solution was cool nonetheless, it felt much too bloated for the usecase I was encountering, as I would only be needing to use the return value from one single function in one single R package and not calling between Go and R several different times. Another option I had was to learn R enough to use the package to do the calculations and print the result to a blank text file, which my Go program would subsequently read from. But again, that required learning R. Which, if I'm being honest, is soemthing I would like to tackle. But my main goal was to get better at Go, specifically. So, seeing as there were no existing Go packages, I decided I would build my own (for the first time!) and share it with other developers who may run into this niche problem.

What?

go-c2dmc is a go package that allow a developer calculate the closest (if not exact) match to DMC color threads. The ColorBank is populated with values matching DMC color threads (and their floss numbers) to RBG and Hexcode values already calculated by threadcolors.com go-c2dmc can calculate the closest match from this list with any provided RGB, HSV, LAB, or Hexcode values by calculating the distance in LAB colorspace using the amazing go-colorful package.

For more information regarding the accuracy of these calculations specific to each colorspace, please refer to the go-colorful README

How do I use go-c2dmc?

Installing

To install go-c2dmc, simply run

$ go get github.com/syke99/go-c2dmc

Then you can import the package in any go file you'd like

import "github.com/syke99/go-c2dmc"

Basic usage

Calculate the closest DMC thread color based on provided RGB values

// Initialize the ColorBank to have DMC colors to test against
cb := dmc.NewColorBank()

// Call cb.Rgb() and pass in RGB values
color, floss := cb.Rgb(245.0, 173.0, 173.0)

fmt.SprintF("DMC Color Name: %s, Floss number: %s", color, floss)

Running the above calculation will return:

DMC Color Name: Salmon, Floss number: 760

And then converting this RGB color into LAB and HSV colorspaces, as well as hexcode:

l, a, b := cb.RgbLab(245.0, 173.0, 173.0)
h, s, v := cb.RgbHsv(245.0, 173.0, 173.0)
hexcode := cb.RgbHex(245.0, 173.0, 173.0)

Who?

This library was developed by Quinn Millican (@syke99)

License

This repo is under the MIT license, see LICENSE for details.

Similar Resources

Go-colorful: A library for playing with colors in golang

Go-colorful: A library for playing with colors in golang

go-colorful A library for playing with colors in Go. Supports Go 1.13 onwards. Why? I love games. I make games. I love detail and I get lost in detail

Dec 30, 2022

Light weight Terminal User Interface (TUI) to pick material colors written by Go.

Light weight Terminal User Interface (TUI) to pick material colors written by Go.

mcpick Light weight Terminal User Interface (TUI) to pick material colors. You do NOT need to take your hands off the keyboard to pick colors. Getting

Dec 27, 2022

Color package for Go (golang)

Color package for Go (golang)

color 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 severa

Dec 31, 2022

cTRL is a server for remote execution of pending tasks and commands in real time, supporting a queue with continuous thread limiting and throttling.

Документация на русском: https://github.com/eltaline/ctrl/blob/master/README-RUS.md cTRL is a server written in Go language that uses a modified versi

Mar 3, 2022

A really basic thread-safe progress bar for Golang applications

A really basic thread-safe progress bar for Golang applications

progressbar A very simple thread-safe progress bar which should work on every OS without problems. I needed a progressbar for croc and everything I tr

Jan 1, 2023

Use the command to convert arbitrary formats to Go Struct (including json, toml, yaml, etc.)

go2struct-tool Use the command to convert arbitrary formats to Go Struct (including json, toml, yaml, etc.) Installation Run the following command und

Dec 16, 2021

Go package to make lightweight ASCII line graph ╭┈╯ in command line apps with no other dependencies.

Go package to make lightweight ASCII line graph ╭┈╯ in command line apps with no other dependencies.

asciigraph Go package to make lightweight ASCII line graphs ╭┈╯. Installation go get github.com/guptarohit/asciigraph Usage Basic graph package main

Jan 8, 2023

Needlessly complex program to parse, increment, and push the latest version number tag on github. Made with 😫 , 😓 & 😭

increment What is this? Needlessly complex program to parse, increment, and push the latest version number tag on github. Err handling by Sentry Made

Feb 28, 2022

lls is lightweight ls. Using lls, you can get a list of files in a directory that contains a large number of files.

lls lls is lightweight ls. Using lls, you can get a list of files in a directory that contains a large number of files. How? You allocate a buffer for

Dec 29, 2022
Comments
  • Please define RGB/DMC

    Please define RGB/DMC

    Working on computers, I know what RGB is, but not DMC. I expect people who use DMC, know what DMC is. But as a casual passerby, it would be nice if you defined your acronyms.

Chalk is a Go Package which can be used for making terminal output more vibrant with text colors, text styles and background colors.
Chalk is a Go Package which can be used for making terminal output more vibrant with text colors, text styles and background colors.

Chalk Chalk is a Go Package which can be used for making terminal output more vibrant with text colors, text styles and background colors. Documentati

Oct 29, 2022
A simple command line tool using which you can skip phone number based SMS verification by using a temporary phone number that acts like a proxy.
A simple command line tool using which you can skip phone number based SMS verification by using a temporary phone number that acts like a proxy.

Fake-SMS A simple command line tool using which you can skip phone number based SMS verification by using a temporary phone number that acts like a pr

Dec 31, 2022
Fast, realtime regex-extraction, and aggregation into common formats such as histograms, numerical summaries, tables, and more!
Fast, realtime regex-extraction, and aggregation into common formats such as histograms, numerical summaries, tables, and more!

rare A file scanner/regex extractor and realtime summarizor. Supports various CLI-based graphing and metric formats (histogram, table, etc). Features

Dec 29, 2022
Golang package with functionality to add colors to your logs to the terminal.
Golang package with functionality to add colors to your logs to the terminal.

colrz It's a set of funcs and constants to provide basic colors to your terminal app. How to use Get it go get github.com/unnamedxaer/colrz Use it pac

Sep 15, 2022
Rdelf2json - CLI application for parsing ELF and converting to json

rdelf2json CLI application for parsing ELF and converting to json Install go ins

Jan 22, 2022
A command line tool for quickly converting Unix timestamps to human readable form.

stamp A command line tool to quickly format a Unix timestamp in a human-readable form. Installation Go is required to build this software. To just bui

Oct 30, 2021
An excellent tool for converting json files to structs or classes in any programming language.
An excellent tool for converting json files to structs or classes in any programming language.

Explore Usage » Report Bug · Request Feature Table of Contents About The Project Supported Languages Getting Started Usage Parameters Set Up Your Own

Dec 10, 2022
Donald Knuth's Algorithm 7.2.2.1M for covering with multiplicities and colors via dancing links

Covering with multiplicities and colors via Dancing Links Go implementation of Donald Knuth's Algorithm 7.2.2.1M for covering with multiplicities and

Dec 14, 2022
Detects whether a terminal supports colors
Detects whether a terminal supports colors

Termcolor Detects what level of color support your terminal has. This package is heavily inspired by chalk's support-color module. Install go get gith

Nov 27, 2022
CLI hex dumper with colors
CLI hex dumper with colors

heksa Hex dumper with colors Features ANSI colors for different byte groups such as Printable: A-Z, a-z, 0-9 Spaces: space, tab, new line Special: 0x0

Sep 27, 2022