-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolors.spin2
68 lines (60 loc) · 1.83 KB
/
colors.spin2
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
CON
' BGR 5+6+5 16bits/pixel (RGB reversed)
black = $0000
white = $FFFF
blue = $F800
green = $07E0
red = $001F
yellow = red+green
orange = %00000_100000_11111
purple = red+blue
cyan = green+blue
dark_turquoise = $A421
grey = $7BEF
lightgrey = %10000_100000_10000
darkgrey = %01000_010000_01000
PUB null()
PUB color_to_rgb(c):r,g,b
'Returns the red, green and blue
'components of a BGR 565 16bit color
r := (%11111) & c
g := ((%111111 << 5) & c) >> 5
b := ((%11111 << 11) & c) >> 11
PUB set_color(r,g,b):c
'Returns a BGR 565 16 bit color
'from 0-255 color components
b := 0 #> b/8 <# $1F
g := 0 #> g/4 <# $3F
r := 0 #> r/8 <# $1F
c := b<<11|g<<5|r
PUB lighten(c,f):light|r,g,b
'Lightens the color c by a factor f
f := f <# 31
r,g,b := color_to_rgb(c)
r := 0 #> (r+f) <# $1F
g := 0 #> (g+ (2*f)) <# $3F
b := 0 #> (b+f) <# $1F
light := (b<<11) | (g<<5) | r
PUB darken(c,f):dark_color|r,g,b
'Darkens the color c by a factor f
f := f <# 31
r,g,b := color_to_rgb(c)
r := 0 #> (r - f) <# $1F
g := 0 #> (g - (2*f)) <# $3F '$3F
b := 0 #> (b - f) <# $1F
dark_color := (b<<11) | (g<<5) | r
PUB transition(c, r, g, b):result | bc, gc, rc
bc := (0 #> (($1F<<11&c)>>11+b) <# $1F)
gc := (0 #> (($3F<<5&c)>>5+g) <# $3F)
rc := (0 #> (($1F&c)+r) <# $1F)
result := bc<<11 | gc<<5 | rc
PUB mix_color(c,r,g,b):result
'Mixes color c with rgb components
b := 0 #> b <# $1F
g := 0 #> g <# $3F
r := 0 #> r <# $1F
result := (c & $1F<<11)+(b<<11)| (c & $3F<<5)+(g<<5)| (c & $1F) + r
PUB invert_color(c):i|r,g,b
'Returns the inverted color of c
r,g,b := color_to_rgb(c)
i := ($1F - b)<<11 | ($3F - g)<<5 | ($1F - r)