cellular-automata/lib/app_component.dart

48 lines
899 B
Dart
Raw Permalink Normal View History

2018-07-07 13:46:40 +00:00
import 'package:angular/angular.dart';
2018-07-07 14:44:27 +00:00
import 'dart:html' as html;
import 'package:rules_of_living/src/App.dart';
2018-07-07 13:46:40 +00:00
@Component(
selector: 'my-app',
2018-07-07 17:05:56 +00:00
templateUrl: "app_component.html",
directives: [coreDirectives]
2018-07-07 13:46:40 +00:00
)
2018-07-07 14:44:27 +00:00
class AppComponent implements OnInit {
var name = "World";
App engine;
@ViewChild("caCanvas")
html.CanvasElement canvas;
@override
void ngOnInit() {
canvas.context2D.setFillColorRgb(255, 0, 0);
canvas.context2D.fillRect(0, 0, 200, 150);
engine = new App(canvas);
2018-07-07 14:44:27 +00:00
html.window.animationFrame.then(animFrame);
}
void animFrame(num now) {
engine.process(now);
html.window.animationFrame.then(animFrame);
}
2018-07-07 15:47:37 +00:00
void onStartClicked() {
engine.running = !engine.running;
2018-07-07 17:05:56 +00:00
}
2018-07-07 15:47:37 +00:00
2018-07-07 17:05:56 +00:00
void onStepClicked() {
engine.running = false;
engine.update();
2018-07-07 17:05:56 +00:00
}
void onResetClicked() {
engine.reset();
2018-07-07 15:47:37 +00:00
}
2018-07-07 17:05:56 +00:00
void onRandomClicked() {}
2018-07-07 13:46:40 +00:00
}