feat: Implemented visualizer

This commit is contained in:
Karma Riuk
2023-08-17 13:37:54 +02:00
parent 399bb9f137
commit 5124a4b98b
10 changed files with 846 additions and 35 deletions

View File

@ -28,6 +28,18 @@ func (w *ImageWriter) Write() error {
return errors.New("Filename of ImageWriter doesn't have .png extension. The only suppported image type is png")
}
w.GenerateImage()
f, err := os.Create(w.Filename)
if err != nil {
return err
}
png.Encode(f, w.img)
f.Close()
return nil
}
func (w *ImageWriter) GenerateImage() *image.RGBA {
w.img = image.NewRGBA(image.Rect(0, 0, w.Maze.Width*w.CellWidth, w.Maze.Height*w.CellHeight))
// Fill the image with walls
@ -50,6 +62,9 @@ func (w *ImageWriter) Write() error {
w.draw(x0, y0, width, height, w.PathColor)
}
}
if len(w.Maze.Solution) == 0 {
return w.img
}
// Fill in the solution
total_len := w.getSolutionLength()
@ -99,14 +114,7 @@ func (w *ImageWriter) Write() error {
w.draw(x0, y0, width, height, colors[c])
}
}
f, err := os.Create(w.Filename)
if err != nil {
return err
}
png.Encode(f, w.img)
f.Close()
return nil
return w.img
}
func (w *ImageWriter) getSolutionLength() int {