Current File : /home/jeshor13/11bsouth.com/DeadFlowers/Petal.js |
var Petal = function(age, hueKey, location, type) {
this.position = location.copy();
this.velocity = createVector();
this.acceleration = createVector();
this.color = hueKey
this.mass = random(3, 5)
this.type = type
this.age = age
this.lifeSpan = constrain(randomGaussian(90000, 30000), 2000, 150000)
this.maxspeed = 1;
Petal.prototype.applyForce = function(f) { // f is a variable, which just points to a space in memorey
this.acceleration.add(p5.Vector.div(f, this.mass)); // conserves gravity and makes sure its the same
}
Petal.prototype.update = function() {
this.position.add(this.velocity);
this.velocity.add(this.acceleration);
this.acceleration.mult(0);
if (this.velocity > 3) {
this.velocity = 3
};
}
Petal.prototype.render = function() {
noStroke()
if (this.type == 1) {
fill(this.color, 100, 100 * (1 - ((millis() - this.age) / this.lifeSpan)), .8)
}
if (this.type == 2) {
fill(this.color + 30, 100, 100 * (1 - ((millis() - this.age) / this.lifeSpan)), .8)
}
if (this.type == 3) {
fill(this.color - 30, 100, 100 * (1 - ((millis() - this.age) / this.lifeSpan)), .8)
}
ellipse(this.position.x, this.position.y, this.mass, this.mass);
}
Petal.prototype.isDead = function() {
return ((1 - ((millis() - this.age) / this.lifeSpan)) < 0.2)
}
// Petal.prototype.follow = function(flow) {
// // What is the vector at that spot in the flow field?
// var desired = flow.lookup(this.position);
// // Scale it up by maxspeed
// desired.mult(this.maxspeed);
// // Steering is desired minus velocity
// var steer = p5.Vector.sub(desired, this.velocity);
// steer.limit(this.maxforce); // Limit to maximum steering force
// this.applyForce(steer);
// }
// // Bounce off window
// Petal.prototype.checkEdges = function() {
// if (this.position.y > height - (this.dirtHeight + 2.5)) {
// this.velocity.y *= -0.9;
// this.position.y = height;
// };
// if (this.position.y < 0) {
// this.velocity.y *= -0.9;
// this.position.y = 0;
// };
// if (this.velocity > 10) {
// this.velocity = 10
// };
// };
}