xxxxxxxxxx
60
let particles = [];
let amount = 100;
let edgeBuffer = -2;
let gridSize = 2;
function outOfBorder(x,y,size){
if(x > width + edgeBuffer || x < -edgeBuffer || y > height + edgeBuffer || y < - edgeBuffer){
return true
}else{
return false
}
}
function setup() {
createCanvas(400, 400);
//init the grid
initGrid(gridSize,gridSize);
for(let i = 0; i < amount; i++){
let x = random(width);
let y = random(height);
let cell = locateCell(createVector(x,y));
let p = new particle(x,y,cell);
append(particles,p);
}
}
function draw() {
background(220);
//draw the grid
//drawGrid();
for(let particle of particles){
particle.update();
particle.show();
//find cell in grid
let cell = locateCell(particle.pos);
if(particle.curCell != cell){
particle.updateCell(cell);
}
}
//fps
textSize(15);
stroke(255);
fill(0);
let fps = frameRate().toFixed(2);
text("FPS: "+fps,width-90,20);
}