forked from ayush-seth/fractal-tree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flower.js
38 lines (33 loc) · 1.07 KB
/
flower.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
function Flower(branch) {
this.size = 10;
this.velocity = createVector(0, 0);
this.acceleration = createVector(0, 0);
this.pos = branch.end.copy();
this.done = false;
this.lifespan = 255;
this.draw = function() {
var colour = document.getElementById("colour").jscolor.rgb;
fill(colour[0],colour[1],colour[2], this.lifespan);
// fill(document.getElementById("colour").jscolor.toHEXString(),,,this.lifespan);
noStroke();
ellipse(this.pos.x, this.pos.y, this.size, this.size);
}
this.update = function() {
if (!this.done)
this.pos = branch.end.copy();
this.pos.add(this.velocity);
this.velocity.add(this.acceleration);
this.acceleration.mult(0);
if (this.done)
this.lifespan-=0.8;
}
this.shed = function() {
this.applyForce(createVector(random(-1, 1), random(-1, -0.1)));
this.update();
this.draw();
this.done = true;
}
this.applyForce = function(force) {
this.acceleration.add(force);
}
}