mirror of
https://github.com/taigrr/colorhash.git
synced 2026-04-02 03:08:48 -07:00
Adding updated hashing
This commit is contained in:
17
hash.go
17
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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user