Also cribbed from: https://github.com/lucasb-eyer/go-colorful/blob/master/colors.go
()
| 672 | |
| 673 | // Also cribbed from: https://github.com/lucasb-eyer/go-colorful/blob/master/colors.go |
| 674 | func (color Color) HSV() (float64, float64, float64) { |
| 675 | |
| 676 | r := float64(color[0]) / 255 |
| 677 | g := float64(color[1]) / 255 |
| 678 | b := float64(color[2]) / 255 |
| 679 | |
| 680 | min := math.Min(math.Min(r, g), b) |
| 681 | v := math.Max(math.Max(r, g), b) |
| 682 | C := v - min |
| 683 | |
| 684 | s := 0.0 |
| 685 | if v != 0.0 { |
| 686 | s = C / v |
| 687 | } |
| 688 | |
| 689 | h := 0.0 // We use 0 instead of undefined as in wp. |
| 690 | if min != v { |
| 691 | if v == r { |
| 692 | h = math.Mod((g-b)/C, 6.0) |
| 693 | } |
| 694 | if v == g { |
| 695 | h = (b-r)/C + 2.0 |
| 696 | } |
| 697 | if v == b { |
| 698 | h = (r-g)/C + 4.0 |
| 699 | } |
| 700 | h /= 6 |
| 701 | if h < 0.0 { |
| 702 | h++ |
| 703 | } |
| 704 | } |
| 705 | return h, s, v |
| 706 | } |
| 707 | |
| 708 | func ColorFromHexString(hex string) Color { |
| 709 |