xxxxxxxxxx
let particles = [];
function preload() {
// preload() runs once
img = loadImage('jrx.png');
}
function setup() {
createCanvas(windowWidth, windowHeight);
background(0);
img.loadPixels();
for(let i =0; i<img.width;i+=5){
for(let h = 0 ; h < img.height ; h+=5){
// 取樣
let c = img.get(i, h);
particles.push({
x: i,
y: h,
clr: color(c)
})
}
}
}
function draw() {
noStroke();
// 噪聲+流動
background(0,0.01);
for(let i = 0 ; i < particles.length; i++){
let p = particles[i];
fill(p.clr);
ellipse(p.x , p.y, 5);
p.x += (noise(p.x/200,p.y/200,1000)-0.5)*10;
p.y += (noise(p.x/200,p.y/200,100000)-0.5)*10;
}
// for(let i =0; i<width;i+=20){
// for(let h = 0 ; h < height ; h+=20){
// // noise
// fill(noise(i/100,h/100,frameCount/100)*300,80,80);
// rect(i,h,30,20);
// }
// }
// ellipse(mouseX, mouseY, 20, 20);
}