From 2c62e9112c25dec105906e2c36b3229638f9221b Mon Sep 17 00:00:00 2001 From: pommicket Date: Thu, 19 Jan 2017 22:13:04 -0500 Subject: Added Stochastic Elementary Cellular Automata --- all.html | 8 ++++++ js/stochasticca.js | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ mathematical.html | 12 +++++++-- stochasticca.html | 23 ++++++++++++++++ 4 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 js/stochasticca.js create mode 100644 stochasticca.html diff --git a/all.html b/all.html index 23c7bac..fd8c09e 100644 --- a/all.html +++ b/all.html @@ -168,6 +168,14 @@ +
+ +
+

diff --git a/js/stochasticca.js b/js/stochasticca.js new file mode 100644 index 0000000..5226c35 --- /dev/null +++ b/js/stochasticca.js @@ -0,0 +1,79 @@ +var params; + +function mod(a, b) +{ + var c = a % b; + while (a < 0) + { + c += b; + } + return c; +} + +function sigmoid(z) +{ + return 1 / (1 + Math.exp(-z)) +} + +function drawCA() +{ + try + { + params = $.parseJSON("[" + $("#params").val() + "]"); + var width = parseInt($("#width").val()); + var time = parseInt($("#time").val()); + } + catch(e) + { + $("#error").text("Error - Invalid parameters: " + $("#params").val() + "."); + return; + } + createCanvas(width, time); + var C = Math.floor(params.length / 2); + var values = [[]]; + for (var i = 0; i < width; i++) + { + values[0][i] = 1; + } + for (var t = 1; t < time; t++) + { + values.push([]); + for (var i = 0; i < width; i++) + { + var total = 0; + for (var c = -C; c <= C; c++) + { + total += params[c+C] * values[t-1][i+c]; + } + values[t].push(Math.random() < sigmoid(total) ? 1 : 0) + } + } + + for (var t = 0; t < time; t++) + { + for (var i = 0; i < width; i++) + { + stroke(values[t][i] === 1 ? 0 : 255); + point(i, t); + } + } +} + +function setup() +{ +} + +$(function() +{ + $("#params").keydown(function (e) + { + if (e.which == 13) + { + drawCA(); + } + }); + $("#display").click(function() + { + drawCA(); + }); +}); diff --git a/mathematical.html b/mathematical.html index 4dde0c1..477fa39 100644 --- a/mathematical.html +++ b/mathematical.html @@ -20,10 +20,18 @@ Shows a projection of a hypersphere onto the plane. It uses a 2x4 matrix to convert 4D points into 2D points. Use the arrow keys and the mouse to rotate it in 4D. - +
- + +
+ +
+

diff --git a/stochasticca.html b/stochasticca.html new file mode 100644 index 0000000..6f7bba9 --- /dev/null +++ b/stochasticca.html @@ -0,0 +1,23 @@ + + + + + + + + + + Stochastic Cellular Automata + + + + +

Stochastic Cellular Automata

+ Parameters:
+ Width:
+ Time:
+
+ + + + -- cgit v1.2.3