xxxxxxxxxx
87
// Meander Lines by Steve's Makerspace
// https://www.youtube.com/@StevesMakerspace
let startAng, startAng2, startAng3, ang;
let rgtAng = 1.57;
let turn = 0.2;
function setup() {
createCanvas(windowWidth, windowWidth/800*600);
blankSpots();
background(80);
wid = width;
hgt = height;
frame = width * 0.05;
angVary = PI * 0.02;
edgeBuff = hgt * 0.08;
lineLength = hgt * 0.001;
stroke(255);
makeLines(10000,15); // number, strokeWeight scale
stroke(220,0,0);
makeLines(30000,5);
stroke(0,0,220);
makeLines(30000,1);
//image(cnv2,0,0);
}
function blankSpots(){
cnv2 = createGraphics(width, height);
cnv2.background(0);
cnv2.rectMode(CENTER);
cnv2.rect(width / 2, height / 2, height*0.9);
}
function makeLines(numb,swScale) {
newLine();
for (i = 0; i < numb; i++) {
ang = ang + random(-angVary, angVary);
x = lineLength * sin(ang) + x;
y = lineLength * cos(ang) + y;
edges();
sw += width * random(-0.00003, 0.00003);
sw = constrain(sw, width * 0.0001, width * 0.009);
strokeWeight(sw*swScale);
line(prevX, prevY, x, y);
prevX = x;
prevY = y;
if (random(1000) < 1) {
newLine();
}
}
}
function newLine() {
//random start ang
newXY();
//ang = random(PI * 2);
ang = PI*0.5;
if (random(2)<1){
ang = PI*0.25;}
else {
ang = PI*0.75;
}
sw = width * random(0.0002, 0.005);
prevX = x;
prevY = y;
}
function newXY() {
cnt = 0;
while (cnt < 40) {
x = round(random(frame, wid - frame));
y = round(random(frame, hgt - frame));
check = cnv2.get(x, y);
if (check[0] != 0) {
break;
}
cnt++;
}
}
function edges() {
front = cnv2.get(edgeBuff * sin(ang) + x, edgeBuff * cos(ang) + y);
if (front[0] == 0) {
ang += turn;
}
}