xxxxxxxxxx
int num = 10;
Particle [] floaterS = new Particle [num];
float hitDistance = 50;
void setup() {
size( 600, 800);
for (int i = 0; i < num; i++) {
floaterS[i] = new Particle(random(width), random(height));
floaterS[i].gravity = new PVector(0, -.1);
floaterS[i].fillColor = color(0, 255, 255);
}
}
void draw() {
background(0);
hitBox();
for (int i = 0; i < num; i++) {
floaterS[i].update();
floaterS[i].display();
}
}
void hitBox () {
//draw hitbox around the particle
fill(247, 17, 144, 80);
strokeWeight(6);
stroke(247, 17, 144);
for (int i = 0; i < num; i++) {
ellipse(floaterS[i].pos.x, floaterS[i].pos.y, hitDistance, hitDistance);
}
}
void mousePressed() {
//on mouse click, add force to object
for (int i = 0; i < num; i++ ) {
if ( dist(mouseX, mouseY, floaterS[i].pos.x, floaterS[i].pos.y) < hitDistance+10) {
floaterS[i].addForce( 0, 10 );
}
}
//// on mouse click, move away from the mouse
//for (int i = 0; i < num; i++) {
// if (dist (mouseX, mouseY, floaterS[i].pos.x, floaterS[i].pos.y) < hitDistance+10) {
// floaterS[i].addForce((floaterS[i].pos.x - mouseX)*0.03, (floaterS[i].pos.y - mouseY)*0.03);
// }
//}
}