cellular_automata_web 1.0.1

cellular_automata_web #

Pub Package Version Latest Dartdocs

Library containing various web renderers for the cellular_automata Dart package.

Web demos #

Play with the hosted demos here. Source code is in the demos/ folder.

Renderers #

  • CanvasRenderer : HTML Canvas renderer, this is the recommended renderer for web.
  • StageXLRenderer : WebGL renderer although in this context not quite as performant as Canvas.
  • HtmlTableRenderer : A HTML table using table cells & css (just for fun!)

Build config #

For best perfomance ensure that you set --omit-implicit-checks and --trust-primitives as dart2js arguments in your build config. See the demo release config for an example of this.

Changelog #

1.0 #

  • New renderer: HtmlTableRenderer (just for fun!)
  • Initial import. This repository contains the various web renderers that previously were included in the main cellular_automata package.


// Copyright (c) 2017, jimmyff. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.

import 'dart:html';
import 'package:cellular_automata/cellular_automata.dart';
import 'package:cellular_automata/rules.dart';

import 'package:cellular_automata_web/renderer_canvas.dart';

// Simple example of using cellular_automata with a web canvas renderer
// Include a canvas element in your html: <canvas id="canvas"></canvas>
void main() {
  final palette = new Map<GameOfLifeStates, String>.from({
    GameOfLifeStates.dead: '#000',
    GameOfLifeStates.deadUnderPopulated: '#483D8B',
    GameOfLifeStates.deadOverPopulated: '#00008B',
    GameOfLifeStates.alive: '#FF69B4',
    GameOfLifeStates.aliveBorn: '#FFC0CB',
  const width = 64;
  const height = 64;

  final scene = new Scene<String>(width: width, height: height, fpsTarget: 15);

  // create the Cnvas renderer that will paint our scene
  final renderer = new CanvasRenderer(width: width, height: height)
        canvas: querySelector('#canvas'),
        canvasWidth: 512,
        canvasHeight: 512,
        paintFullSize: true);

    ..onPrepare.listen((int count) {
      // setup the scene
            automaton: new Automaton<GameOfLifeStates, String>(
          width: width,
          height: height,
          palette: palette,
          defaultState: GameOfLifeStates.dead,
          wrap: true,
          rules: new GameOfLife(),
        )..applyGenerator(new MathematicalGenerator<GameOfLifeStates>(
                type: MathematicalGenerators.random,
                valueTrue: GameOfLifeStates.alive,
                valueFalse: GameOfLifeStates.dead)));
    ..onComplete.listen((SceneCompleteReason s) {
      // restart the scene when complete

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  cellular_automata_web: ^1.0.1

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:cellular_automata_web/renderer_canvas.dart';
import 'package:cellular_automata_web/renderer_html_table.dart';
import 'package:cellular_automata_web/renderer_stagexl.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Feb 14, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.5

Health suggestions

Fix lib/src/renderers/stagexl_renderer.dart. (-6.31 points)

Analysis of lib/src/renderers/stagexl_renderer.dart reported 13 hints, including:

line 8 col 14: Unnecessary new keyword.

line 25 col 38: Use = to separate a named parameter from its default value.

line 51 col 20: Unnecessary new keyword.

line 54 col 23: Unnecessary new keyword.

line 55 col 19: Unnecessary new keyword.

Fix lib/src/renderers/html_table_renderer.dart. (-3.45 points)

Analysis of lib/src/renderers/html_table_renderer.dart reported 7 hints, including:

line 5 col 14: Unnecessary new keyword.

line 20 col 21: Use = to separate a named parameter from its default value.

line 21 col 22: Use = to separate a named parameter from its default value.

line 22 col 25: Use = to separate a named parameter from its default value.

line 44 col 19: Unnecessary new keyword.

Fix lib/src/renderers/canvas_renderer.dart. (-1 points)

Analysis of lib/src/renderers/canvas_renderer.dart reported 2 hints:

line 5 col 14: Unnecessary new keyword.

line 64 col 7: DO use curly braces for all flow control structures.

Maintenance suggestions

Package is getting outdated. (-55.34 points)

The package was last published 81 weeks ago.

The package description is too short. (-3 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.61.0 <3.0.0
cellular_automata ^1.0.0 1.0.2
logging ^0.11.3+1 0.11.4
stagexl ^1.2.0+3 1.4.3
Transitive dependencies
charcode 1.1.3
collection 1.14.12
convert 2.1.1
meta 1.1.8
petitparser 3.0.1
typed_data 1.1.6
xml 3.7.0
Dev dependencies
test ^1.3.0