xxxxxxxxxx
83
// Daniel Shiffman
// http://codingtra.in
// http://patreon.com/codingtrain
// 10PRINT
// https://www.youtube.com/watch?v=bEyTZ5ZZxZs
let x = 0;
let y = 0;
let spacing;
let groundCol;
let wallCol;
let finished = false;
function setup() {
noiseSeed(random(1, 3));
spacing = random(4, 30);
frameRate(80);
createCanvas(windowWidth, windowHeight);
background(0);
groundCol = color(159, 103, 59);
wallCol = color(104, 67, 39);
}
function draw() {
noStroke();
for (let i = 0; i < 100000; i++) {
drawSegment();
moveSegment(spacing);
}
noLoop();
}
function drawSegment() {
if (noise(x * y * 2) > noise(x * y)) {
backslash(x, y, spacing);
} else {
forwardslash(x, y, spacing);
}
}
function moveSegment(spacing) {
x = x + spacing;
if (x > width) {
x = 0;
y = y + spacing;
if (y > height) {
y = 0;
}
}
}
function backslash(x, y, spacing) {
noStroke();
fill(wallCol);
rect(x, y, spacing, spacing);
//stroke(255);
line(x, y, x + spacing, y + spacing);
}
function forwardslash(x, y, spacing) {
noStroke();
fill(groundCol);
rect(x, y, spacing, spacing);
//line(x, y + spacing, x + spacing, y);
}
function keyPressed() {
noiseSeed(random(1, 3));
spacing = random(4, 30);
for (let i = 0; i < 100000; i++) {
drawSegment();
moveSegment(spacing);
}
}