diff --git a/main.go b/main.go index 0a00c93..9717f32 100644 --- a/main.go +++ b/main.go @@ -284,45 +284,49 @@ func getUV(img image.Image) (vals []float64) { return } +func between[T cmp.Ordered](v, min, max T) bool { + return v >= min && v <= max +} + func getColor(v float64) string { - if v < 1.0 { + switch { + case between(v, 0, 1): return "006300" - } else if v >= 1.0 && v <= 2.0 { + case between(v, 1, 2): return "00a014" - } else if v >= 2.0 && v <= 3.0 { + case between(v, 2, 3): return "81c600" - } else if v >= 3.0 && v <= 4.0 { + case between(v, 3, 4): return "fff800" - } else if v >= 4.0 && v <= 5.0 { + case between(v, 4, 5): return "ffd100" - } else if v >= 5.0 && v <= 6.0 { + case between(v, 5, 6): return "ffa600" - } else if v >= 6.0 && v <= 7.0 { + case between(v, 6, 7): return "ff7200" - } else if v >= 7.0 && v <= 8.0 { + case between(v, 7, 8): return "ff4a00" - } else if v >= 8.0 && v <= 9.0 { + case between(v, 8, 9): return "ff0000" - } else if v >= 9.0 && v <= 10.0 { + case between(v, 9, 10): return "ff0078" - } else if v >= 10.0 { + case v >= 10: return "a80080" } return "000000" } +func colorIs(c color.RGBA, v uint8) bool { + return c.R == v && c.G == v && c.B == v +} + func isWhite(col color.Color) bool { col = color.RGBAModel.Convert(col) c, ok := col.(color.RGBA) if !ok { return false } - if c.R == 255 && - c.G == 255 && - c.B == 255 { - return true - } - return false + return colorIs(c, 255) } func isBlack(col color.Color) bool { @@ -331,12 +335,7 @@ func isBlack(col color.Color) bool { if !ok { return false } - if c.R == 0 && - c.G == 0 && - c.B == 0 { - return true - } - return false + return colorIs(c, 0) } func isStop(col color.Color) bool { @@ -345,14 +344,7 @@ func isStop(col color.Color) bool { if !ok { return false } - if c.R == 241 && - c.G == 241 && - c.B == 241 { - return true - } - if c.R == 88 && - c.G == 88 && - c.B == 88 { + if colorIs(c, 241) || colorIs(c, 88) { return true } return false @@ -364,19 +356,7 @@ func isStart(col color.Color) bool { if !ok { return false } - if c.R == 241 && - c.G == 241 && - c.B == 241 { - return true - } - if c.R == 214 && - c.G == 214 && - c.B == 214 { - return true - } - if c.R == 0 && - c.G == 0 && - c.B == 0 { + if colorIs(c, 241) || colorIs(c, 214) || colorIs(c, 0) { return true } return false @@ -389,6 +369,7 @@ func fatal(err error) { } } +// DefaultCity is Muenchen const DefaultCity = "24" var locations = map[string]string{