blob: 0cc48da1a75d5fed07e335228b38355e46376f6e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
package colors
import (
"fmt"
"math"
)
type RGB struct {
R int // 0-255
G int // 0-255
B int // 0-255
}
func (c RGB) String() string {
return fmt.Sprintf("rgb(%d, %d, %d)", c.R, c.G, c.B)
}
func (c RGB) ToPrecise() PreciseColor {
return PreciseColor{
R: float64(c.R) / 255,
G: float64(c.G) / 255,
B: float64(c.B) / 255,
}
}
func (c RGB) FromPrecise(p PreciseColor) ColorSpace {
return RGB{
R: int(math.Round(p.R * 255)),
G: int(math.Round(p.G * 255)),
B: int(math.Round(p.B * 255)),
}
}
|