From b5e225ccc5317fa1d486b8ae09b21d21b71826c8 Mon Sep 17 00:00:00 2001 From: erinn Date: Fri, 9 Aug 2019 19:47:26 -0700 Subject: [PATCH] add -pxsize parameter to zoom in, try values 1,2,3,... --- graphics/graphics.go | 19 ++++++++++++------- main.go | 3 ++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/graphics/graphics.go b/graphics/graphics.go index 22c40aa..5a5e2c8 100644 --- a/graphics/graphics.go +++ b/graphics/graphics.go @@ -12,17 +12,18 @@ import ( type Graphics struct { window *sdl.Window renderer *sdl.Renderer - width, height int32 + width, height, pxsize int32 t int colorMap map[string][4]uint8 } -func NewGraphics(width, height int32) *Graphics { +func NewGraphics(width, height, pxsize int32) *Graphics { graphics := new(Graphics) graphics.width = width graphics.height = height + graphics.pxsize = pxsize window, err := sdl.CreateWindow("Microworlds", sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED, - width, height, sdl.WINDOW_SHOWN) + width * pxsize, height * pxsize, sdl.WINDOW_SHOWN) if err != nil { panic(err) } @@ -41,13 +42,17 @@ func NewGraphics(width, height int32) *Graphics { return graphics } +func (g *Graphics) DrawTileColor(x, y int32) { + g.renderer.FillRect(&sdl.Rect{X: x * g.pxsize, Y: y * g.pxsize, W: g.pxsize, H: g.pxsize}) +} + func (g *Graphics) ColorPheromone(name string, color [4]uint8) { g.colorMap[name] = color } func (g *Graphics) Render(env *core.Environment, turtles []*core.Turtle) { g.renderer.SetDrawColor(0x00, 0x00, 0x00, 0x00) - g.renderer.FillRect(&sdl.Rect{X: 0, Y: 0, W: 600, H: 600}) + g.renderer.FillRect(&sdl.Rect{X: 0, Y: 0, W: g.width * g.pxsize, H: g.width * g.pxsize}) for x := 0; x < int(g.width); x++ { for y := 0; y < int(g.height); y++ { @@ -58,13 +63,13 @@ func (g *Graphics) Render(env *core.Environment, turtles []*core.Turtle) { // TODO explictly define this scale scaledamount := uint8(float64(color[0]) * (amount/2)) g.renderer.SetDrawColor(scaledamount,0,scaledamount, uint8(0xF0)) - g.renderer.DrawPoint(int32(x), int32(y)) + g.DrawTileColor(int32(x), int32(y)) } } if env.HasValue(x, y) { g.renderer.SetDrawColor(255, 255, 255, uint8(255)) - g.renderer.DrawPoint(int32(x), int32(y)) + g.DrawTileColor(int32(x), int32(y)) } } } @@ -72,7 +77,7 @@ func (g *Graphics) Render(env *core.Environment, turtles []*core.Turtle) { g.renderer.SetDrawColor(0xF3, 0x81, 0, 0x00) for _, t := range turtles { x, y := t.Pos() - g.renderer.DrawPoint(int32(x), int32(y)) + g.DrawTileColor(int32(x), int32(y)) t.Run(env) } diff --git a/main.go b/main.go index 014c6ce..6ffba56 100644 --- a/main.go +++ b/main.go @@ -20,6 +20,7 @@ var model = flag.String("model", "slime", "slimemold|swarm|woodchips") var width = flag.Int("width", 300, "width of environment") var height = flag.Int("height", 300, "height of environment") +var pxsize = flag.Int("pxsize", 1, "pixels per tile edge") var numTurtles = flag.Int("numTurtles", 5000, "number of turtles") func main() { @@ -44,7 +45,7 @@ func main() { env := core.NewEnvironment(*width, *height) turtles := make([]*core.Turtle, *numTurtles) - g := graphics.NewGraphics(int32(*width), int32(*height)) + g := graphics.NewGraphics(int32(*width), int32(*height), int32(*pxsize)) switch *model {