-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcolor.go
64 lines (54 loc) · 1010 Bytes
/
color.go
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package tcod
//go:generate scripts/makecolors -v OFILE=color_const.go resources/colors
// #include <libtcod.h>
import "C"
// Color represents a colour
type Color struct {
R, G, B byte
}
func (c *Color) getNative() C.TCOD_color_t {
return C.TCOD_color_RGB(C.uint8_t(c.R),
C.uint8_t(c.G), C.uint8_t(c.B))
}
// Add sums the RGB values of c and o, capping each
// one at 255
func (c Color) Add(o Color) Color {
r := uint16(c.R) + uint16(o.R)
g := uint16(c.G) + uint16(o.G)
b := uint16(c.B) + uint16(o.B)
if r > 255 {
r = 255
}
if g > 255 {
g = 255
}
if b > 255 {
b = 255
}
return Color{
R: byte(r),
G: byte(g),
B: byte(b),
}
}
// Sub subtracts the RGB values of o from c, with a
// minimum of 0 for each one
func (c Color) Sub(o Color) Color {
r := uint16(c.R) - uint16(o.R)
g := uint16(c.G) - uint16(o.G)
b := uint16(c.B) - uint16(o.B)
if r > 255 {
r = 0
}
if g > 255 {
g = 0
}
if b > 255 {
b = 0
}
return Color{
R: byte(r),
G: byte(g),
B: byte(b),
}
}