Skip to content

Instantly share code, notes, and snippets.

@peterchester
Created October 26, 2012 23:17
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 peterchester/3962111 to your computer and use it in GitHub Desktop.
Save peterchester/3962111 to your computer and use it in GitHub Desktop.
I Ching Random Walk
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<style>
.ichingchar {
padding: 0;
margin: 0;
height: 24px;
width: 19px;
display: block;
float: left;
font-size: 33px;
}
</style>
</head>
<body>
<input type="submit" id="start" value="Random Walk with the I Ching" />
<div id="iching"></div>
<script>
chars = [
'&#19904;', // ䷀
'&#19946;', // ䷪
'&#19917;', // ䷍
'&#19912;', // ䷈
'&#19913;', // ䷉
'&#19916;', // ䷌
'&#19947;' // ䷫
];
i = 0;
function bounceiching() {
inc = Math.round(Math.random()*3) - 1;
i = Math.abs(( i + inc )) % chars.length;
$("#iching").html( '<span class="ichingchar" id="char'+i+'">'+chars[ i ]+'</span>' + $("#iching").html() );
}
$(document).ready(function() {
interval = false;
interval_toggle = false;
$("#start").click(function() {
if (interval_toggle) {
clearInterval(interval);
interval_toggle = false;
$(this).val("CONTINUE");
} else {
interval = setInterval("bounceiching()", 50);
interval_toggle = true;
$(this).val("STOP");
}
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment