xxxxxxxxxx
122
let gridSize = 25
function setup(){
createCanvas(500,500)
}
function draw(){
background("#789D8F")
let overunder = [];
let arrayLength = 100; // Adjust the length as needed
for (let i = 0; i < arrayLength; i++) {
overunder.push(int(random(2))); // random(2) generates a number between 0 and 2
}
let cursor = 0;
let pixelSize = width/gridSize;
let pS = pixelSize
stroke("#9FB8B0");
strokeWeight(2)
for(let i = 0; i < gridSize; i++){
for(let j = 0; j < gridSize; j++){
let ox = pS/2 + i * pS
let oy = pS/2 + j * pS
// stroke(random(0,255),random(0,255),0)
if(j < gridSize -1){
line(ox, oy,ox, oy + pS) // vertical
}
if ( i < gridSize- 1){
line(ox, oy,ox + pS, oy) // horizontal
}
// stroke(random(0,255),random(0,255),0)
}
}
let reDrawVLines = [];
let reDrawHLines = [];
noFill()
stroke("#FBFBF2");
strokeWeight(11)
let lastPoint = createVector(5 * pS, 3 * pS);
beginShape()
curveVertex(lastPoint.x, lastPoint.y)
let left2right = true;
let x,y
let vPasses = 20
for(let i = 0; i < vPasses; i++){
let hPasses = int(random(2,10))
for(let j = 0; j < hPasses; j++){
console.log(overunder[cursor])
if(left2right){
x = j * pS + lastPoint.x;
y = lastPoint.y;
if( j >= 1){
if( overunder[cursor]){
reDrawVLines.push(createVector(x,y))
}
cursor++;
}
}
else{
x = lastPoint.x - j * pS;
y = lastPoint.y;
if( j < hPasses - 1){
if(overunder[cursor]){
reDrawVLines.push(createVector(x,y))
}
cursor++;
}
}
let r = 0.5
curveVertex(x+random(-r,r), y+random(-r,r))
// circle(x,y,3)
}
lastPoint = createVector(x,y+pS)
left2right = !left2right;
if(i < vPasses -1){
if(overunder[cursor]){
reDrawHLines.push(createVector(x,y+pS))
}
cursor++
}
}
curveVertex(lastPoint.x, lastPoint.y)
endShape()
// redraw vertical lines
stroke("#9FB8B0");
strokeWeight(2)
for(let i = 0; i < reDrawVLines.length; i++){
let lx = reDrawVLines[i].x - pS/2;
let ly = reDrawVLines[i].y - pS/2;
line(lx, ly, lx, ly + pS)
}
for(let i = 0; i < reDrawHLines.length; i++){
let lx = reDrawHLines[i].x - pS/2;
let ly = reDrawHLines[i].y - pS/2;
line(lx, ly, lx + pS, ly)
}
noLoop()
}