xxxxxxxxxx
65
let x1;
let y1;
let x0;
let y0;
let sclX = 30;
let sclY = 10;
let lenW;
let lenH;
function setup() {
createCanvas(600, 200);
//background(220);
x1 = 0.9 * width;
y1 = 0.9 * height;
x0 = 0.1 * width;
y0 = 0.1 * height;
w = x1 - x0;
h = y1 - y0;
lenW = w / sclX;
lenH = h / sclY;
strokeWeight(4);
noFill();
//fill(200,210,180);
rect(x0, y0, w, h);
strokeWeight(2);
vertStitch(0.5);
horiStitch(0.5);
save();
}
function draw() {
noLoop();
}
function vertStitch(p) {
push();
translate(x0,y0);
for (let x = lenW; x < w; x += lenW) {
let begin = 0;
if (random() < p) {
begin = 1;
}
for (let y = begin * lenH; y < h; y += 2 * lenH) {
line(x, y, x, y + lenH);
}
}
pop();
}
function horiStitch(p) {
push();
translate(x0,y0);
for (let y = lenH; y < h; y += lenH) {
let begin = 0;
if (random() < p) {
begin = 1;
}
for (let x = begin * lenW; x < w; x += 2 * lenW) {
line(x, y, x + lenW, y);
}
}
pop();
}