1
0
Fork 0

add -pxsize parameter to zoom in, try values 1,2,3,...

This commit is contained in:
erinn 2019-08-09 19:47:26 -07:00
parent c0a11bc2da
commit b5e225ccc5
2 changed files with 14 additions and 8 deletions

View File

@ -12,17 +12,18 @@ import (
type Graphics struct { type Graphics struct {
window *sdl.Window window *sdl.Window
renderer *sdl.Renderer renderer *sdl.Renderer
width, height int32 width, height, pxsize int32
t int t int
colorMap map[string][4]uint8 colorMap map[string][4]uint8
} }
func NewGraphics(width, height int32) *Graphics { func NewGraphics(width, height, pxsize int32) *Graphics {
graphics := new(Graphics) graphics := new(Graphics)
graphics.width = width graphics.width = width
graphics.height = height graphics.height = height
graphics.pxsize = pxsize
window, err := sdl.CreateWindow("Microworlds", sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED, 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 { if err != nil {
panic(err) panic(err)
} }
@ -41,13 +42,17 @@ func NewGraphics(width, height int32) *Graphics {
return 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) { func (g *Graphics) ColorPheromone(name string, color [4]uint8) {
g.colorMap[name] = color g.colorMap[name] = color
} }
func (g *Graphics) Render(env *core.Environment, turtles []*core.Turtle) { func (g *Graphics) Render(env *core.Environment, turtles []*core.Turtle) {
g.renderer.SetDrawColor(0x00, 0x00, 0x00, 0x00) 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 x := 0; x < int(g.width); x++ {
for y := 0; y < int(g.height); y++ { 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 // TODO explictly define this scale
scaledamount := uint8(float64(color[0]) * (amount/2)) scaledamount := uint8(float64(color[0]) * (amount/2))
g.renderer.SetDrawColor(scaledamount,0,scaledamount, uint8(0xF0)) 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) { if env.HasValue(x, y) {
g.renderer.SetDrawColor(255, 255, 255, uint8(255)) 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) g.renderer.SetDrawColor(0xF3, 0x81, 0, 0x00)
for _, t := range turtles { for _, t := range turtles {
x, y := t.Pos() x, y := t.Pos()
g.renderer.DrawPoint(int32(x), int32(y)) g.DrawTileColor(int32(x), int32(y))
t.Run(env) t.Run(env)
} }

View File

@ -20,6 +20,7 @@ var model = flag.String("model", "slime", "slimemold|swarm|woodchips")
var width = flag.Int("width", 300, "width of environment") var width = flag.Int("width", 300, "width of environment")
var height = flag.Int("height", 300, "height 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") var numTurtles = flag.Int("numTurtles", 5000, "number of turtles")
func main() { func main() {
@ -44,7 +45,7 @@ func main() {
env := core.NewEnvironment(*width, *height) env := core.NewEnvironment(*width, *height)
turtles := make([]*core.Turtle, *numTurtles) turtles := make([]*core.Turtle, *numTurtles)
g := graphics.NewGraphics(int32(*width), int32(*height)) g := graphics.NewGraphics(int32(*width), int32(*height), int32(*pxsize))
switch *model { switch *model {