main.go: broken WIP for HSV

This commit is contained in:
Codeberg 2019-05-28 12:08:38 +02:00 committed by Holger Waechtler
parent 5ac5f5101f
commit 6e230cfb44

17
main.go
View File

@ -84,7 +84,8 @@ type HSV struct {
v float32 v float32
} }
func rgb(r, g, b float32) *RGB { func f2rgb(r, g, b float32) *RGB {
// make RGB from 3 floats
c := new(RGB) c := new(RGB)
c.r = uint8(r * 1.0 / 255) c.r = uint8(r * 1.0 / 255)
c.g = uint8(g * 1.0 / 255) c.g = uint8(g * 1.0 / 255)
@ -92,7 +93,7 @@ func rgb(r, g, b float32) *RGB {
return c return c
} }
func s2rgb(s string) *RGB { func rgb(s string) *RGB {
c := new(RGB) c := new(RGB)
fmt.Sscanf(s, "#%02x%02x%02x", c.r, c.g, c.b) fmt.Sscanf(s, "#%02x%02x%02x", c.r, c.g, c.b)
return c return c
@ -106,12 +107,12 @@ func (c *HSV) to_rgb() *RGB {
t := c.v * (1 - c.s * (1 - f)) t := c.v * (1 - c.s * (1 - f))
switch (h) { switch (h) {
case 6: case 6:
case 0: return rgb(C.V, t, p) case 0: return f2rgb(C.V, t, p)
case 1: return rgb(q, C.V, p) case 1: return f2rgb(q, C.V, p)
case 2: return rgb(p, C.V, t) case 2: return f2rgb(p, C.V, t)
case 3: return rgb(p, q, C.V) case 3: return f2rgb(p, q, C.V)
case 4: return rgb(t, p, C.V) case 4: return f2rgb(t, p, C.V)
case 5: return rgb(C.V, p, q) case 5: return f2rgb(C.V, p, q)
} }
} }