Properly apply modulus to input ints

This commit is contained in:
2022-10-03 01:05:51 -07:00
parent 1a5f9fe512
commit 2d452d8c20

View File

@@ -8,6 +8,8 @@ import (
"strings" "strings"
) )
const TotalHexColorspace = 0xffffff
type ( type (
SimpleColor int SimpleColor int
NamedPalette map[string]SimpleColor NamedPalette map[string]SimpleColor
@@ -93,13 +95,13 @@ func (p SimplePalette) ToAnsi16() (sp SimplePalette) {
} }
func New(color int) SimpleColor { func New(color int) SimpleColor {
return SimpleColor(color) return SimpleColor(color % TotalHexColorspace)
} }
func FromRGBA(r, g, b, _ uint32) SimpleColor { func FromRGBA(r, g, b, _ uint32) SimpleColor {
c := r c := r % TotalHexColorspace
c = c<<8 + g c = c<<8 + (g % TotalHexColorspace)
c = c<<8 + b c = c<<8 + (b % TotalHexColorspace)
return SimpleColor(c) return SimpleColor(c)
} }