-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
48 lines (39 loc) · 1.04 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"pathfinder/maze"
"pathfinder/astar"
"fmt"
"image/png"
"os"
"log"
"image"
)
func main() {
width, height := 500, 200
img := maze.RenderMaze(maze.GenerateMaze(width, height))
if err := maze.SaveImage("maze.png", img); err != nil {
log.Fatal(err)
}
file, err := os.Open("maze.png")
if err != nil {
log.Fatalf("Error while opening image: %v", err)
}
defer file.Close()
rgbaImg, err := png.Decode(file)
if err != nil {
log.Fatalf("Error while decoding PNG: %v", err)
}
grid, start, end, err := astar.ParseImage(rgbaImg.(*image.RGBA))
if err != nil {
log.Fatal(err)
}
fmt.Println("Initial Grid:")
astar.PrintGrid(grid)
if path := astar.FindPath(grid, start, end); path != nil {
fmt.Println("Path found:")
astar.PrintPath(path)
astar.DrawPathOnImage(rgbaImg.(*image.RGBA), path)
} else {
fmt.Println("No path found.")
}
}