diff --git a/lib/app_component.dart b/lib/app_component.dart index 4169c55..8e726df 100644 --- a/lib/app_component.dart +++ b/lib/app_component.dart @@ -39,22 +39,20 @@ class AppComponent implements OnInit { } void onStepClicked() { - engine.running = false; - engine.update(); + engine.step(); } void onResetClicked() { - engine.running = false; engine.reset(); } void onRandomClicked() { engine.running = false; - engine.grid.addPattern(); + engine.addPattern(); } void onEdgesClicked() { - engine.grid.switchEdgeRendering(); + engine.toggleEdgeRendering(); } void onClearClicked() { diff --git a/lib/src/Engine.dart b/lib/src/Engine.dart index 04b4e95..80f16ed 100644 --- a/lib/src/Engine.dart +++ b/lib/src/Engine.dart @@ -19,20 +19,21 @@ class Engine { num _drawLag = 0.0; final html.CanvasElement canvas; - Grid grid = new Grid(100, 100); - bool running = false; + Grid _grid = new Grid(100, 100); + bool _running = false; Engine(this.canvas) { _elapsed.start(); - grid.addPattern(amount: 15, dispersal: 5); + _grid.addPattern(amount: 15, dispersal: 5); } void reset() { - grid.reset(); + _grid.reset(); + running = false; } void clear() { - grid = new Grid(100, 100); + _grid = new Grid(100, 100); running = false; } @@ -59,11 +60,34 @@ class Engine { void update() { // print("updating"); - if(!grid.update()) running = false; + if (!_grid.update()) running = false; + } + + void step() { + running = false; + _grid.update(); } void render([num interp]) { // print("rendering"); - grid.render(canvas, interp); + _grid.render(canvas, interp); } + + void addPattern( + {CellPattern pattern, int x, int y, int amount, int dispersal, int seed}) { + _grid.addPattern( + pattern: pattern, + x: x, + y: y, + amount: amount, + dispersal: dispersal, + seed: seed); + } + + void toggleEdgeRendering() { + _grid.renderEdges = !_grid.renderEdges; + } + + void set running(bool on) => _running = on; + bool get running => _running; } diff --git a/lib/src/Grid.dart b/lib/src/Grid.dart index f47e5bf..528e170 100644 --- a/lib/src/Grid.dart +++ b/lib/src/Grid.dart @@ -208,8 +208,9 @@ class Grid { _dirty = false; } - void switchEdgeRendering([bool on]) { - _renderEdges = on ?? !_renderEdges; + void set renderEdges(bool on) { + _renderEdges = on; _dirty = true; } + bool get renderEdges => _renderEdges; }