From 2d452d8c20440e5f504601361764dd88f6ef920f Mon Sep 17 00:00:00 2001 From: Tai Groot Date: Mon, 3 Oct 2022 01:05:51 -0700 Subject: [PATCH] Properly apply modulus to input ints --- simplecolor/simplecolors.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/simplecolor/simplecolors.go b/simplecolor/simplecolors.go index 77e51f2..dcbbb91 100644 --- a/simplecolor/simplecolors.go +++ b/simplecolor/simplecolors.go @@ -8,6 +8,8 @@ import ( "strings" ) +const TotalHexColorspace = 0xffffff + type ( SimpleColor int NamedPalette map[string]SimpleColor @@ -93,13 +95,13 @@ func (p SimplePalette) ToAnsi16() (sp SimplePalette) { } func New(color int) SimpleColor { - return SimpleColor(color) + return SimpleColor(color % TotalHexColorspace) } func FromRGBA(r, g, b, _ uint32) SimpleColor { - c := r - c = c<<8 + g - c = c<<8 + b + c := r % TotalHexColorspace + c = c<<8 + (g % TotalHexColorspace) + c = c<<8 + (b % TotalHexColorspace) return SimpleColor(c) }