From 891963a516eab2337584b5b906092f487a002cee Mon Sep 17 00:00:00 2001
From: semblanceofsense <semblanceofsensegaming@gmail.com>
Date: Fri, 31 Jan 2025 21:40:21 -0700
Subject: [PATCH] gradient

---
 internal/outputmaze/outputmaze.go | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

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)
+}