Skip to content

Instantly share code, notes, and snippets.

@ucnv
Created March 7, 2010 16:09
Show Gist options
  • Save ucnv/324440 to your computer and use it in GitHub Desktop.
Save ucnv/324440 to your computer and use it in GitHub Desktop.
<!doctype html>
<html>
<head>
<title>patterns</title>
<meta charset="utf-8">
<style type="text/css">
body {
text-align: center;
}
#x {
font-family: Arial, sans-serif;
font-size: 14px;
line-height: 1;
margin: 10px auto;
}
</style>
<script>
function patterns() {
var rows = 3;
var cols = 40;
var lines = [];
var d = {
'╫': 0,
'═': 5, // 0101
'║': 10, // 1010
'╔': 6, // 0110
'╗': 3, // 0011
'╚': 12, // 1100
'╝': 9, // 1001
'╠': 14, // 1110
'╣': 11, // 1011
'╦': 7, // 0111
'╩': 13, // 1101
'╬': 15, // 1111
};
var prevLine, thisLine;
for(var i = 0; i < rows; i++) {
thisLine = [];
for(var j = 0; j < cols; j++) {
var firstRow = i == 0, lastRow = i == rows - 1;
var firstCol = j == 0, lastCol = j == cols - 1;
var u = firstRow ? 0 : d[prevLine[j]] >> 1 & 1;
var l = firstCol ? 0 : d[thisLine[j - 1]] >> 2 & 1;
var c = [];
for(var x in d) {
if((d[x] >> 3 & 1) == u && (d[x] >> 0 & 1) == l) {
if(lastCol && (d[x] >> 2 & 1) == 1) continue;
if(lastRow && (d[x] >> 1 & 1) == 1) continue;
if(!lastCol && (firstRow || lastRow) && (d[x] >> 2 & 1) == 0) continue;
if(!lastRow && (firstCol || lastCol) && (d[x] >> 1 & 1) == 0) continue;
c.push(x);
}
}
thisLine[j] = c[Math.floor(Math.random() * c.length)];
}
lines.push(thisLine.join(''));
prevLine = thisLine;
}
var x = document.getElementById('x');
x.innerHTML = lines.join('<br />');
}
window.onload = function() {
patterns();
var ix = window.setInterval(patterns, 1000);
window.stop = function() { window.clearInterval(ix); };
};
</script>
</head>
<body><div id="x"></div>
<p><a href="javascript:stop();">stop</a></p></body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment