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.

example/example.dart

// 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)
    ..initCanvas(
        canvas: querySelector('#canvas'),
        canvasWidth: 512,
        canvasHeight: 512,
        paintFullSize: true);

  scene
    ..onPrepare.listen((int count) {
      // setup the scene
      scene
        ..clearAutomata()
        ..addAutomaton(
            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)));
    })
    ..onPaint.listen(renderer.render)
    ..onComplete.listen((SceneCompleteReason s) {
      // restart the scene when complete
      scene
        ..stop()
        ..start();
    })
    ..start();
}

Use this package as a library

1. Depend on it

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


dependencies:
  cellular_automata_web: ^1.0.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support 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';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
95
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
97
Overall:
Weighted score of the above. [more]
48
Learn more about scoring.

We analyzed this package on Jul 13, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: web

Platform components identified in package: html.

Health suggestions

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

Analysis of lib/src/renderers/stagexl_renderer.dart reported 5 hints:

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

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

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

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

line 96 col 11: DO use curly braces for all flow control structures.

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

Analysis of lib/src/renderers/html_table_renderer.dart reported 4 hints:

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 58 col 7: DO use curly braces for all flow control structures.

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

Analysis of lib/src/renderers/canvas_renderer.dart reported 1 hint:

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

Maintenance suggestions

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.

Dependencies

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.3+2
stagexl ^1.2.0+3 1.4.0+3
Transitive dependencies
charcode 1.1.2
collection 1.14.11
convert 2.1.1
meta 1.1.7
petitparser 2.4.0
typed_data 1.1.6
xml 3.5.0
Dev dependencies
test ^1.3.0

Admin