xxxxxxxxxx
67
let y = 0;
let bands = [];
const minWidth = 10;
const maxWidth = 150;
const maxChange = 15;
function setup() {
createCanvas(400, 400);
colorMode(HSB);
initBands();
}
function draw() {
let x = 0;
for(let b = 0; b < bands.length; b ++) {
const band = bands[b];
for(let i = 0; i < band.x; i ++) {
stroke(band.y, 255, 255);
line(x + i, y, x + i, height);
}
x += band.x;
}
modifyBands();
y ++;
}
function modifyBands() {
let x = 0;
bands = bands.filter(band => {
band.x += random(-maxChange, maxChange);
if(band.x <= 0) {
return false;
}
x += band.x;
return true;
});
while(x < width) {
const band = newBand();
x += band.x;
bands.push(band);
}
}
function initBands() {
bands = [];
let x = 0;
while(x < width) {
const band = newBand();
bands.push(band);
x += band.x;
}
}
function newBand() {
let w = random(minWidth, maxWidth);
let h = random(255);
return createVector(w, h);
}