diff --git a/lib/game/Game.dart b/lib/game/Game.dart index 489a7ea..5c529fb 100644 --- a/lib/game/Game.dart +++ b/lib/game/Game.dart @@ -65,11 +65,11 @@ class Game { // Slightly oscillating colors to highlight rendering updates void _oscillate() { - if(_oscill >= 50.0 || _oscill <= -50.0) { + if (_oscill >= 50.0 || _oscill <= -50.0) { _oscillDir = !_oscillDir; - _oscill = max( min(_oscill, 49.0), -49.0); - } - else _oscillDir == true ? _oscill += _OSCILLSPEED : _oscill -= _OSCILLSPEED; + _oscill = max(min(_oscill, 49.0), -49.0); + } else + _oscillDir == true ? _oscill += _OSCILLSPEED : _oscill -= _OSCILLSPEED; } Color _getOscillatedCol(Color col) { diff --git a/lib/game/LoopExample.dart b/lib/game/LoopExample.dart index cf00224..2e2996f 100644 --- a/lib/game/LoopExample.dart +++ b/lib/game/LoopExample.dart @@ -1,6 +1,6 @@ import 'package:browserloop/game/Game.dart'; -abstract class LoopExample{ +abstract class LoopExample { Game game; void stop() {} @@ -9,4 +9,4 @@ abstract class LoopExample{ abstract class VariableUpdates { double MS_PER_UPDATE = 300.0; -} \ No newline at end of file +} diff --git a/lib/src/00-oldcode.dart b/lib/src/00-oldcode.dart index 0d534af..6af88fc 100644 --- a/lib/src/00-oldcode.dart +++ b/lib/src/00-oldcode.dart @@ -42,10 +42,10 @@ void _demoSetup() { ctx.setFillColorRgb(rng.nextInt(255), rng.nextInt(255), rng.nextInt(255)); }; var _changeGrid = (int delta) { - _clear(); - int newgrid = GRIDNUM + delta; - GRIDNUM = (newgrid == 0) ? GRIDNUM : newgrid; - _start(); + _clear(); + int newgrid = GRIDNUM + delta; + GRIDNUM = (newgrid == 0) ? GRIDNUM : newgrid; + _start(); }; _clear(); @@ -55,10 +55,7 @@ void _demoSetup() { _start(); }); html.querySelector('#basic_stop').onClick.listen((e) => _stop()); - html - .querySelector('#basic_reset') - .onClick - .listen((e) => _clear()); + html.querySelector('#basic_reset').onClick.listen((e) => _clear()); html.querySelector('#basic_plus').onClick.listen((e) => _changeGrid(-5)); html.querySelector('#basic_minus').onClick.listen((e) => _changeGrid(5)); } diff --git a/lib/src/02-AnimationFrameWhile.dart b/lib/src/02-AnimationFrameWhile.dart index 5421325..260589d 100644 --- a/lib/src/02-AnimationFrameWhile.dart +++ b/lib/src/02-AnimationFrameWhile.dart @@ -27,4 +27,4 @@ class WhileLoop implements LoopExample { void start() { window.requestAnimationFrame(eventloop); } -} \ No newline at end of file +} diff --git a/lib/src/03-VariableTimestep.dart b/lib/src/03-VariableTimestep.dart index dd0ef62..2b6849f 100644 --- a/lib/src/03-VariableTimestep.dart +++ b/lib/src/03-VariableTimestep.dart @@ -34,4 +34,4 @@ class VariableTimestep implements LoopExample { elapsed.reset(); window.requestAnimationFrame(eventloop); } -} \ No newline at end of file +} diff --git a/lib/src/04-FixedLoopVariableRender.dart b/lib/src/04-FixedLoopVariableRender.dart index 3df27bf..b51e268 100644 --- a/lib/src/04-FixedLoopVariableRender.dart +++ b/lib/src/04-FixedLoopVariableRender.dart @@ -23,7 +23,6 @@ class FixedLoopVariableRender implements LoopExample, VariableUpdates { } render(lag / MS_PER_UPDATE); id = window.requestAnimationFrame(eventloop); - } void update() { @@ -45,4 +44,4 @@ class FixedLoopVariableRender implements LoopExample, VariableUpdates { elapsed.reset(); window.requestAnimationFrame(eventloop); } -} \ No newline at end of file +} diff --git a/lib/src/05_DirtyFlagRendering.dart b/lib/src/05_DirtyFlagRendering.dart index 48072b6..4cac73c 100644 --- a/lib/src/05_DirtyFlagRendering.dart +++ b/lib/src/05_DirtyFlagRendering.dart @@ -22,9 +22,8 @@ class DirtyFlagRender implements LoopExample, VariableUpdates { update(); lag -= MS_PER_UPDATE; } - if(dirty) render(lag / MS_PER_UPDATE); + if (dirty) render(lag / MS_PER_UPDATE); id = window.requestAnimationFrame(eventloop); - } void update() { @@ -51,4 +50,4 @@ class DirtyFlagRender implements LoopExample, VariableUpdates { elapsed.reset(); window.requestAnimationFrame(eventloop); } -} \ No newline at end of file +} diff --git a/web/main.dart b/web/main.dart index 476ac28..fa5ed12 100644 --- a/web/main.dart +++ b/web/main.dart @@ -9,10 +9,14 @@ import 'package:browserloop/src/05_DirtyFlagRendering.dart'; CanvasElement baseCanvas = new CanvasElement(width: 480, height: 480); List examples = [ - Example("While Loop Example", "#while_loop", new WhileLoop(new Game(baseCanvas))), - Example("Variable Timestep", "#variable_timestep", new VariableTimestep(new Game(baseCanvas))), - Example("Fixed Update, Variable Render", "#fixed_variable", new FixedLoopVariableRender(new Game(baseCanvas))), - Example("Variable Render with Dirty Flag", "#dirty_flag", new DirtyFlagRender(new Game(baseCanvas))) + Example( + "While Loop Example", "#while_loop", new WhileLoop(new Game(baseCanvas))), + Example("Variable Timestep", "#variable_timestep", + new VariableTimestep(new Game(baseCanvas))), + Example("Fixed Update, Variable Render", "#fixed_variable", + new FixedLoopVariableRender(new Game(baseCanvas))), + Example("Variable Render with Dirty Flag", "#dirty_flag", + new DirtyFlagRender(new Game(baseCanvas))) ]; LoopExample active; @@ -24,11 +28,12 @@ class Example { Example(this.name, this.query, this.loop); CanvasElement get canvas { - if(loop != null) return loop.game.canvas; + if (loop != null) return loop.game.canvas; return new CanvasElement(width: 480, height: 480); } + set canvas(CanvasElement canvas) { - if(loop != null) loop.game.canvas = canvas; + if (loop != null) loop.game.canvas = canvas; } } @@ -144,9 +149,10 @@ void addControls(Example ex) { ..max = "50" ..value = "3" ..step = "1" - ..onInput.listen((Event e) { - loop.MS_PER_UPDATE = (1000 / int.parse((e.target as InputElement).value)); - })); + ..onInput.listen((Event e) { + loop.MS_PER_UPDATE = + (1000 / int.parse((e.target as InputElement).value)); + })); // querySelector('#reset').onClick.listen((e) => ex.loop.game.reset()); // querySelector('#plus').onClick.listen((e) => _changeGrid(-5)); // querySelector('#minus').onClick.listen((e) => _changeGrid(5));