Apply dartfmt
This commit is contained in:
parent
2f96712b60
commit
34bdd1ae81
5 changed files with 27 additions and 31 deletions
|
@ -4,10 +4,9 @@ import 'dart:html' as html;
|
||||||
import 'package:rules_of_living/src/App.dart';
|
import 'package:rules_of_living/src/App.dart';
|
||||||
|
|
||||||
@Component(
|
@Component(
|
||||||
selector: 'my-app',
|
selector: 'my-app',
|
||||||
templateUrl: "app_component.html",
|
templateUrl: "app_component.html",
|
||||||
directives: [coreDirectives]
|
directives: [coreDirectives])
|
||||||
)
|
|
||||||
class AppComponent implements OnInit {
|
class AppComponent implements OnInit {
|
||||||
var name = "World";
|
var name = "World";
|
||||||
|
|
||||||
|
|
|
@ -18,9 +18,8 @@ class App {
|
||||||
num _updateLag = 0.0;
|
num _updateLag = 0.0;
|
||||||
num _drawLag = 0.0;
|
num _drawLag = 0.0;
|
||||||
|
|
||||||
|
|
||||||
final html.CanvasElement canvas;
|
final html.CanvasElement canvas;
|
||||||
Grid grid = new Grid(100,100);
|
Grid grid = new Grid(100, 100);
|
||||||
bool running = false;
|
bool running = false;
|
||||||
|
|
||||||
App(this.canvas) {
|
App(this.canvas) {
|
||||||
|
@ -28,13 +27,13 @@ class App {
|
||||||
grid.startingPattern();
|
grid.startingPattern();
|
||||||
}
|
}
|
||||||
|
|
||||||
void reset () {
|
void reset() {
|
||||||
grid = new Grid(100, 100);
|
grid = new Grid(100, 100);
|
||||||
running = false;
|
running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void process(num now) {
|
void process(num now) {
|
||||||
_drawLag+= _elapsed.elapsedMilliseconds;
|
_drawLag += _elapsed.elapsedMilliseconds;
|
||||||
_updateLag += _elapsed.elapsedMilliseconds;
|
_updateLag += _elapsed.elapsedMilliseconds;
|
||||||
_elapsed.reset();
|
_elapsed.reset();
|
||||||
|
|
||||||
|
@ -59,7 +58,6 @@ class App {
|
||||||
grid.update();
|
grid.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void render([num interp]) {
|
void render([num interp]) {
|
||||||
// print("rendering");
|
// print("rendering");
|
||||||
grid.render(canvas, interp);
|
grid.render(canvas, interp);
|
||||||
|
|
|
@ -20,8 +20,8 @@ class Cell {
|
||||||
|
|
||||||
void update(int neighbors) {
|
void update(int neighbors) {
|
||||||
if (state == true) {
|
if (state == true) {
|
||||||
surviveRules.forEach( (Rule rule) {
|
surviveRules.forEach((Rule rule) {
|
||||||
if(rule.evaluate(neighbors) == true) this.nextState = true;
|
if (rule.evaluate(neighbors) == true) this.nextState = true;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
birthRules.forEach((Rule rule) {
|
birthRules.forEach((Rule rule) {
|
||||||
|
|
|
@ -4,10 +4,7 @@ import 'dart:math' as math;
|
||||||
import 'package:rules_of_living/src/Cell.dart';
|
import 'package:rules_of_living/src/Cell.dart';
|
||||||
import 'package:rules_of_living/src/Rule.dart';
|
import 'package:rules_of_living/src/Rule.dart';
|
||||||
|
|
||||||
enum Pattern {
|
enum Pattern { SpaceShip, Blinker }
|
||||||
SpaceShip,
|
|
||||||
Blinker
|
|
||||||
}
|
|
||||||
|
|
||||||
class Grid {
|
class Grid {
|
||||||
final int w;
|
final int w;
|
||||||
|
@ -25,24 +22,25 @@ class Grid {
|
||||||
print("Grid creation finished");
|
print("Grid creation finished");
|
||||||
}
|
}
|
||||||
|
|
||||||
void startingPattern({Pattern pattern, int x, int y, int amount, int dispersal}) {
|
void startingPattern(
|
||||||
|
{Pattern pattern, int x, int y, int amount, int dispersal}) {
|
||||||
math.Random rng = new math.Random();
|
math.Random rng = new math.Random();
|
||||||
int cx = x ?? rng.nextInt(w~/3) + (w~/3);
|
int cx = x ?? rng.nextInt(w ~/ 3) + (w ~/ 3);
|
||||||
int cy = y ?? rng.nextInt(h~/3) + (h~/3);
|
int cy = y ?? rng.nextInt(h ~/ 3) + (h ~/ 3);
|
||||||
switch (pattern) {
|
switch (pattern) {
|
||||||
// Two blocks, offset
|
// Two blocks, offset
|
||||||
// ##
|
// ##
|
||||||
// ##
|
// ##
|
||||||
case Pattern.Blinker:
|
case Pattern.Blinker:
|
||||||
setCellState(cx, cy, true);
|
setCellState(cx, cy, true);
|
||||||
setCellState(cx+1, cy, true);
|
setCellState(cx + 1, cy, true);
|
||||||
setCellState(cx, cy+1, true);
|
setCellState(cx, cy + 1, true);
|
||||||
setCellState(cx+1, cy+1, true);
|
setCellState(cx + 1, cy + 1, true);
|
||||||
|
|
||||||
setCellState(cx+2, cy+2, true);
|
setCellState(cx + 2, cy + 2, true);
|
||||||
setCellState(cx+3, cy+2, true);
|
setCellState(cx + 3, cy + 2, true);
|
||||||
setCellState(cx+2, cy+3, true);
|
setCellState(cx + 2, cy + 3, true);
|
||||||
setCellState(cx+3, cy+3, true);
|
setCellState(cx + 3, cy + 3, true);
|
||||||
break;
|
break;
|
||||||
// A 'gliding' Spaceship
|
// A 'gliding' Spaceship
|
||||||
// #
|
// #
|
||||||
|
@ -57,7 +55,8 @@ class Grid {
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
for (var i = 0; i < amount ?? rng.nextInt(20); i++) {
|
for (var i = 0; i < amount ?? rng.nextInt(20); i++) {
|
||||||
setCellState(cx + dispersal ?? rng.nextInt(10), cy + dispersal ?? rng.nextInt(10), true);
|
setCellState(cx + dispersal ?? rng.nextInt(10),
|
||||||
|
cy + dispersal ?? rng.nextInt(10), true);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -82,11 +81,11 @@ class Grid {
|
||||||
|
|
||||||
// DEBUG RULE TESTING FOR PATTERNS
|
// DEBUG RULE TESTING FOR PATTERNS
|
||||||
Rule coagSurvive = new Rule((int n) {
|
Rule coagSurvive = new Rule((int n) {
|
||||||
if (n==1) return true;
|
if (n == 1) return true;
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
Rule coagBirth = new Rule((int n) {
|
Rule coagBirth = new Rule((int n) {
|
||||||
if (n==1) return true;
|
if (n == 1) return true;
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue