xxxxxxxxxx
124
let grid, particles;
let vaporwave = ["#ff71ce", "#01cdfe", "#05ffa1", "#b967ff", "#fffb96"];
const Y_AXIS = 1;
const X_AXIS = 2;
let _scale;
function setup() {
createCanvas(1920, 1280);
noiseDetail(random(2,14), random(0.25,0.85));
_scale = width / 1000;
grid = [];
for (let y = 0; y < height; y++) {
grid[y] = [];
for (let x = 0; x < width; x++) {
let n = noise(x * 0.01, y * 0.01);
grid[y][x] = Math.floor(map(n, 0.0, 1.0, 0, 9));
}
}
// 0 1 2
// 3 4 5
// 6 7 8
particles = [];
for (let _ = 0; _ < 1500; _++) {
let c= color(20);
if (random() > 0.9) c = color(random(vaporwave));
particles.push({ x: random(width - 1), y: random(height - 1), c:c });
}
background(220);
// setGradient(0,0,width,height,color(random(vaporwave)), color(random(vaporwave)), Y_AXIS);
drawingContext.shadowOffsetX = -2*_scale;//5;
drawingContext.shadowOffsetY = 2*_scale;//-5;
drawingContext.shadowBlur = 4*_scale;
drawingContext.shadowColor = color(20);//'black';
noStroke();
}
let paused = false;
function draw() {
if (!paused) {
fill(20);
// drawingContext.shadowOffsetX = 5;
// drawingContext.shadowOffsetY = -5;
// drawingContext.shadowBlur = 10;
// drawingContext.shadowColor = 'black';
for (let p of particles) {
fill(p.c);
square(p.x, p.y, 2*_scale);
let a = grid[int(p.y)][int(p.x)];
switch (a) {
case 0:
p.x--;
p.y--;
break;
case 1:
p.y--;
break;
case 2:
p.x++;
p.y--;
break;
case 3:
p.x--;
break;
case 4:
redo(p);
break;
case 5:
p.x++;
break;
case 6:
p.x--;
p.y++;
break;
case 7:
p.y++;
break;
case 8:
p.x++;
p.y++;
break;
}
if (p.x < 0 || p.x > width - 1 || p.y < 0 || p.y > height - 1) redo(p);
}
}
}
function keypressed() {
if (key == ' ') paused = !paused;
}
function redo(p) {
p.x = random(width - 1);
p.y = random(height - 1);
}
function setGradient(x, y, w, h, c1, c2, axis) {
noFill();
if (axis === Y_AXIS) {
// Top to bottom gradient
for (let i = y; i <= y + h; i++) {
let inter = map(i, y, y + h, 0, 1);
let c = lerpColor(c1, c2, inter);
stroke(c);
line(x, i, x + w, i);
}
} else if (axis === X_AXIS) {
// Left to right gradient
for (let i = x; i <= x + w; i++) {
let inter = map(i, x, x + w, 0, 1);
let c = lerpColor(c1, c2, inter);
stroke(c);
line(i, y, i, y + h);
}
}
}