-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlower.pde
More file actions
69 lines (54 loc) · 1.64 KB
/
Flower.pde
File metadata and controls
69 lines (54 loc) · 1.64 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
class Flower{
float x;
float y;
Cell c;
Dna dna;
float hp;
float age;
float mSize;
Flower(float mS, Dna dna) {
this.age=random(0,0.3);
this.mSize = mS;
this.dna = dna;
this.hp = dna.cloneCost*dna.maxHp;
++this.dna.numFlowers;
}
void update() {
float temp = Earth.getTemp(c.cal);
float tempDiff = this.dna.idealTemp - temp;
if (abs(tempDiff)<this.dna.sensitivity) {
this.age += dna.aging/1000;
this.hp += 0.001*(1-this.age);
Cell nb = c.freeNb();
if (nb != null) {
Flower nF = this.clone();
if (nF != null) {
nb.addFlower(nF);
nb.newF = true;
}
}
} else{
this.hp += -0.0005;
}
this.hp = constrain(this.hp, 0, this.dna.maxHp);
}
Flower clone() {
if (this.hp > 2*this.dna.cloneCost*this.dna.maxHp) {
this.hp *= 1-this.dna.cloneCost;
return new Flower(this.mSize,this.dna.mutate());
}
return null;
}
boolean dead() {
return this.hp == 0;
}
void display(boolean uniClr) {
noStroke();
if(uniClr){
fill(this.dna.uniqClr.r, this.dna.uniqClr.g, this.dna.uniqClr.b);
}else{
fill(this.dna.clr.r, this.dna.clr.g, this.dna.clr.b);
}
ellipse(this.x, this.y, this.mSize * this.hp / this.dna.maxHp, this.mSize * this.hp / this.dna.maxHp);
}
}