xxxxxxxxxx
let patchSize;
let patchs = 8;
let warpL = 75;
let weftL = 50;
function setup() {
createCanvas(800, 800);
noLoop();
patchSize = width / patchs;
//strokeWeight(1);
}
function draw() {
background(220);
//noiseSeed(0);
for (let i = 0; i < patchs; i++) {
for (let j = 0; j < patchs; j++) {
let dim = patchSize * (0.75 + noise(i / patchs, j / patchs) / 2);
drawWeave(i * patchSize, j * patchSize, dim);
strokeWeight(0.01*j*i);
}
}
}
function drawWeave(x, y, dim) {
push();
translate(x, y);
for (let i = 0; i <= warpL; i++) {
let warpX = i / warpL * dim;
// Draw the "warp" (vertical) lines
stroke(random(0,40));
line(warpX, 0, warpX, dim);
// Draw the "weft" (horizontal) lines, alternating over and under the warp lines
for (let j = 0; j <= weftL; j++) {
let weftY = j / weftL * dim;
stroke(random(220,255));
// Add a slight "napping" effect at the intersections
let napOff = sin(radians(j - i)) * random(1.5,3);
if (j % 2 === 0) {
line(0, weftY + napOff, dim, weftY + napOff);
} else {
if (warpX - napOff > 0) {
line(0, weftY + napOff, warpX - napOff, weftY + napOff);
}
if (warpX + napOff < dim) {
line(warpX + napOff, weftY + napOff, dim, weftY + napOff);
}
}
}
}
pop();
}
function keyTyped() {
if (key === "s" || key === "S") {
saveCanvas("ombre-textile_c-" + floor(random(100)), "png");
}
}