Piet

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 colors = ['#cc0000', '#ffc118', '#0d0a51', 'none', 'none', 'none'];
var backgroundColor = '#cdd7b5';

s.rect(0, 0, width, height).attr({fill: backgroundColor})

// adapted from https://raw.githubusercontent.com/odewahn/codebox_recursion_examples/master/mondrian.pde

var n = 2;

// Draw a Mondarian-inspired image using recursion
function piet(x0, y0, x1, y1, n) {
 if (n == 0) {
   var sw = 3;
   s.rect(x0, y0, x1 - x0 - sw, y1 - y0 - sw).attr({fill: colors[getRandomInt(0, colors.length - 1)], strokeWidth: sw, stroke: '#000000'});
 } else {
    var i = getRandomInt(x0, x1);
    var j = getRandomInt(y0, y1);

    piet(x0, y0, i, j, n - 1); // Recurse on upper left rectangle
    piet(i, y0, x1, j, n - 1); // Recurse on upper right rectangle
    piet(x0, j,i,y1, n - 1);   // Recurse on lower left rectangle
    piet(i, j, x1, y1, n - 1); // Recurse on lower right rectangle
 }
}

piet(1, 1, width, height, n);