xxxxxxxxxx
var sz; // Size of each shape
var stCl; // Stroke color
var colors = ['#FF6B6B', '#4ECDC4', '#FFE66D', '#1A535C', '#FF4E50']; // Color palette
var gap; // the gap between tiles
function setup() {
createCanvas(600, 600);
// Size of each shape in max
sz = 80;
stCl = '#000000';
// gap
gap = 4;
// Disable Loop
noLoop();
}
function draw() {
background(250, 248, 245); // smokey white
// Center pattern on the canvas
let offsetX = (width - (sz + gap) * 6) / 2;
let offsetY = (height - (sz + gap) * 6) / 2;
push();
translate(offsetX, offsetY); // Center the pattern
// Diagonal grid pattern with shifted rows
for (var j = 0; j < 6; j++) {
for (var k = 0; k < 6; k++) {
push();
translate((sz + gap) * j, (sz + gap) * k); // Grid position
drawShapes(j, k); // Pass the indices to alternate shapes
pop();
}
}
pop();
}
function drawShapes(j, k) {
// Set rect and ellipse mode for drawing shapes
rectMode(CENTER);
ellipseMode(CENTER);
// Random color from palette
let shapeColor = random(colors);
fill(shapeColor);
noStroke();
// Alternate shapes based on grid position
if ((j + k) % 2 === 0) {
// Draw concentric circles
for (var i = 0; i < 8; i++) {
let chanceFac = random(0, 1);
if (chanceFac < 0.7) {
ellipse(0, 0, sz - 8 * i, sz - 8 * i);
}
}
} else {
// Draw concentric triangles
for (var i = 0; i < 8; i++) {
let chanceFac = random(0, 1);
if (chanceFac < 0.7) {
beginShape();
vertex(-sz / 2 + 4 * i, sz / 2 - 4 * i);
vertex(sz / 2 - 4 * i, sz / 2 - 4 * i);
vertex(0, -sz / 2 + 4 * i);
endShape(CLOSE);
}
}
}
}
function keyPressed() {
if (key == 'r') {
draw();
}
if (key == 's') {
saveCanvas('test.ai');
}
}