psize
This commit is contained in:
parent
891963a516
commit
b7655cf15d
@ -3,6 +3,7 @@ package getMaze
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"image"
|
||||||
"image/color"
|
"image/color"
|
||||||
"image/png"
|
"image/png"
|
||||||
"io"
|
"io"
|
||||||
@ -59,9 +60,10 @@ func GetMaze(imagepath string) (Maze, error) {
|
|||||||
return *new(Maze), err
|
return *new(Maze), err
|
||||||
}
|
}
|
||||||
|
|
||||||
for y := image.Bounds().Min.Y; y < image.Bounds().Max.Y; y += 10 {
|
psize := DeterminePixelSize(image)
|
||||||
|
for y := image.Bounds().Min.Y; y < image.Bounds().Max.Y; y += psize {
|
||||||
newRow := make([]Point, 0)
|
newRow := make([]Point, 0)
|
||||||
for x := image.Bounds().Min.X; x < image.Bounds().Max.X; x+= 10 {
|
for x := image.Bounds().Min.X; x < image.Bounds().Max.X; x+= psize {
|
||||||
typ := 0
|
typ := 0
|
||||||
switch image.At(x, y) {
|
switch image.At(x, y) {
|
||||||
case color.RGBA{ R: 255, G: 0, B: 0, A: 255 }:
|
case color.RGBA{ R: 255, G: 0, B: 0, A: 255 }:
|
||||||
@ -77,8 +79,8 @@ func GetMaze(imagepath string) (Maze, error) {
|
|||||||
return *new(Maze), errors.New("bad color")
|
return *new(Maze), errors.New("bad color")
|
||||||
}
|
}
|
||||||
newPoint := Point{
|
newPoint := Point{
|
||||||
X: x / 10,
|
X: x / psize,
|
||||||
Y: y / 10,
|
Y: y / psize,
|
||||||
Value: typ,
|
Value: typ,
|
||||||
}
|
}
|
||||||
newRow = append(newRow, newPoint)
|
newRow = append(newRow, newPoint)
|
||||||
@ -100,3 +102,12 @@ func PrintMaze(maze Maze) {
|
|||||||
fmt.Println("]")
|
fmt.Println("]")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DeterminePixelSize(image image.Image) int {
|
||||||
|
var x, y int
|
||||||
|
color := image.At(x, y)
|
||||||
|
for (color == image.At(x, y)) {
|
||||||
|
x++
|
||||||
|
}
|
||||||
|
return x
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user