Minecraft

to generate a new and unique variation

Source Code

Every variart piece is open source, you can see exactly how it is drawn from the code.

var grassColors = ['#35601E', '#87AF62', '#4D7A34', '#508137'];
var dirtColors = ['#54382B', '#7B563D', '#886148']
var silverColors = ['#858386', '#79777A'];
var squareSize = 25;
var highlight = false;
var grassPercentage = [1.0, 1.0, 1.0, 0.9, 0.93, 0.67, 0.80];

for (var x = 0; x < width; x += squareSize){
  for (var y = 0; y < height; y += squareSize){

    // one flaw here, there can be holes in the grass...
    if (grassPercentage[y/squareSize] !== undefined){
      var ran = getRandomArbitary(0, 1);
      if (ran <= grassPercentage[y/squareSize]){
        var color = grassColors[getRandomInt(0, grassColors.length - 1)];                         
      } else {
        var color = dirtColors[getRandomInt(0, dirtColors.length - 1)]; 
      }
    } else {
      if (getRandomArbitary(0, 1) < .03){
        var color = silverColors[getRandomInt(0, silverColors.length - 1)];
      } else {
        var color = dirtColors[getRandomInt(0, dirtColors.length - 1)];        
      }
    }

    s.rect(x, y, squareSize, squareSize).attr({
      fill: color
    });
    
    if (highlight){
      s.line(x + squareSize, y, x + squareSize, y + squareSize).attr({
        stroke: '#000',
        strokeWidth: 3,
        strokeOpacity: 0.1
      });
  
      s.line(x, y + squareSize, x + squareSize, y + squareSize).attr({
        stroke: '#000',
        strokeWidth: 3,
        strokeOpacity: 0.1
      });
    }
  }
}