You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

29 lines
747 B

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