class Turtle { float xpos; float ypos; float angle; float unitsize; float anglechange; float[] xpos_a; float[] ypos_a; float[] angle_a; float[] startw_a; int acount; float startw; int branchcount; // Vector branches; Branch[] branches; int branchesarrayindex; Turtle() { this.unitsize = -20 + random(15); this.anglechange = -30 + random(5); this.branchcount = 0; this.startw = 15; this.xpos_a = new float[100]; this.ypos_a = new float[100]; this.angle_a = new float[100]; this.startw_a = new float[100]; this.acount = 0; this.branches = new Branch[100]; for (int i = 0; i < this.branches.length; i++) { this.branches[i] = new Branch(); } this.branchesarrayindex = 0; }; void process(char c, boolean drawit) { if (c == '+') { this.angle += this.anglechange; } else if (c == '-') { this.angle -= this.anglechange; } else if (c == 'F') { float tremble = gWind;// * gWindMultiplier; // if (gReactive) { // tremble = (gWind + 0.02);// * gWindMultiplier; // } float us = this.unitsize ;// * 1;//random(1); float a = angle * 0.0174532925 * ((1 + (tremble / 2)) - random(tremble)); float tx = this.xpos + (sin(a) * us); float ty = this.ypos + (cos(a) * us); stroke(gStemred, gStemgreen, gStemblue, gStemalpha); if (this.branchcount > 1) { // && !gReactive) { if (drawit) { line(this.xpos, this.ypos, tx, ty); } } else { // if branch array doesn't have enough branches, // add new branch to array, // only make branch if spare branch in array if (this.branchesarrayindex < this.branches.length) { this.branches[this.branchesarrayindex].setX1(this.xpos); this.branches[this.branchesarrayindex].setY1(this.ypos); this.branches[this.branchesarrayindex].setX2(tx); this.branches[this.branchesarrayindex].setY2(ty); this.branches[this.branchesarrayindex].calcSAngle(); this.branches[this.branchesarrayindex].setSW(this.startw); // render branch if (drawit) { this.branches[this.branchesarrayindex].render(); } this.branchesarrayindex++; float hyp = sqrt(pow((tx - this.xpos),2) + pow((ty - this.ypos),2)); this.startw = (this.startw - (hyp * ((this.startw - pow(this.startw, 0.9)) / hyp))); } }; this.xpos = tx; this.ypos = ty; } else if (c =='[') { this.branchcount ++; this.xpos_a = append(this.xpos_a, this.xpos); this.ypos_a = append(this.ypos_a, this.ypos); this.angle_a = append(this.angle_a, this.angle); this.startw_a = append(this.startw_a, this.startw); } else if (c ==']') { this.branchcount --; this.xpos = this.xpos_a[this.xpos_a.length - 1]; this.ypos = this.ypos_a[this.ypos_a.length - 1]; this.angle = this.angle_a[this.angle_a.length - 1]; this.startw = this.startw_a[this.startw_a.length - 1]; this.xpos_a = shorten(this.xpos_a); this.ypos_a = shorten(this.ypos_a); this.angle_a = shorten(this.angle_a); this.startw_a = shorten(this.startw_a); }; }; void setXY(float nx, float ny) { this.xpos = nx; this.ypos = ny; } void setHeading(float ang) { this.angle = ang; } void setBranchCount(int bc) { this.branchcount = bc; } void setBranchesArrayIndex(int bai) { this.branchesarrayindex = bai; } void setStartBranchWidth(float sbw) { this.startw = sbw; } void setUnitsize(float us) { this.unitsize = us; } void setAnglechange(float ac) { anglechange = ac; } };