diff --git a/internal/outputmaze/outputmaze.go b/internal/outputmaze/outputmaze.go index 4c64cef..53ac304 100644 --- a/internal/outputmaze/outputmaze.go +++ b/internal/outputmaze/outputmaze.go @@ -5,6 +5,7 @@ import ( "image" "image/color" "image/png" + "math" getMaze "mazesolver/internal/getmaze" "os" ) @@ -20,8 +21,10 @@ func EditMaze(points []getMaze.Point, oldPath, newPath string) (string, error) { return "", err } - for _, v := range points { - updateColor(image, v, color.RGBA{0, 255, 0, 255}) + for n, v := range points { + var h float64 = (float64(1) - (((float64(n)) / (float64(len(points)))))) / float64(1.1) + r, g, b := hueToRGB(h) + updateColor(image, v, color.RGBA{uint8(r * 255), uint8(g * 255), uint8(b * 255), 255}) } f, err := os.Create(newPath) @@ -48,3 +51,19 @@ func updateColor(image image.Image, p getMaze.Point, color color.Color) error { } return nil } + +func hueToRGB(h float64) (float64, float64, float64) { + kr := math.Mod(5+h*6, 6) + kg := math.Mod(3+h*6, 6) + kb := math.Mod(1+h*6, 6) + + r := 1 - math.Max(min3(kr, 4-kr, 1), 0) + g := 1 - math.Max(min3(kg, 4-kg, 1), 0) + b := 1 - math.Max(min3(kb, 4-kb, 1), 0) + + return r, g, b +} + +func min3(a, b, c float64) float64 { + return math.Min(math.Min(a, b), c) +}