xxxxxxxxxx
50
/*
Based on Daniel Shiffman's implementation of code for the Commodore 64:
10 PRINT CHR$(205.5+RND(1)); : GOTO 10
Coding Train Coding Challenge #76: 10PRINT in p5.js
https://www.youtube.com/watch?v=bEyTZ5ZZxZs
*/
let x, y, spacing;
function setup() {
createCanvas(windowWidth, windowHeight);
stroke(255);
strokeWeight(2);
initialize();
}
function initialize() {
background(0);
x = 0;
y = 0;
spacing = min(width / 20, height / 20); //determines the smallest number within the min() function and seperates the canvas into that many sections
}
function draw() {
if (random(1) > 0.5) { //develops a function that occurs 50% of the time for one part and 50% of the time for the second part
line(x, y, x + spacing, y + spacing); //draws a line that starts at the original x and y and ends at the x and y plus the spacing variable
} else {
line(x, y + spacing, x + spacing, y);// draws a line at the original x coordinate, the y coordinate plus the spacing, and ends at the x coordinate plus the spacing and the original y coordinate
}
x += spacing; //moves the x position to the next sextion of the screen based on the spacing
if (x > width) { //once the x position moves to the end of the screen, this function runs
x = 100;
y += spacing;
} //once the lines get to the right end of the screen, the lines start again in the next row determined on the spacing
if (y > height) {
background(0);
x = 0;
y = 0;
} //once the lines reach the bottom of the screen, the design starts over
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
initialize(); //if the window is resized then the x and y positions are reset and the design starts again
}