xxxxxxxxxx
43
/* Adapted from Daniel Shiffman,
Naturn of Code
https://github.com/nature-of-code/noc-examples-p5.js/tree/master/chp04_systems/NOC_4_07_ParticleSystemForcesRepeller
*/
let repeller;
let ps = [];
let H = 40;
function setup() {
createCanvas(windowWidth, windowHeight);
colorMode(HSB, 360, 100, 100, 100);
frameRate(20);
background(H, 50, random(70,100))
ps = new ParticleSystem(createVector(width/2, 0));
repeller = new Repeller();
}
function draw() {
background(H, 50, random(70,100), 5);
// Hue change
H += 1;
if (H >= 70){
H = 50;
}
if (frameCount%5==0){
push();
//scale(random(.4,.5));
translate(0, height*.4)
grid();
pop();
}
ps.addParticle(random(width), height*.2);
// Apply gravity force to all Particles
let gravity = createVector(0, random(0.2));
ps.applyForce(gravity);
ps.applyRepeller(repeller);
repeller.run();
ps.run();
}