xxxxxxxxxx
let spots;
let img;
let t = 0;
let vel = 0.005;
const nodeNum =10000;
const nodes = [];
function preload() {
img = loadImage("2024.png");
}
function setup() {
createCanvas(800, 800);
img.loadPixels();
img.resize(800, 800);
spots = [];
for (let x = 0; x < img.width; x++) {
for (let y = 0; y < img.height; y++) {
let index = x + y * img.width;
let c = img.pixels[index * 4];
let b = brightness([c]);
if (b > 1) {
spots.push(createVector(x, y));
}
}
}
frameRate(30)
}
function draw() {
randomSeed(1)
background(255);
noFill();
let faderX = easeInOutBack(t);
strokeWeight(2);
for (let i = 0; i < nodeNum; i++) {
let r = int(random(0, spots.length));
let spot = spots[r];
let randomX = random(width);
let randomY = random(height);
let x = lerp(randomX, spot.x, faderX);
let y = lerp(randomY, spot.y, faderX);
point(x, y);
}
if(t < 1 && frameCount > 60)
t += vel;
if(t >= 1 || t <= 0) vel *= -1;
}
function easeInOutBack(t) {
const c1 = 1.70158;
const c2 = c1 * 1.525;
return t < 0.5 ? (pow(2 * t, 2) * ((c2 + 1) * 2 * t - c2)) / 2 : (pow(2 * t - 2, 2) * ((c2 + 1) * (t * 2 - 2) + c2) + 2) / 2;
}