Atlas Fold

to generate a new and unique variation

Source Code

Every variart piece is a small program. This is the one that drew what you're looking at.

var background = '#CFCBC2';
// Quiet planes, repeated so they turn up more often than the loud ones.
var planes = ['#E9E4D6', '#E9E4D6', '#B9B8B1', '#B9B8B1', '#C9D6A6', '#7FC7BD',
              '#D7A93B', '#9E9C3A', '#E34A8C', '#E77F8E', '#E64B2E', '#6A3A22', '#1C2A20'];
var bars = ['#E8322B', '#111111', '#F07C84', '#F2EDE0'];
var margin = 60;

var columns = intVariable('Columns', 3, 7);
var fold = intVariable('Fold', 10, 45);

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

var w = (width - margin * 2) / columns;
var rows = 8;
var rowH = (height - margin * 2 - fold) / rows;

// A seam's height at a column edge: alternate edges sit a Fold lower, so
// every seam zig-zags across the sheet and neighbouring columns fold apart.
function seam(k, edge){
  return margin + k * rowH + (edge % 2) * fold;
}

function cell(c, k0, k1, fill){
  var x0 = margin + c * w, x1 = x0 + w;
  s.polygon(x0, seam(k0, c), x1, seam(k0, c + 1), x1, seam(k1, c + 1), x0, seam(k1, c))
    .attr({fill: fill, stroke: fill, strokeWidth: 0.5});
}

// Columns start and stop at staggered rows, like strips of folded paper.
for (var c = 0; c < columns; c++){
  var start = getRandomInt(0, 2), end = rows - getRandomInt(0, 2);
  // Planes span one to three rows, so the column has tall panels and short.
  var k = start;
  while (k < end){
    var span = Math.min(getRandomInt(1, 3), end - k);
    cell(c, k, k + span, planes[getRandomInt(0, planes.length - 1)]);
    k += span;
  }
}

// Bars ride a seam across two neighbouring columns, reading as chevrons.
var chevrons = getRandomInt(2, 4);
for (var i = 0; i < chevrons; i++){
  var c0 = getRandomInt(0, columns - 2);
  var k = getRandomInt(2, rows - 3);
  var fill = bars[getRandomInt(0, bars.length - 1)];
  cell(c0, k, k + 0.35, fill);
  cell(c0 + 1, k, k + 0.35, fill);
}