01 - Grid Primitives

Testing nested loops, grid alignment, and drawing basic shapes on A5.

← Back to Portfolio

Core Algorithm: drawCell

This function takes each individual grid cell and populates it with randomly scaling, nested primitives algorithmically.

function drawCell(x, y, w, h) {
    push();
    translate(x + w / 2, y + h / 2);

    let padding = 5;
    let maxDim = Math.min(w, h) - padding * 2;

    // Determine primitive type and nest depth
    let rType = 1;
    let steps = floor(random(3, 8));

    for (let i = 0; i < steps; i++) {
        let size = map(i, 0, steps - 1, maxDim, maxDim * 0.1);
        if (size <= 0) continue;

        if (rType === 0) {
            circle(0, 0, size);
        } else if (rType === 1) {
            rectMode(CENTER);
            rect(0, 0, size, size);
        }
    }
    pop();
}