xxxxxxxxxx
62
let pixelsPerInch = 300;
let widthInInches = 40;
let heightInInches = 4;
let boxSizeInInches = 1; // width between imaginary grid lines
let lineWidthInInches = .1; // width of the actual drawn black lines
let saveImage = false; // set to true before you run when you want to save
/*
let strokeWidth = 1;
let boxSize = 100;
let screenWidth = 300;
let screenHeight = 300;
*/
let progress = 0;
function setup() {
console.log("Process started. Generating image.");
screenWidth = pixelsPerInch * widthInInches;
screenHeight = pixelsPerInch * heightInInches;
boxSize = boxSizeInInches * pixelsPerInch;
strokeWidth = lineWidthInInches * pixelsPerInch;
let BLACK = color(0);
let WHITE = color(255);
createCanvas(screenWidth, screenHeight);
background(WHITE);
strokeWeight(strokeWidth);
stroke(BLACK);
for (i = 0; i < screenWidth; i += boxSize) {
for (j = 0; j < screenHeight; j += boxSize) {
theLine(int(random(4)));
}
progress = 100 * (i*j) / (screenWidth * screenHeight);
console.log(progress + "% completed");
}
if(saveImage)
saveCanvas('image','png');
}
function draw() {}
function theLine(dir) {
switch (dir) {
case 0:
line(i + boxSize / 2, j, i + boxSize / 2, j + boxSize);
break;
case 1:
line(i, j, i + boxSize, j + boxSize);
break;
case 2:
line(i + boxSize, j, i, j + boxSize);
break;
case 3:
line(i, j + boxSize / 2, i + boxSize, j + boxSize / 2);
break;
}
}