Click to change the weave
Source ยท src/sketches/kambli-loom.js
// Kambli loom โ a weave draft woven row by row: black Deccani wool with natural-white
// stripes, cycling plain, twill and basket weaves. Click to change the weave.
const WEAVES = [
['plain', (x, y) => (x + y) % 2 === 0],
['twill 2/2', (x, y) => (x + y) % 4 < 2],
['twill 3/3', (x, y) => (x - y + 600) % 6 < 3],
['basket 2ร2', (x, y) => (Math.floor(x / 2) + Math.floor(y / 2)) % 2 === 0],
];
export default function kambliLoom(p, el) {
let W, H, cell, cols, rows, row = 0, w = 0, pause = 0;
const restart = () => { cell = Math.max(6, Math.round(W / 70)); cols = Math.ceil(W / cell); rows = Math.ceil(H / cell); row = 0; p.background(246, 240, 228); };
const weftColour = y => (Math.floor(y / 9) % 8 === 4 ? [232, 224, 208] : [28, 24, 22]);
const warpColour = x => (Math.floor(x / 14) % 10 === 5 ? [222, 214, 196] : [42, 36, 32]);
p.setup = () => { W = el.clientWidth; H = el.clientHeight; p.createCanvas(W, H); restart(); };
p.draw = () => {
const [name, up] = WEAVES[w];
p.noStroke();
for (let n = 0; n < 2 && row < rows; n++, row++) {
for (let x = 0; x < cols; x++) {
const over = up(x, row);
const c = over ? warpColour(x) : weftColour(row);
p.fill(c[0], c[1], c[2]); p.rect(x * cell, row * cell, cell, cell);
p.fill(0, 0, 0, over ? 30 : 14); p.rect(x * cell, row * cell + cell * 0.72, cell, cell * 0.28); // thread shadow
}
}
if (row >= rows && ++pause > 150) { pause = 0; w = (w + 1) % WEAVES.length; restart(); }
// label
p.fill(246, 240, 228); p.rect(10, H - 32, 210, 22, 3);
p.fill(40); p.textSize(12); p.textFont('monospace'); p.text(`${name} ยท click to change`, 18, H - 17);
};
p.mousePressed = () => {
if (p.mouseX >= 0 && p.mouseX <= W && p.mouseY >= 0 && p.mouseY <= H) { w = (w + 1) % WEAVES.length; restart(); }
};
p.windowResized = () => { W = el.clientWidth; H = el.clientHeight; p.resizeCanvas(W, H); restart(); };
}