From 8bdfc9cca64116c078e2547f12c6d27a540f5799 Mon Sep 17 00:00:00 2001 From: Tai Groot Date: Sun, 2 Oct 2022 23:53:21 -0700 Subject: [PATCH] Create toHex apis --- simplecolor/simplecolors.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/simplecolor/simplecolors.go b/simplecolor/simplecolors.go index 44f6a71..750825d 100644 --- a/simplecolor/simplecolors.go +++ b/simplecolor/simplecolors.go @@ -1,6 +1,7 @@ package simplecolor import ( + "fmt" "image/color" "sort" "strconv" @@ -22,6 +23,17 @@ func (s SimplePalette) ToPalette() color.Palette { return color.Palette(x) } +func (c SimpleColor) ToHex() string { + return "#" + fmt.Sprintf("%06X", c) +} + +func (c SimpleColor) ToShortHex() string { + value := c >> 16 & 0xF + value += c >> 8 & 0xF + value += c & 0xF + return "#" + fmt.Sprintf("%06X", value) +} + func (s SimpleColor) RGBA() (r, g, b, a uint32) { return uint32(s) >> 16 & 0xFF, uint32(s) >> 8 & 0xFF, uint32(s) & 0xFF, 0xFF }