Created
March 10, 2010 15:00
-
-
Save ucnv/327949 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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 = 4; | |
var cols = 29; | |
var lines = [' ']; | |
var d = { | |
'╭': 6, | |
'╮': 3, | |
'╯': 9, | |
'╰': 12 | |
}; | |
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 ? (Math.random() > 0.5) : d[prevLine[j]] >> 1 & 1; | |
var l = firstCol ? (Math.random() > 0.5) : d[thisLine[j - 1]] >> 2 & 1; | |
var c = []; | |
for(var x in d) { | |
if((d[x] >> 3 & 1) == u && (d[x] >> 0 & 1) == l) { | |
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 interval = 1200, ix = window.setInterval(patterns, interval); | |
window.pause = function() { | |
if(ix) { | |
window.clearInterval(ix); | |
ix = false | |
} else { | |
ix = window.setInterval(patterns, interval); | |
} | |
} | |
}; | |
</script> | |
</head> | |
<body><div id="x"></div> | |
<p><a href="javascript:pause();">pause</a></p></body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment