Pinball dot-matrix clock animation thingy
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

61 lines
1.3 KiB

package matrix
import (
"fmt"
"image/color"
"strings"
"golang.org/x/image/colornames"
)
func init() {
colornames.Map["amber"] = color.RGBA{R: 0xff, G: 0x7f, A: 0xff}
}
func adjustBrightness(c color.RGBA, f uint32) color.RGBA {
if f >= 0x0100 {
return c
}
return color.RGBA{
R: uint8((uint32(c.R) * f) >> 8),
G: uint8((uint32(c.G) * f) >> 8),
B: uint8((uint32(c.B) * f) >> 8),
A: c.A,
}
}
func parseColor(s string) (color.RGBA, error) {
if len(s) == 0 {
return colornames.White, nil
}
s = strings.Replace(s, " ", "", -1)
switch {
case s[0] == '#':
switch len(s) {
case 4:
var c = color.RGBA{A: 0xff}
_, err := fmt.Sscanf(s, "#%1x%1x%1x", &c.R, &c.G, &c.B)
c.R *= 0x11
c.G *= 0x11
c.B *= 0x11
return c, err
case 7:
var c = color.RGBA{A: 0xff}
_, err := fmt.Sscanf(s, "#%02x%02x%02x", &c.R, &c.G, &c.B)
return c, err
}
case strings.HasPrefix(s, "rgb("):
var c = color.RGBA{A: 0xff}
_, err := fmt.Sscanf(s, "rgb(%d,%d,%d)", &c.R, &c.G, &c.B)
return c, err
case strings.HasPrefix(s, "rgba("):
var c color.RGBA
_, err := fmt.Sscanf(s, "rgba(%d,%d,%d,%d)", &c.R, &c.G, &c.B, &c.A)
return c, err
default:
if c, ok := colornames.Map[strings.ToLower(s)]; ok {
return c, nil
}
}
return colornames.White, fmt.Errorf("matrix: unknown color %q", s)
}