Skip to content

Instantly share code, notes, and snippets.

@frigginglorious
Forked from whackashoe/gist:ffa7aea78467ecc73abc
Last active February 29, 2016 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frigginglorious/a1763fe38c7f7e436b03 to your computer and use it in GitHub Desktop.
Save frigginglorious/a1763fe38c7f7e436b03 to your computer and use it in GitHub Desktop.
radial-2 neighborhood 1d ca
<html>
<head></head>
<body>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r74/three.min.js"></script>
<script>
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)); })]; }
);
document.write(grid);
}
}(_.random(1 << 30), 32));
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment