xxxxxxxxxx
66
class Drop {
constructor(x, y, mass, color = 100, end, force = 0) {
this.color = color;
this.pos = createVector(x, y);
this.vel = createVector(0, 10);
this.wind = createVector(0, 0);
this.xoff = 100
this.n = 0
this.mass = mass
this.end1 = end
force = this.force
}
display() {
noStroke()
fill(this.pos.y / 3, this.pos.y / 2, this.color)
if (this.overlapping) {
fill(0, 255, 0);
}
this.xoff = this.xoff + 0.01
this.n = noise(this.xoff) * .6
this.end = createVector(this.end1 + random(-200, 200), 0);
this.acc = p5.Vector.sub(this.end, this.pos);
this.acc.setMag(1)
this.vel.limit(1);
this.acc.div(this.mass)
this.vel.add(this.acc);
this.pos.add(this.vel)
this.vel.y = this.vel.y + this.n;
ellipse(this.pos.x, this.pos.y, 10 + this.pos.y / 10, 10 + this.pos.y / 10)
if (this.pos.y < 0) {
this.pos.y = 5
this.friction()
}
}
intersects(other) {
let d = dist(this.pos.x, this.pos.y, other.pos.x, other.pos.y);
if (d < 15) {
return true;
} else {
return false;
}
}
friction() {
this.force = this.vel.copy()
this.force.normalize();
this.force.mult(-1);
let mu = 0.1
//let normal = this.mass
this.force.setMag(mu * this.mass)
this.vel.add(this.force)
}
}