Implement Canvas as Angular Component
This commit is contained in:
parent
827ab83b88
commit
3780e61453
2 changed files with 25 additions and 20 deletions
|
@ -1,11 +1,14 @@
|
||||||
import 'package:angular/angular.dart';
|
import 'package:angular/angular.dart';
|
||||||
|
|
||||||
|
import 'dart:html' as html;
|
||||||
|
import 'package:rules_of_living/src/App.dart';
|
||||||
|
|
||||||
@Component(
|
@Component(
|
||||||
selector: 'my-app',
|
selector: 'my-app',
|
||||||
template: '''
|
template: '''
|
||||||
<h1>Hello {{name}}</h1>
|
<h1>Cellular Automata - The Rules of Life</h1>
|
||||||
<div id="output">
|
<div id="output">
|
||||||
<canvas id="canvas"></canvas>
|
<canvas #caCanvas width="500" height="500"></canvas>
|
||||||
</div>
|
</div>
|
||||||
<div id="controls">
|
<div id="controls">
|
||||||
<button id="run">Run</button>
|
<button id="run">Run</button>
|
||||||
|
@ -16,6 +19,24 @@ import 'package:angular/angular.dart';
|
||||||
</div>
|
</div>
|
||||||
''',
|
''',
|
||||||
)
|
)
|
||||||
class AppComponent {
|
class AppComponent implements OnInit {
|
||||||
var name = 'Darth Marty';
|
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);
|
||||||
|
html.window.animationFrame.then(animFrame);
|
||||||
|
}
|
||||||
|
|
||||||
|
void animFrame(num now) {
|
||||||
|
engine.process(now);
|
||||||
|
html.window.animationFrame.then(animFrame);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,23 +1,7 @@
|
||||||
import 'dart:html' as html;
|
|
||||||
|
|
||||||
import 'package:rules_of_living/App.dart';
|
|
||||||
|
|
||||||
import 'package:angular/angular.dart';
|
import 'package:angular/angular.dart';
|
||||||
import 'package:rules_of_living/app_component.template.dart' as ng;
|
import 'package:rules_of_living/app_component.template.dart' as ng;
|
||||||
|
|
||||||
html.CanvasElement el;
|
|
||||||
App engine;
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(ng.AppComponentNgFactory);
|
runApp(ng.AppComponentNgFactory);
|
||||||
|
|
||||||
el = new html.CanvasElement(width: 500, height: 500);
|
|
||||||
html.querySelector('#output').append(el);
|
|
||||||
engine = new App(el);
|
|
||||||
html.window.animationFrame.then(animFrame);
|
|
||||||
}
|
|
||||||
|
|
||||||
void animFrame(num now) {
|
|
||||||
engine.process(now);
|
|
||||||
html.window.animationFrame.then(animFrame);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue