2018-08-11 00:19:47 +00:00
|
|
|
package level
|
2018-07-24 03:10:53 +00:00
|
|
|
|
|
|
|
import (
|
2018-08-11 00:19:47 +00:00
|
|
|
"git.kirsle.net/apps/doodle/render"
|
2018-07-24 03:10:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Grid is a 2D grid of pixels in X,Y notation.
|
2018-08-11 00:19:47 +00:00
|
|
|
type Grid map[*Pixel]interface{}
|
2018-07-24 03:10:53 +00:00
|
|
|
|
|
|
|
// Exists returns true if the point exists on the grid.
|
2018-08-11 00:19:47 +00:00
|
|
|
func (g *Grid) Exists(p *Pixel) bool {
|
2018-07-24 03:10:53 +00:00
|
|
|
if _, ok := (*g)[p]; ok {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw the grid efficiently.
|
2018-08-11 00:19:47 +00:00
|
|
|
func (g *Grid) Draw(e render.Engine) {
|
2018-07-24 03:10:53 +00:00
|
|
|
for pixel := range *g {
|
2018-08-11 00:19:47 +00:00
|
|
|
color := pixel.Swatch.Color
|
|
|
|
e.DrawPoint(color, render.Point{
|
2018-07-25 00:44:32 +00:00
|
|
|
X: pixel.X,
|
|
|
|
Y: pixel.Y,
|
|
|
|
})
|
2018-07-24 03:10:53 +00:00
|
|
|
}
|
|
|
|
}
|