forked from steambap/captcha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hsva.go
43 lines (38 loc) · 755 Bytes
/
hsva.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
package captcha
import "math"
type hsva struct {
h, s, v float64
a uint8
}
// https://gist.github.com/mjackson/5311256
func (c hsva) RGBA() (r, g, b, a uint32) {
var i = math.Floor(c.h * 6)
var f = c.h*6 - i
var p = c.v * (1.0 - c.s)
var q = c.v * (1.0 - f*c.s)
var t = c.v * (1 - (1-f)*c.s)
var red, green, blue float64
switch int(i) % 6 {
case 0:
red, green, blue = c.v, t, p
case 1:
red, green, blue = q, c.v, p
case 2:
red, green, blue = p, c.v, t
case 3:
red, green, blue = p, q, c.v
case 4:
red, green, blue = t, p, c.v
case 5:
red, green, blue = c.v, p, q
}
r = uint32(red * 255)
r |= r << 8
g = uint32(green * 255)
g |= g << 8
b = uint32(blue * 255)
b |= b << 8
a = uint32(c.a)
a |= a << 8
return
}