xxxxxxxxxx
116
var particles = [];
var path;
const MAXSPEED = 1;
const MAXFORCE = 1;
const dt = 1;
var numsubstep = 2;
var spawnradius = 50;
const population = 10;
//sliders and such
let arriveSlider = 0.04;
let fleeSlider = 0.16;
function setup() {
wid = floor(windowWidth);
hit = floor(windowHeight);
createCanvas(wid, hit);
// for(var i = 0; i < population; i++){
// append(particles, new Particle(random(wid),random(hit/2,hit)));
// }
//random shape path
path = new Path(50);
path.addPoint(200,100);
path.addPoint(wid-200,100);
path.addPoint(wid-200,hit-400);
path.addPoint(wid/2,hit-500);
path.addPoint(200,hit-400);
path.addPoint(200,100);
//"bridge" paths
// path = new Path(100);
// path.addPoint(200,100);
// path.addPoint(200,300);
// Create a slider with min, max, and starting value
arriveSlider = createSlider(0, 1, arriveSlider, 0.01);
arriveSlider.position(10, height + 10);
arriveSlider.style('width', '380px');
fleeSlider = createSlider(0, 1, fleeSlider, 0.01);
fleeSlider.position(10, height + 50);
fleeSlider.style('width', '380px');
}
//Add particles
// function mouseDragged(){
// append(particles, new Particle(mouseX,mouseY));
// }
//Add particles is spawn radius
function mousePressed(){
for(var i = 0; i < population; i++){
append(particles, new Particle(random(mouseX-10,mouseX+10),random(mouseY-10,mouseY+10)));
}
}
function draw() {
background(100);
path.display();
strokeWeight(1);
for(i = 0; i < particles.length;i++){
particle = particles[i];
//substepping
for(j = 1; j <= numsubstep; j++){
var distance = particle.predict(path);
if (distance > path.radius/2){
particle.findTarget(particle.normalPoint);
}
particle.behaviors(particles);
particle.update();
}
particle.show();
}
//Stats
let fps = frameRate();
if(fps <= 10){
console.log("Under 10 fps with "+particles.length );
}
fill(0);
stroke(0);
text("FPS: " + fps.toFixed(2) + " | Particles: " + particles.length, 10, height - 20);
}
///
function Grid(size){
this.size = size;
}
Grid.prototype.get = function(x,y){
//return all particles within the the x,y grid of size w,h
}