/ p5 / re-code 12

Inspiré par Computer Graphics and Art vol3 n°2 page 31, « Unimaginable Images » (from the « 196 Trapeziums Series ») de Vera Molnar

// This sketch is part of the ReCode Project - http://recodeproject.com
// From Computer Graphics and Art vol3 no2 pg 31
// Unimaginable Images (from the "196 Trapeziums Series")
// by Vera Molnar
// 
// 
// Quin Kennedy
// 2012
// Creative Commons license CC BY-SA 3.0

var numTiles = 14;
var gutterRelativeSize = .5;
var windowSize = 780;
//we need space for each tile, 
//space for each gutter above each tile, 
//and space for the final gutter (below of the bottom row)


function setup(){
 var tileSize = floor(windowSize/(numTiles*(1+gutterRelativeSize)+gutterRelativeSize));
 var gutterSize = floor(tileSize*gutterRelativeSize);
 var actualWinSize = (tileSize+gutterSize)*numTiles+gutterSize;
 createCanvas(actualWinSize, actualWinSize);
 noLoop();
}

function draw(){
 background(255);
 stroke(0);
 var tileSize = floor(windowSize/(numTiles*(1+gutterRelativeSize)+gutterRelativeSize));
 var gutterSize = floor(tileSize*gutterRelativeSize);
 //strokeWeight(2);
 strokeJoin(ROUND);
 noFill();
 //for each grid cell...
 for(var i = 0, gi = gutterSize; i < numTiles; i++, gi += gutterSize+tileSize){
 for(var j = 0, gj = gutterSize; j < numTiles; j++, gj += gutterSize+tileSize){
 drawTrapezium(gi+tileSize/2, gj+tileSize/2);
 }
 }
}

function drawTrapezium(xCenter, yCenter){
 var tileSize = floor(windowSize/(numTiles*(1+gutterRelativeSize)+gutterRelativeSize));

 var topScale = random(-2, 2);
 var bottomScale = random(-2, 2);
 var halfTile = tileSize/2.;
 quad(xCenter - tileSize/2 + random(-tileSize, tileSize), yCenter - halfTile,
 xCenter + tileSize/2 + random(-tileSize, tileSize), yCenter - halfTile,
 xCenter + tileSize/2 + random(-tileSize, tileSize), yCenter + halfTile,
 xCenter - tileSize/2 + random(-tileSize, tileSize), yCenter + halfTile);
}