xxxxxxxxxx
54
/*Reference: Coding Train Challenge #24*/
var inc = 0.1;
var length = 10;
var cols;
var rows;
var ioff = 0;
var joff = 0;
var koff = 0;
function setup() {
createCanvas(720, 720);
strokeWeight(0.5);
cols = floor(width / length);
rows = floor(height / length);
refresh = true;
// noLoop();
}
function draw() {
if (refresh) {
background(255, 250, 240);
for (var i = 0; i < rows; i++) {
joff = 0;
for (var j = 0; j < cols; j++) {
//generate smooth noise variable for hole
var a = noise(joff, ioff);
//generate vector lines
var v = p5.Vector.fromAngle(random(PI));
joff += inc;
//decides where to put holes
if (a < 0.3) {
erase = true;
} else {
erase = false;
}
//draw line if not called for hole
if (!erase) {
push(); //stores line
translate(j * length, i * length);
rotate(v.heading(PI));
line(length, 0, -length / 2, 0);
pop(); //erases line
}
}
ioff += inc;
}
}
refresh = false;
}
function mousePressed() {
refresh = true;
}