Tessellate
to generate a new and unique variation
Every variart piece is open source, you can see exactly how it is drawn from the code.
var foregroundColors = ["#30cb9f","#add8e8","#df91c5","#e24fa0","#263a93","#39b3e6"];
var triangleSize = intVariable("Triangle Size", 40, 160);
var colorCount = intVariable("Colours", 3, foregroundColors.length);
var half = triangleSize / 2;
var rowHeight = triangleSize / 2;
var palette = foregroundColors.slice(0, colorCount);
// Pick a colour that differs from the triangle to the left and the one above,
// so no two triangles sharing an edge ever match.
function pickColor(left, above){
var color = left;
while (color == left || color == above){
color = palette[getRandomInt(0, palette.length - 1)];
}
return color;
}
var lastRow = [];
for (var row = 0; row * rowHeight < height; row++){
var y = row * rowHeight;
var thisRow = [];
for (var k = 0; (k - 1) * half < width; k++){
var x = (k - 1) * half;
var color = pickColor(thisRow[k - 1], lastRow[k]);
var points;
if ((k + row) % 2 == 0){
points = [x, y, x + triangleSize, y, x + half, y + rowHeight];
} else {
points = [x, y + rowHeight, x + triangleSize, y + rowHeight, x + half, y];
}
// A hairline stroke in the same colour hides anti-aliasing seams.
s.polygon(points).attr({fill: color, stroke: color, strokeWidth: 1});
thisRow.push(color);
}
lastRow = thisRow;
}
Copyright © 2014–2026 Kevin Marsh. All rights reserved. Questions? Comments? hello@variart.io