Current File : /home/jeshor13/11bsouth.com/DeadFlowers/Flower.js
var Flower = function(origin, timeCreated) {
  this.origin = origin.copy();
  this.KeyHueValue = round(random(31, 329))
  this.petals = [];
  //this.stems = [];
  this.age = timeCreated
  this.drawFlower = true
  this.angle = 0
  this.k = 3;
  this.cycles = random(QUARTER_PI, HALF_PI)


  this.update = function(flowerID) {
    this.angle += .02
    if (this.drawFlower == true) {
      for (var i = 1; i < 4; i++) {
        this.location = createVector((100 * (cos(this.k * (i) * this.angle + this.cycles) * cos(this.angle)) + 30 * (noise(this.angle + 500) - .5) + this.origin.x), (100 * (cos(this.k * (i) * this.angle + this.cycles) * sin(this.angle)) + 30 * (noise(this.angle) - .5) + this.origin.y))
        this.petals.push(new Petal(this.age, this.KeyHueValue, this.location, i));
      }
      if (this.petals.length > 1000) {
        this.drawFlower = false
      }
    }
    for (var i = 0; i < this.petals.length; i++) {
      this.petals[i].update();
      this.petals[i].render();
      if (this.petals[i].isDead() == true) {
        var gravity = createVector(0, -0.06 * this.petals[i].mass);
        this.petals[i].applyForce(gravity); // ADDS THE GRAVITY FORCE
        this.petals[i].applyForce(wind);
        //this.petals[i].follow(flowfield);
        if (random(6) > frameRate() || this.petals[i].position.y > height || this.petals[i].position.y < 0 || this.petals[i].position.x > width || this.petals[i].position.x < 0) {
          this.petals.splice(i, 1)
        }
      }
    }
  }
}