Bad Procedural Code
by STHayden
HTML
<div></div>
JavaScript
var div = $('div');
var xLimit = 50;
var yLimit = 50;
var seed = 12345;
var map = Map();
map.forEach(function(row, y) {
var rowEl = $('<div />');
rowEl.css({ height: 10 });
row.forEach(function(point, x) {
var s = getColorSquare(point);
rowEl.append(s);
});
div.append(rowEl);
});
function Map() {
var map = [];
for(var y = 0; y <= yLimit; y++) {
var row = [];
for(var x = 0; x <= xLimit; x++) {
var type = getType(seed, x, y);
row.push(type);
}
map.push(row);
}
return map;
}
function mapConsolidate(map) {
map.forEach(function(row, y) {
row.forEach(function(type, x) {
var north = map[y-1, x];
var east = map[y, x+1];
var south = map[y+1, x];
var west = map[y, x-1];
});
})
}
/*
map.forEach(function(row, y) {
row.forEach(function(type, x) {
});
})
*/
function getType(seed, x, y) {
var base = Math.cos((x * seed) + (y + seed)) * seed;
var rounded = Math.round(base);
var type = rounded % 3;
if(type) {
return 'blue';
} else {
return 'green';
}
}
function getColorSquare(type) {
var s = $('<div />').css({
height: 10,
width: 10,
background: type,
float: 'left',
});
return s;
}