xxxxxxxxxx
57
let img;
let points = [];
let mult = 0.008;
var vScale = 1;
var density;
function preload() {
img = loadImage("22.jpg");
createCanvas(img.width, img.height);
}
function setup() {
noStroke();
angleMode(DEGREES);
noiseDetail(1);
//access the pixel information of the image
density = 10;
var space = img.width / density;
for (let col = 0; col < img.width; col += space) {
for (let row = 0; row < img.height; row += space) {
points.push(new Point(col, row));
}
}
}
function draw() {
for (var i = 0; i < points.length; i++) {
points[i].update();
points[i].show();
}
}
function Point(x, y) {
this.point = {
x: x,
y: y,
};
this.update = function () {
this.point.x += random(-10, 10);
this.point.y += random(-10, 10);
this.point.x = constrain(this.point.x, 0, img.width);
this.point.y = constrain(this.point.y, 0, img.height);
};
this.show = function () {
//noStroke();
var px = floor(this.point.x / vScale);
var py = floor(this.point.y / vScale);
var col = img.get(px, py);
fill(col[0], col[1], col[2], col[3]);
ellipse(this.point.x, this.point.y, 4, 4);
};
}