diff --git a/conway.go b/conway.go index 7cf74b0..777fad5 100644 --- a/conway.go +++ b/conway.go @@ -62,11 +62,9 @@ func initGrid(width, height int, parent ...[][]Cell) ([][]Cell, error) { return cells, nil } -var grid [][]Cell - func setup(callback func([][]Cell), width, height int, FPS time.Duration) chan bool { // Initialize grid - grid, _ = initGrid(width, height) + grid, _ := initGrid(width, height) // Prepare ticker and finishing flag ticker := time.NewTicker((1000 / FPS) * time.Millisecond) @@ -79,7 +77,7 @@ func setup(callback func([][]Cell), width, height int, FPS time.Duration) chan b case <-done: return case <-ticker.C: - draw(callback) + grid = draw(grid, callback) } } }() @@ -88,7 +86,7 @@ func setup(callback func([][]Cell), width, height int, FPS time.Duration) chan b return done } -func draw(callback func([][]Cell)) { +func draw(grid [][]Cell, callback func([][]Cell)) [][]Cell { generation, _ := initGrid(len(grid), len(grid[0]), grid) // Iterate through grid for i := 0; i < len(grid); i++ { @@ -108,6 +106,6 @@ func draw(callback func([][]Cell)) { // curr && cout >= 2 && cout <= 3 || !curr && cout == 3 } } - grid = generation callback(generation) + return generation }