56 lines
1.0 KiB
Go
56 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"image"
|
|
"image/color"
|
|
"image/png"
|
|
"os"
|
|
"test-maze/mazer"
|
|
)
|
|
|
|
const SIZE_X = 48
|
|
const SIZE_Y = 48
|
|
const CELL_SCALE = 10
|
|
|
|
func main() {
|
|
matrix := mazer.GenerateMaze(SIZE_X, SIZE_Y)
|
|
|
|
img := image.NewRGBA(image.Rect(0, 0, SIZE_X*CELL_SCALE, SIZE_Y*CELL_SCALE))
|
|
|
|
white := color.RGBA{R: 255, G: 255, B: 255, A: 255}
|
|
black := color.RGBA{R: 0, G: 0, B: 0, A: 255}
|
|
|
|
for cellY := 0; cellY < SIZE_Y; cellY++ {
|
|
startY := cellY * CELL_SCALE
|
|
for cellX := 0; cellX < SIZE_X; cellX++ {
|
|
startX := cellX * CELL_SCALE
|
|
|
|
p := black
|
|
if matrix[cellY][cellX] == 1 {
|
|
p = white
|
|
}
|
|
|
|
for dy := 0; dy < CELL_SCALE; dy++ {
|
|
row := img.Pix[(startY+dy)*img.Stride:]
|
|
for dx := 0; dx < CELL_SCALE; dx++ {
|
|
offset := (startX + dx) * 4
|
|
row[offset+0] = p.R
|
|
row[offset+1] = p.G
|
|
row[offset+2] = p.B
|
|
row[offset+3] = p.A
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
f, err := os.Create("maze.png")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
defer f.Close()
|
|
|
|
if err := png.Encode(f, img); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|