cellular-automata/lib/app_component.dart

62 lines
1.2 KiB
Dart
Raw 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;
2018-07-09 13:16:28 +00:00
import 'package:rules_of_living/src/Engine.dart';
2018-07-07 14:44:27 +00:00
2018-07-07 13:46:40 +00:00
@Component(
2018-07-07 18:49:02 +00:00
selector: 'my-app',
templateUrl: "app_component.html",
directives: [coreDirectives])
2018-07-07 14:44:27 +00:00
class AppComponent implements OnInit {
var name = "World";
2018-07-09 13:16:28 +00:00
Engine engine;
2018-07-07 14:44:27 +00:00
@ViewChild("caCanvas")
html.CanvasElement canvas;
@override
void ngOnInit() {
2018-07-07 19:07:42 +00:00
canvas.context2D.setFillColorRgb(200, 0, 0);
canvas.context2D.fillRect(0, 0, canvas.width, canvas.height);
canvas.context2D.setFillColorRgb(0, 255, 0);
canvas.context2D.fillText('''
If you see this
the app is broken :(
''', canvas.width/2, canvas.height/2);
2018-07-09 13:16:28 +00:00
engine = new Engine(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() {
2018-07-09 15:27:56 +00:00
engine.step();
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() {
engine.running = false;
2018-07-09 15:32:35 +00:00
engine.addPattern();
}
2018-07-08 17:01:14 +00:00
void onEdgesClicked() {
engine.toggleEdgeRendering();
2018-07-08 17:01:14 +00:00
}
2018-07-08 17:45:35 +00:00
void onClearClicked() {
engine.clear();
2018-07-08 17:45:35 +00:00
}
2018-07-07 13:46:40 +00:00
}