let img;
let cnv;
let points =[]
let mult = 0.008
var vScale = 1;
function preload(){
img = loadImage("assets/22.jpg");
}
function setup() {
cnv = createCanvas(img.width, img.height);
//print img
let newCanvasX = (windowWidth-img.width/20)/2;
let newCanvasY = (windowHeight-img.height/20)/5;
cnv.position(newCanvasX,newCanvasY);
angleMode(DEGREES)
noiseDetail(1);
//access the pixel information of the image
var 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){
var p = createVector(col, row);
points.push(p);
}
}
}
function draw() {
for (var i = 0; i < points.length; i++) {
points[i].update();
points[i].show();
}
}
function Points(x,y){
this.points.x = x;
this.points.y = y;
this.update = function(){
this.points.x += random(-10,10);
this.points.y += random(-10,10);
this.x = constrain(this.x,0,width);
this.y = constrain(this.y,0,height);
}
this.show = function(){
//noStroke();
var px = floor(this.x / vScale);
var py = floor(this.y / vScale);
var col = img.get(px,py);
fill(col[0],col[1],col[2]);
ellipse(this.x,this.y,1,1);
}
}
This is my code, I got an error that said points[i].update is not a function… I don’t understand cos it works well in my other sketch, maybe there is a shared function name, I changed this.x into this. points. x, doesn’t work. I don’t know how to deal with it, please help me!