xxxxxxxxxx
213
let vaporwave = [
(20, 20, 20),
"#ff71ce",
"#01cdfe",
"#05ffa1",
"#b967ff",
"#fffb96",
];
let pos, col, timeLeft;
function setup() {
createCanvas(1000, 1000);
background(220);
let gfx = createGraphics(width, height);
texturize(gfx, 10000);
image(gfx, 0, 0);
walkers = [];
for (let _ = 0; _ < 1000; _++) walkers.push(resetPos());
strokeWeight(5);
for (let w of walkers) {
for (let i = w.timeLeft; i >= 0; i--) {
stroke(w.col);
point(w.pos.x, w.pos.y);
newdir = random(DIRS);
w.pos.x += newdir.x * 2;
w.pos.y += newdir.y * 2;
w.timeLeft--;
if (
w.pos.x < 0 ||
w.pos.x > width - 1 ||
w.pos.y < 0 ||
w.pos.y > height - 1 ||
w.timeLeft <= 0
)
break;
}
}
dither(null)
noLoop();
console.log("done");
}
let DIRS = [
{ x: -1, y: -1 },
{ x: 0, y: -1 },
{ x: 1, y: -1 },
{ x: -1, y: 0 },
{ x: 0, y: 0 },
{ x: 1, y: 0 },
{ x: -1, y: 1 },
{ x: 0, y: 1 },
{ x: 1, y: 1 },
];
let walkers;
function resetPos() {
let w = {};
w.timeLeft = random(1000,2500);
w.pos = { x: width / 2, y: height / 2 };
// w.pos = {x: random(width-1), y: random(height-1)}
w.col = color(random(vaporwave));
console.log("hi");
return w;
}
function draw() {
/*
if (!paused) {
for (let w of walkers) {
stroke(w.col);
point(w.pos.x, w.pos.y);
newdir = random(DIRS);
w.pos.x += newdir.x;
w.pos.y += newdir.y;
w.timeLeft--;
if (
w.pos.x < 0 ||
w.pos.x > width - 1 ||
w.pos.y < 0 ||
w.pos.y > height - 1 ||
w.timeLeft <= 0
)
w = resetPos();
}
}
*/
}
let paused = false;
function keyPressed() {
if (key == " ") paused = !paused;
}
function texturize(g, density) {
for (let _ = 0; _ < density; _++) {
g.stroke(
180 - random(0, 50), //BASE_H,
180 - random(0, 50), //BASE_S - random(0, 5),
180 - random(0, 50), //BASE_B - random(0, 8),
random(10, 175)
);
x1 = random(0, width);
y1 = random(0, height);
theta = random(0, TWO_PI);
segmentLength = random(2, 5);
x2 = cos(theta) * segmentLength + x1;
y2 = sin(theta) * segmentLength + y1;
g.line(x1, y1, x2, y2);
}
}
const referenceSize = 1000;
function index(g, x, y) {
if (g == null) return (x + y * width) * 4;
else return (x + y * g.width) * 4;
}
function DivideBy255(value) {
return (value + 1 + (value >> 8)) >> 8;
}
function dither(g) {
if (g == null) {
let _scale = Math.ceil(1, map(width, 0, referenceSize, 0, 1, false));
loadPixels();
for (let y = 0; y < height - _scale; y++) {
for (let x = _scale; x < width - _scale; x++) {
let oldr = pixels[index(g, x, y)];
let oldg = pixels[index(g, x, y) + 1];
let oldb = pixels[index(g, x, y) + 2];
let newr = (DivideBy255(oldr) * 255) | 0;
let newg = (DivideBy255(oldg) * 255) | 0;
let newb = (DivideBy255(oldb) * 255) | 0;
pixels[index(g, x, y)] = newr;
pixels[index(g, x, y) + 1] = newg;
pixels[index(g, x, y) + 2] = newb;
for (let _y = 1; _y <= _scale; _y++) {
for (let _x = 1; _x <= _scale; _x++) {
pixels[index(g, x + _x, y)] += ((oldr - newr) * 7) >> 4;
pixels[index(g, x + _x, y) + 1] += ((oldr - newr) * 7) >> 4;
pixels[index(g, x + _x, y) + 2] += ((oldr - newr) * 7) >> 4;
pixels[index(g, x - _x, y + _y)] += ((oldr - newr) * 3) >> 4;
pixels[index(g, x - _x, y + _y) + 1] += ((oldr - newr) * 3) >> 4;
pixels[index(g, x - _x, y + _y) + 2] += ((oldr - newr) * 3) >> 4;
pixels[index(g, x, y + _y)] += ((oldr - newr) * 5) >> 4;
pixels[index(g, x, y + _y) + 1] += ((oldr - newr) * 5) >> 4;
pixels[index(g, x, y + _y) + 2] += ((oldr - newr) * 5) >> 4;
pixels[index(g, x + _x, y + _y)] += ((oldr - newr) * 1) >> 4;
pixels[index(g, x + _x, y + _y) + 1] += ((oldr - newr) * 1) >> 4;
pixels[index(g, x + _x, y + _y) + 2] += ((oldr - newr) * 1) >> 4;
}
}
}
}
updatePixels();
} else {
let _scale = Math.ceil(1, map(g.width, 0, referenceSize, 0, 1, false));
g.loadPixels();
for (let y = 0; y < g.height - _scale; y++) {
for (let x = _scale; x < g.width - _scale; x++) {
let oldr = g.pixels[index(g, x, y)];
let oldg = g.pixels[index(g, x, y) + 1];
let oldb = g.pixels[index(g, x, y) + 2];
let newr = (DivideBy255(oldr) * 255) | 0;
let newg = (DivideBy255(oldg) * 255) | 0;
let newb = (DivideBy255(oldb) * 255) | 0;
g.pixels[index(g, x, y)] = newr;
g.pixels[index(g, x, y) + 1] = newg;
g.pixels[index(g, x, y) + 2] = newb;
for (let _y = 1; _y <= _scale; _y++) {
for (let _x = 1; _x <= _scale; _x++) {
g.pixels[index(g, x + _x, y)] += ((oldr - newr) * 7) >> 4;
g.pixels[index(g, x + _x, y) + 1] += ((oldr - newr) * 7) >> 4;
g.pixels[index(g, x + _x, y) + 2] += ((oldr - newr) * 7) >> 4;
g.pixels[index(g, x - _x, y + _y)] += ((oldr - newr) * 3) >> 4;
g.pixels[index(g, x - _x, y + _y) + 1] += ((oldr - newr) * 3) >> 4;
g.pixels[index(g, x - _x, y + _y) + 2] += ((oldr - newr) * 3) >> 4;
g.pixels[index(g, x, y + _y)] += ((oldr - newr) * 5) >> 4;
g.pixels[index(g, x, y + _y) + 1] += ((oldr - newr) * 5) >> 4;
g.pixels[index(g, x, y + _y) + 2] += ((oldr - newr) * 5) >> 4;
g.pixels[index(g, x + _x, y + _y)] += ((oldr - newr) * 1) >> 4;
g.pixels[index(g, x + _x, y + _y) + 1] += ((oldr - newr) * 1) >> 4;
g.pixels[index(g, x + _x, y + _y) + 2] += ((oldr - newr) * 1) >> 4;
}
}
}
}
g.updatePixels();
}
}