Skip to content

Instantly share code, notes, and snippets.

@jacktandrew
Created March 20, 2012 07:38
Show Gist options
  • Save jacktandrew/2132556 to your computer and use it in GitHub Desktop.
Save jacktandrew/2132556 to your computer and use it in GitHub Desktop.
Dominoes with Recursion
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="js/lib/underscore.js"></script>
<script src="js/lib/simple-inheritance.js"></script>
<script src="js/lib/backbone.js"></script>
<script src="js/lib/jStorage.js"></script>
<style>
div.tile {height: 70px; width: 35px; border-radius: 7px; float: left; margin: 10px;}
div.tile, div.bar {border: 2px outset #444;}
div.pips {height: 30px; width: 35px;position: relative; margin-top: 2px;}
div.pips div {border-radius: 5px; height: 4px; width: 5px; background: #333; position: absolute; border:2px inset #444;}
div.bar {height:0px; width: 25px; margin: 0 3px;}
.pips._1 div {top: 11px; left: 13px;}
.pips._2 div, .pips._4 div {top: 5px; left: 6px;}
.pips._2 div:last-child, .pips._4 div:last-child {top: 17px; left: 20px;}
.pips._3 div, .pips._5 div {top: 3px; left: 4px;}
.pips._3 div:nth-child(1), .pips._5 div:nth-child(2) {top: 11px; left: 13px;}
.pips._3 div:last-child, .pips._5 div:last-child {top: 19px; left: 22px;}
.pips._4 div:nth-child(1) {top: 5px; left: 20px;}
.pips._4 div:nth-child(2) {top: 17px; left: 6px;}
.pips._5 div:nth-child(1) {top: 3px; left: 22px;}
.pips._5 div:nth-child(3) {top: 19px; left: 4px;}
.pips._6 div {top: 1px; left: 4px;}
.pips._6 div:nth-child(1) {top: 11px; left: 4px;}
.pips._6 div:nth-child(2) {top: 21px; left: 4px;}
.pips._6 div:nth-child(3) {top: 1px; left: 22px;}
.pips._6 div:nth-child(4) {top: 11px; left: 22px;}
.pips._6 div:nth-child(5) {top: 21px; left: 22px;}
</style>
<script>
$(function() {
var boneyard = [];
function boneBuilder(a,b) {
boneyard.push('_' + a + '_' + b);
if (b === 0) { return boneyard }
if (a === 0) { a = b; b--; }
return boneBuilder(a-1,b);
};
boneBuilder(6,6);
function draw(n) {
for (i = 0; i < n; i++) {
var r = Math.floor(Math.random() * boneyard.length)
var pair = boneyard.splice(r,1)[0]
var newTile = $("<div class='tile'></div>").addClass(pair)
function makeFace(x){
return $("<div class='pips'></div>").addClass('_' + x).append( makePips(x) )
function makePips(x) {
var starter = "<div></div>"
if (x < 1) { return "" }
else { return starter.concat( makePips(x-1) ); }
}
}
newTile.append( makeFace( pair.slice(1,2) ) )
newTile.append("<div class='bar'></div>")
newTile.append( makeFace( pair.slice(3,4) ) )
$('body').append(newTile)
}
}
draw(28);
});
</script>
</head>
<body>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment