xxxxxxxxxx
//The image need a black background
var img, taille=10, points=[], ecart=100;
function preload(){
img = loadImage("test.jpg");
}
function setup() {
createCanvas(windowWidth, windowHeight);
background(100);
img.loadPixels();
img.resize(width, height);
class Point{
constructor(x,y){
this.x = x;
this.y = y;
this.velx = taille;
}
affiche(){
push();
let v = img.get(this.x,this.y);
let b = (v[0]+v[1]+v[2])/3;
fill(255,255,255,30+b);
noStroke();
ellipse(this.x, this.y, taille, taille);
pop();
}
moov(){
let v = img.get(this.x,this.y);
let b = (v[0]+v[1]+v[2])/3/30;
this.x += this.velx-b;
}
reset(){
if(this.x >= img.width){
this.x = 0;
}
}
}
for(var x = 0; x<img.width/ecart; x++){
for(var y = 0; y < img.height/taille; y++){
points.push(new Point(x*ecart,y*taille))
}
}
}
function draw(){
background(0,0,0,10);
for(var n in points){
points[n].affiche();
points[n].moov();
points[n].reset();
}
}