class Target { Plant plantType; Vector3D vel, loc, acc; Engine e = new Engine (); boolean isAlive = true; String s; float r ; float angle; float angleInc; int charCount = 0; float timer; int counter = 0; float magnitude; float inc =0.1; int [] direction = { -1, 1} ;//controls the cuve of the wave (left or right) // float shapeArray [] = sinLUT; int lineNum; // position of the line in array which is attached to this target int depth; float timeUnit; //int leafCount; float leafScale;// = 1.0f; float flowerScale; boolean getLocs = true; /////////////////////////////////////// // this is called for all of the branchlines // //// SETTINGS FOR EACH BRANCH // Target (Plant p, Attributes atts, Vector3D loc_, float angle_, int parent, int d) { plantType = p; depth = d; /// GET A RANDOM STRING FROM THE ARRAY OF STRINGS (if there is one) /// int arrayItem = int (random (atts.stringArray.length)); String selectedString = atts.stringArray [arrayItem]; // convert the string using the Engine and set the result as the 's' s = e.convertString (selectedString); /////// loc = loc_; vel = new Vector3D (0, 0, 0); acc = new Vector3D (0, 0, 0); angle = angle_; lineNum = parent; addLine(atts); // attach a line object to this target. //// SET PROPERTIES ACCORDING TO ATTRIBUTES// r = plantType.radius; //magnitude = random (atts.lo, atts.hi); //40;// random (plantType.lo, plantType.hi); magnitude = atts.lo;// magnitude*=direction [int (random (direction.length))]; timeUnit = atts.unitLength / r;//atts.t; timer = 0; leafScale = plantType.leafStart; flowerScale = plantType.flowerStart; } /////////////////////////////////////// void runTimer () { if (timer > 0) { calcForce (); timer --; } else { getLetter (); } if (getLocs) { getLoc(); } } //////////////////////////////////////////// void getLetter () { char letter = s.charAt (charCount); e.interpretChar (letter, this); if (charCount < s.length()-1) { charCount++; } } //////////////////////////////////////// void calcForce () { // use LUT to get force before applying this to velocity // float direction = shapeArray [counter%360] * magnitude + angle ;// add initial angle (its direction) //direction *= -1; acc.x = r * cos (radians (direction))*1; // vel.x ? acc.y = r * sin (radians (direction))*1; // vel.y ?? //acc.x *=0.99; //acc.y *=0.5; counter++; /////////////////////////////////////////// ///// 'bounce' magnitude between hi and lo ///// //inc += random (-1, 1); // too much randomness ! magnitude += inc; ///// ACESSING HI AND LO FROM the Line array [lineNum] ; /// if (magnitude < l [lineNum].lineType.lo || magnitude > l [lineNum].lineType.hi) { inc = -inc; } /////////////////////////////////////////////////////////////////// loc.add (acc); //if (loc.x > width) { // kill target and start a new one..... //loc.x = 0; //} } ////////////////////////////////// void render () { fill (0, 0, 0); fill (256, 0, 0); ellipse (loc.x, loc.y, 20, 20); } //////////////////////////////////////// void addLine (Attributes atts) { /// adds a new line which is 'attached' to this Target // before a new line is added - the ball and line number of the current line needs to be stored // linePos is the number of the line which creates the branch. lineCount++; l[lineCount] = new Line (atts, this, lineCount, lineNum); lineNum = lineCount; // update linePos to be number of the latest line being created... } ////////////////////////////////////// void addBranch (Attributes atts) { Vector3D tLoc = new Vector3D (loc.x, loc.y, loc.z); float theta = acc.heading2D(); theta = degrees (theta); /// create a new line // send the name of the current line: it is the next line's parent... // set the new depth = current depth + 1 // anglelnc is increased as part of the enginne (if char = a + or a - ) ////////////////////////////////////////////////////// /// increase the 'depth count' only for branches //// if (atts.type == "branch") { //println ("a branch is added"); // println (atts.parent); //if (atts.parent != null) { //if (atts.parent.type != "stem") { depth++; //} //} // if (atts.parent.type == "stem") { //depth++; //} } if (depth < MAXDEPTH ) { Target t = new Target (plantType, atts, tLoc, theta+angleInc, lineNum, depth); a.add (t); } //// if it has reached max depth do not draw any more branches ./// if (depth >= MAXDEPTH) { if (atts.type != "branch") { Target t = new Target (plantType, atts, tLoc, theta+angleInc, lineNum, depth); a.add (t); } } } //////////////////////////////////// void addPlant (Plant plant, Attributes atts) { Target t = new Target (plant, atts, new Vector3D (width, random (height/2)), -180, 0, 0); // loc, angle, string, parent a.add (t); } ////////////////////////////////// // ADD A METHOD WHICH GETS THE LOCATION OF THE TARGET ; TO SEE IF THE STEM HITS THE EDGE OF THE SCREEN /// void getLoc () { String type = l[lineNum].lineType.type; if (type == "stem") { float xLoc = loc.x; float yLoc = loc.y; plantType.stemLoc.setXY (xLoc, yLoc); //// HAS IT HIT THE EDGE OF THE STAGE ?? if (xLoc>width || xLoc<0 || yLoc>height || yLoc<0) { /// STORE LOCATION IN PLANT (as stemLoc) //plantType.stemLoc.setXY (xLoc, yLoc); getLocs = false; } } } }