package color import "github.com/lucasb-eyer/go-colorful" type RGB struct { Red float64 `json:"red"` Green float64 `json:"green"` Blue float64 `json:"blue"` } func (rgb RGB) AtIntensity(intensity float64) RGB { hue, sat, _ := colorful.Color{R: rgb.Red, G: rgb.Green, B: rgb.Blue}.Hsv() hsv2 := colorful.Hsv(hue, sat, intensity) return RGB{Red: hsv2.R, Green: hsv2.G, Blue: hsv2.B} } func (rgb RGB) ToHS() HueSat { hue, sat, _ := colorful.Color{R: rgb.Red, G: rgb.Green, B: rgb.Blue}.Hsv() return HueSat{Hue: hue, Sat: sat} } func (rgb RGB) ToXY() XY { x, y, z := (colorful.Color{R: rgb.Red, G: rgb.Green, B: rgb.Blue}).Xyz() return XY{ X: x / (x + y + z), Y: y / (x + y + z), } }