To develop this, a function must be created to choose either 0 and 1 only (i.e. let randomNum = round(random(0, 1))). This is then used in an if() and else() statements. For instance, if the chosen number is 0, draw lines going to "this" direction, else draw lines to "that" direction. To prevent the canvas from looping continuously without using noLoop(), the P5.js function randomSeed() is used. The value in the parameters of this function can be played around with until the desired pattern is displayed. To create the pulsating effect, another if() and else() statements as well as booleans are used to determine the timing and speed of the animation.
Link to Full Codes
push();
let randomNum = round(random(0, 1)); // round(...) = Between Natural numbers of 0 and 1.
translate(transX, transY);
noFill();
stroke(random(j) * random(t, - 0.09), random(i) * random(t, -0.09), numOfSquares - j);
if (randomNum == 0) {
line(0, 0, squareSize, squareSize);
} else {
line(0, squareSize, squareSize, 0);
}
pop();