blob: eefebb8c214ca6acd3ed5c51aa56229f605e15d4 (
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
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
module gx
pub const (
blue = Color{
r: 0
g: 0
b: 255
}
red = Color{
r: 255
g: 0
b: 0
}
green = Color{
r: 0
g: 255
b: 0
}
yellow = Color{
r: 255
g: 255
b: 0
}
orange = Color{
r: 255
g: 165
b: 0
}
purple = Color{
r: 128
g: 0
b: 128
}
black = Color{
r: 0
g: 0
b: 0
}
gray = Color{
r: 128
g: 128
b: 128
}
indigo = Color{
r: 75
g: 0
b: 130
}
pink = Color{
r: 255
g: 192
b: 203
}
violet = Color{
r: 238
g: 130
b: 238
}
white = Color{
r: 255
g: 255
b: 255
}
dark_blue = Color{
r: 0
g: 0
b: 139
}
dark_gray = Color{
r: 169
g: 169
b: 169
}
dark_green = Color{
r: 0
g: 100
b: 0
}
dark_red = Color{
r: 139
g: 0
b: 0
}
light_blue = Color{
r: 173
g: 216
b: 230
}
light_gray = Color{
r: 211
g: 211
b: 211
}
light_green = Color{
r: 144
g: 238
b: 144
}
light_red = Color{
r: 255
g: 204
b: 203
}
)
// Color represents a 32 bit color value in sRGB format
pub struct Color {
pub mut:
r byte
g byte
b byte
a byte = 255
}
// hex takes in a 32 bit integer and splits it into 4 byte values
pub fn hex(color int) Color {
return Color{
r: byte((color >> 24) & 0xFF)
g: byte((color >> 16) & 0xFF)
b: byte((color >> 8) & 0xFF)
a: byte(color & 0xFF)
}
}
pub fn rgb(r byte, g byte, b byte) Color {
return Color{
r: r
g: g
b: b
}
}
pub fn rgba(r byte, g byte, b byte, a byte) Color {
return Color{
r: r
g: g
b: b
a: a
}
}
pub fn (c Color) + (c2 Color) Color {
return Color{
r: c.r + c2.r
g: c.g + c2.g
b: c.b + c2.b
a: c.b + c2.a
}
}
pub fn (c Color) - (c2 Color) Color {
return Color{
r: c.r - c2.r
g: c.g - c2.g
b: c.b - c2.b
a: c.b - c2.a
}
}
pub fn (c Color) * (c2 Color) Color {
return Color{
r: c.r * c2.r
g: c.g * c2.g
b: c.b * c2.b
a: c.b * c2.a
}
}
pub fn (c Color) / (c2 Color) Color {
return Color{
r: c.r / c2.r
g: c.g / c2.g
b: c.b / c2.b
a: c.b / c2.a
}
}
pub fn (c Color) eq(c2 Color) bool {
return c.r == c2.r && c.g == c2.g && c.b == c2.b && c.a == c2.a
}
pub fn (c Color) str() string {
return 'Color{$c.r, $c.g, $c.b, $c.a}'
}
// rgba8 - convert a color value to an int in the RGBA8 order.
// see https://developer.apple.com/documentation/coreimage/ciformat
[inline]
pub fn (c Color) rgba8() int {
return (int(c.r) << 24) + (int(c.g) << 16) + (int(c.b) << 8) + int(c.a)
}
// bgra8 - convert a color value to an int in the BGRA8 order.
// see https://developer.apple.com/documentation/coreimage/ciformat
[inline]
pub fn (c Color) bgra8() int {
return (int(c.b) << 24) + (int(c.g) << 16) + (int(c.r) << 8) + int(c.a)
}
// abgr8 - convert a color value to an int in the ABGR8 order.
// see https://developer.apple.com/documentation/coreimage/ciformat
[inline]
pub fn (c Color) abgr8() int {
return (int(c.a) << 24) + (int(c.b) << 16) + (int(c.g) << 8) + int(c.r)
}
const (
string_colors = map{
'blue': blue
'red': red
'green': green
'yellow': yellow
'orange': orange
'purple': purple
'black': black
'gray': gray
'indigo': indigo
'pink': pink
'violet': violet
'white': white
'dark_blue': dark_blue
'dark_gray': dark_gray
'dark_green': dark_green
'dark_red': dark_red
'light_blue': light_blue
'light_gray': light_gray
'light_green': light_green
'light_red': light_red
}
)
pub fn color_from_string(s string) Color {
return gx.string_colors[s]
}
|