xxxxxxxxxx
/******************
Code by Vamoss
Original code link:
https://openprocessing.org/sketch/1116518
Author links:
http://vamoss.com.br
http://twitter.com/vamoss
http://github.com/vamoss
******************/
var positions = [];
const GRID_SIZE = 50;
function setup() {
createCanvas(windowWidth, windowHeight);
background("#1a0633");
colors = [color("#1a0633"), color("#1a0633"), color("#581845"), color("#900C3F"), color("#C70039"), color("#FF5733"), color("#FFC30F"), color("#581845")];
for(var i = 0; i < colors.length/2; i++){
var position = {
current: {
x: round(width / 2 / GRID_SIZE) * GRID_SIZE,
y: round(height / 2 / GRID_SIZE) * GRID_SIZE
},
previous: {
x: round(width / 2 / GRID_SIZE) * GRID_SIZE,
y: round(height / 2 / GRID_SIZE) * GRID_SIZE
}
}
positions.push(position);
}
}
function draw() {
positions.forEach((position, index) => {
for(let i = 0; i < 3; i++){
position.current.x += round(random(-1, 1)) * GRID_SIZE;
position.current.y += round(random(-1, 1)) * GRID_SIZE;
position.current.x = constrain(position.current.x, GRID_SIZE, round(width / GRID_SIZE) * GRID_SIZE - GRID_SIZE);
position.current.y = constrain(position.current.y, GRID_SIZE, round(height / GRID_SIZE) * GRID_SIZE - GRID_SIZE);
if(random() < 0.1){
stroke(colors[(index*2+0)%colors.length]);
strokeWeight(GRID_SIZE);
line(position.current.x, position.current.y, position.previous.x, position.previous.y);
stroke(colors[(index*2+1)%colors.length]);
strokeWeight(2);
line(position.current.x, position.current.y, position.previous.x, position.previous.y);
}
position.previous.x = position.current.x;
position.previous.y = position.current.y;
}
});
}