// class Engine { int count; int flowerCount; // tracks the number of flowers IN A SEQUENCE int fd = 0; Rule ruleset []; ///// CONSTRUCTORS ////////// Engine (Rule [] r) { ruleset = r; } Engine () { } ///////////////////////////////////////////////// void interpretChar (char letter, Target t) { ///////////////////////////////////////////// int tempValue = int (letter); // convert letter to an int. if (tempValue >= 49 && tempValue <= 57) { count = tempValue - 48; // convert ascii into numbers 1 to 9 } /////// N represents a petalNum variable set for each plant /////////// if (letter == 'N') { /// ACCESS petalNum FROM line.Attribute (lineType) ASSOCIATED WITH TARGET (in array at position t.lineNum) count = l [t.lineNum].lineType.petalNum; // get petalNum from Target>lineNum>lineType // this is also used for leaves // } /////////////////////////////////////// if (letter == '+') { t.angleInc += l[t.lineNum].lineType.petalAngle; // 'petalAngle' is also use for leaves } if (letter == '-') { t.angleInc -= l[t.lineNum].lineType.petalAngle; // 'petalAngle' is also use for leaves } if (letter == 'c') { // change property of line ... t.plantType.Leaf.setFLength (.5); } if (letter == 'F') { // each 'F' represents a unit of time... String lineType = l [t.lineNum].lineType.type; if (lineType != "flower") { // t.timer += random (t.timeUnit*.9, t.timeUnit);//this.timeUnit; t.timer += t.timeUnit; } else { t.timer += 1; } t.angleInc = 0; // reset angle increment flowerCount = 0; // reset flower count; } if (letter == '*') { // halt (end) // nothing happens - ends the line... a.remove (t); // remove ball from ArrayList (a) // t.isAlive = false; } if (letter == '<') { t.charCount = 0; // loop back to start of String; } /////////////////////////////////////////////////////////////////////// if (letter == 'B') { //1. CREATE A NEW BRANCH (BASED ON INITIAL BRANCH ('ROOT')); Attributes root = BranchParent; Attributes newBranch = new Attributes (root.type, root.stringArray, root.c1, root.c2, root.petalNum, root.petalAngle, root.lo, root.hi, root.maxW, root.unitLength, false ); //2.ADD NEW BRANCH TO PLANT.ARRAYLIST (); t.plantType.addBranchToList (newBranch); //3. // GET THE NEW BRANCH FROM PLANT ARRAY Attributes justAddedBranch = (Attributes) t.plantType.branchList.get (t.plantType.bCount-1); //4. CREATE A NEW TARGET WITH PLANT AND PLANT.ARRAYLIST (NEWBRANCH) AS ARGUMENTS t.addBranch (justAddedBranch); t.angleInc = 0; // reset angle increment } ///////////////////////////////////////////////////////////// /// use a letter to start a new Plant (i,e, a new Target) if (letter == 'P') { // start new Plant // select a new plant type.. createNewPlant (); } ///// ADD A LEAF /////////////////////////// // either create and add a NEW leaf or just add an exisiting leaf object /// if (letter == 'L') { /////// IF THE LEAF IS ATTACHED TO A BRANCH...... // GET THE ARRAY POSITION OF THE BRANCH (PARENT) // Attributes myParent; if (l [t.lineNum].lineType.type == "branch") { int myBranchArrayPos = l [t.lineNum].lineType.arrayPosition; /// get parent from ArrayList (); myParent = (Attributes) t.plantType.branchList.get (myBranchArrayPos-1); } else { // must be from a Stem myParent = (Attributes) t.plantType.Stem; // Leaf attached to a Stem } /// GET THE CURRENT WIDTH OF THE BALL OF THE LINE (PARENT) /// //float w = l [t.lineNum]._alpha; //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// //Attributes cl = LeafChild;//CHANGE THIS SO THAT IT REFERS TO AN ATTRIBUTE OF A PLANT // Attributes cl = t.plantType.Leaf; // refers to a intial 'Leaf' within the Plant // float numberOfSpaces = count-1; // 3 leaves = 2 spaces etc.. float ang = l [t.lineNum].lineType.petalAngle; /// CREATE NEW LEAF: BASED ON PARENT BRANCH AND MAIN LEAF // ALTER SCALE OF LEAF ////////////////////////////////////////////// // ALTER SCALE OF LEAF (according to a set Plant.leafGrowth value) use to set new unitLength and width. t.leafScale *= t.plantType.leafGrowth; /////////////////////////////////////////////////// Attributes newLeaf = new Attributes (myParent, cl.type, cl.stringArray, cl.sineStart, cl.sineLength, cl.minWidth, cl.maxW*t.leafScale, cl.deviation, cl.shapeNoise, cl.unitLength*t.leafScale ); newLeaf.blur = t.plantType.leafBlur; // do we blur the flower ??? newLeaf.followParentColor = t.plantType.leafFollowParentColor; // does each petal follow it's parent color ? if (numberOfSpaces >= 1) { t.angleInc = -1*((numberOfSpaces* ang) / 2); for (int i=0; i