cellular-automata/lib/service/engine_service.dart

45 lines
646 B
Dart
Raw Normal View History

import 'dart:html' as html;
import 'package:rules_of_living/src/Engine.dart';
class EngineService {
Engine _engine;
Engine get engine => _engine ?? create(null);
Engine create(html.CanvasElement canvas) {
_engine = Engine(canvas);
return _engine;
}
void run() {
engine.running = true;
}
void stop() {
engine.running = false;
}
void toggleRunning() {
engine.running = !engine.running;
}
void step() {
engine.step();
}
void reset() {
engine.reset();
}
void addRandomPattern() {
engine.running = false;
engine.addPattern();
}
void clear() {
engine.clear();
}
}