To make threads easier to track, it might be good to alternate slightly lighter and darker bg colours per poster #371
Omnikron13
started this conversation in
Ideas
Replies: 2 comments 3 replies
-
package main
import (
"fmt"
"image/color"
"math/bits"
"github.com/cespare/xxhash"
gc "github.com/lucasb-eyer/go-colorful"
)
func main() {
c := get_hsluv("Omnikron13")
r, g, b, a := c.RGBA()
fmt.Printf("RGB: %#v%0x%0x, A: %0x\n", r>>8, g>>8, b>>8, a>>8)
}
func get_colour(s string) (sat uint64, luv uint64, hue float64) {
const mask5bit = 0b11111
const mask32bit = 0xFFFFFFFF
hash := xxhash.Sum64String(s)
sat = hash & mask5bit
hash = bits.RotateLeft64(hash, -5)
luv = hash & mask5bit
hash = bits.RotateLeft64(hash, -5)
hue = float64(hash&mask32bit) / float64(mask32bit) * 360
return
}
func get_hsluv(s string) (c color.Color) {
sat, luv, hue := get_colour(s)
c = gc.HSLuv(hue, float64(sat+28)/100, float64(luv+28)/100)
return
} |
Beta Was this translation helpful? Give feedback.
2 replies
-
Repo here that I'll probably expand upon somewhat that does just this sort of hash->colour https://github.com/Omnikron13/hash-colour |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Additionally, if usernames were hashed and that hash used to generate a colour within certain bounds, it could make it a lot easier to track threads by recognising the colour of the names you're talking to.
An xxhash is very quick and gives you at least 64 bits to divide up over some subset of a chosen colour space. I believe there are some good packages for HSL, HSV, etc. etc.
Packages like this one support all manner of colour profiles, some of which like HSLuv are very good for generating a range of colours which appear similarly bright/saturated/etc. as you shift around whatever subset of them.
You probably only want about 5 bits for +-16 swing either side of about 60 for saturation and 5 more for luminosity, and then the hash leaves 54 bits for the 360 degree hue, though you'd only really need 24 or 32 or something. One possible hash of my handle could be: taking 24 bits for hue:
Of this taking 32 bits:
The first 42-bits of the xxhash of a given user could give them a predictable coloured username as you're going over threads.
I'd take 5-bits for +-16 around 60 sat, 5-bits for +-16 around 60 luv, and 32 bits as the 0-360 hue, personally.
(I took the bits from the left hand side of the hash, but I suppose it would probably be better to take 5, bitshift, take 5, bitshift and take 32 from the right hand side...)
Beta Was this translation helpful? Give feedback.
All reactions