From 5c6cb8e0c944c8997c6059cf7ccaeeee353e4de9 Mon Sep 17 00:00:00 2001 From: Tai Groot Date: Mon, 10 Oct 2022 01:28:39 -0700 Subject: [PATCH] Adding updated hashing --- hash.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/hash.go b/hash.go index 960f4ea..4f141ae 100644 --- a/hash.go +++ b/hash.go @@ -3,6 +3,7 @@ package colorhash import ( "encoding/binary" "hash/fnv" + "image/color" "io" ) @@ -36,3 +37,19 @@ func HashBytes(r io.Reader) int { } return sint } + +func BytesToColor(p ColorSet, r io.Reader) color.Color { + i := HashBytes(r) % p.Len() + return p.Get(i) +} + +func StringToColor(p ColorSet, s string) color.Color { + i := HashString(s) % p.Len() + return p.Get(i) +} + +func (sp StringerPalette) GetString(s string) string { + h := HashString(s) + h = h % len(sp) + return sp[h](s) +}