Pattern-rewrite Automata
Cellular automata based on rewriting rules (axioms).
by Nikita Sadkov
HTML
<p id="info">hello</p>
<canvas id="canvas" width="400" height="400" style="border:1px solid #000000;"></canvas>
JavaScript
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
var cv_w = canvas.width;
var cv_h = canvas.height;
var info = document.getElementById('info');
var colorize = 0;
var FPS = 30; //frames per seconds
var cols = 20;
var rows = 20;
//the color of a cells is determined by number of neigbors
var colors = ["#00001f","#1f003f","#3f005f","#5f007f",
"#9f003f","#b00000","#d01f00","#e01f70",
"#ff5fE0"];
var cell_w = cv_w/cols
var cell_h = cv_h/rows
var world0 = []
var world1 = []
for (y = -1; y < rows+1; y++) {
world0[y] = [];
world1[y] = [];
for (x = -1; x < cols+1; x++) {
world0[y][x] = 0;
world1[y][x] = 0;
}
}
world = world0;
var initial0 = ""+
" 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 |"+
"0 |"+
"1 |"+
"2 |"+
"3 |"+
"4 * * |"+
"5 * * |"+
"6 * * |"+
"7 |"+
"8 * |"+
"9 * * |"+
"0 |"+
"1 |"+
"2 |"+
"3 |"+
"4 * * * |"+
"5 * * |"+
"6 * * * * |"+
"7 * * |"+
"8 |"+
"9 ";
var rules_proto0 = ""+
"-r------------|"+
" = * |"+
"* * * = * |"+
" = * |"+
"-r------------|"+
"* = * |"+
"? * ? = * |"+
"* = * |"+
"-r------------|"+
" * ? = |"+
"* * ? = * |"+
"? ? ? = * * |"+
"-r------------|"+
"* * = ...