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
704 B

  1. package color
  2. import "github.com/lucasb-eyer/go-colorful"
  3. type RGB struct {
  4. Red float64 `json:"red"`
  5. Green float64 `json:"green"`
  6. Blue float64 `json:"blue"`
  7. }
  8. func (rgb RGB) AtIntensity(intensity float64) RGB {
  9. hue, sat, _ := colorful.Color{R: rgb.Red, G: rgb.Green, B: rgb.Blue}.Hsv()
  10. hsv2 := colorful.Hsv(hue, sat, intensity)
  11. return RGB{Red: hsv2.R, Green: hsv2.G, Blue: hsv2.B}
  12. }
  13. func (rgb RGB) ToHS() HueSat {
  14. hue, sat, _ := colorful.Color{R: rgb.Red, G: rgb.Green, B: rgb.Blue}.Hsv()
  15. return HueSat{Hue: hue, Sat: sat}
  16. }
  17. func (rgb RGB) ToXY() XY {
  18. x, y, z := (colorful.Color{R: rgb.Red, G: rgb.Green, B: rgb.Blue}).Xyz()
  19. return XY{
  20. X: x / (x + y + z),
  21. Y: y / (x + y + z),
  22. }
  23. }