xxxxxxxxxx
59
//define initial variables
let startX;
let startY;
let endX;
let endY;
let seed = 1;
//setup function init
function setup() {
//canvassize set to match window size
createCanvas(windowWidth, windowHeight);
//draw color set to white
stroke(255);
//outline width set to 2
strokeWeight(2);
}
//init draw function
function draw() {
//set background to black
background(0);
//set a constant of 1 for making random consistently output the same way every time
randomSeed(seed)
//for loop init, i set to 0, if i is less than 100 add 1 and run
for (let i = 0; i < 100; i++) {
//variable to start line at a random X and Y location from 20 to the border - 20
startX = random(20, width - 20);
startY = random(20, height - 20);
//if statement a 1/10 chance of running
if (random(10) < 1) {
//define amount to a random number between 5-20
let amount = random(5, 20);
//add amount to the endX coordinate of the line each time
endX += amount;
//add amount to the startY coordinate to create the endY coordinate
endY = startY + amount;
//9/10 chance of running
} else {
//define amount to a random number between 5-20
let amount = random(5, 20);
//add amount to the endY coordinate of the line each time
endY += amount;
//add amount to the startX coordinate to create the endX coordinate
endX = startX + amount;
}
//draw the line with these coordinates
line(startX, startY, endX, endY);
}
}
//randomize the seed of random 0-1000 if the mouse is pressed, at the moment random will be consistent in how it chooses the next number
function mousePressed() {
seed = random(1000);
}