Skip to content

Instantly share code, notes, and snippets.

@whackashoe
Last active February 26, 2016 21:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save whackashoe/ffa7aea78467ecc73abc to your computer and use it in GitHub Desktop.
Save whackashoe/ffa7aea78467ecc73abc to your computer and use it in GitHub Desktop.
radial-2 neighborhood 1d ca
var ca = (function(rule, grid_size) {
var radius = 5;
var ruleset = _.map(_.range(1 << radius), function(i) { return (rule >> i) & 1; });
var grid = _.times(grid_size, _.random.bind(_, 0, 1));
for(var i=0; i<10; i++) {
grid = _.map(
_.zip.apply(_, _.map(_.range(-Math.floor(radius/2), Math.floor(radius/2)), _.partial(_.arr.rotate, grid, _))),
function(m) { return ruleset[_.foldl(m, function(a, b, i) { return a + (b * (1 << i)); })]; }
);
console.log(grid);
}
}(_.random(1 << 30), 32));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment