Beispiel #1
0
// HSB2RGB convert HSB (HSV) color to RGB
func HSB2RGB(h, s, b int) (int, int, int) {
	var r, g, bb float64

	if h+s+b == 0 {
		return 0, 0, 0
	}

	ts := float64(s) / 100.0
	tb := float64(b) / 100.0

	f := float64(h)/60.0 - math.Floor(float64(h)/60.0)
	p := (tb * (1 - ts))
	q := (tb * (1 - f*ts))
	t := (tb * (1 - (1-f)*ts))

	switch (h / 60) % 6 {
	case 0:
		r, g, bb = tb, t, p
	case 1:
		r, g, bb = q, tb, p
	case 2:
		r, g, bb = p, tb, t
	case 3:
		r, g, bb = p, q, tb
	case 4:
		r, g, bb = t, p, tb
	case 5:
		r, g, bb = tb, p, q
	}

	return int(mathutil.Round(r*0xFF, 0)),
		int(mathutil.Round(g*0xFF, 0)),
		int(mathutil.Round(bb*0xFF, 0))
}
Beispiel #2
0
// Float floating number pretty formating
func Float(f float64) float64 {
	if f < 10.0 {
		return mathutil.Round(f, 2)
	}

	return mathutil.Round(f, 1)
}