Created
July 1, 2015 17:52
-
-
Save deitrick/2d824f0c5cf0f0be671b to your computer and use it in GitHub Desktop.
box thing
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
$(document).ready(function() { | |
// create new grid object based on size[[x,x], [x,x]] | |
var grid = new Grid(5).init(); | |
// set top left (first element of first array) to be full | |
grid[0][0].value = 1; | |
// build the dom | |
grid.forEach(function(row, i) { | |
$("#grid").append("<div class='row row-" + i + "'></div>"); | |
row.forEach(function(spot){ | |
if (spot.value === 1) { | |
$(".row-" + i).append("<div class='spot full'></div>") | |
} else { | |
$(".row-" + i).append("<div class='spot'></div>") | |
} | |
}); | |
}); | |
}); | |
function Grid (size) { | |
this.init = function() { | |
var grid = []; | |
for (var i = 0; i < size; i++) { | |
var row = []; | |
for (var x = 0; x < size; x++) { | |
row.push(new Box()); | |
} | |
grid.push(row); | |
}; | |
return grid; | |
} | |
} | |
function Box(value) { | |
this.value = value | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment