xxxxxxxxxx
51
/*
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);
}
function draw() {
if (random(1) > 0.5) {
line(x, y, x + spacing, y + spacing);
} else {
line(x, y + spacing, x + spacing, y);
}
x += spacing;
if (x > width) {
x = 0;
y += spacing;
}
if (y > height) {
background(0);
x = 0;
y = 0;
}
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
initialize();
}