void Start() { string axiom; float angle; int derivations; Dictionary <string, List <Production> > productions; LSystemParser.Parse( file.text, out axiom, out angle, out derivations, out productions); string moduleString; LSystemDeriver.Derive( axiom, angle, derivations, productions, out moduleString); GameObject leaves, trunk; LSystemInterpreter.Interpret( segmentAxialSamples, segmentRadialSamples, segmentWidth, segmentHeight, leafSize, leafAxialDensity, leafRadialDensity, useFoliage, narrowBranches, leafMaterial, trunkMaterial, angle, moduleString, out leaves, out trunk); leaves.transform.parent = transform; leaves.transform.localPosition = Vector3.zero; trunk.transform.parent = transform; trunk.transform.localPosition = Vector3.zero; UpdateColliderBounds(trunk); }
void OnWizardCreate() { GameObject lsys = new GameObject("L-System"); lsys.transform.position = new Vector3(0.0f, 0.0f, 0.0f); LSystemParser parse = (LSystemParser)lsys.AddComponent(typeof(LSystemParser)); LSystemPainter render = (LSystemPainter)lsys.AddComponent(typeof(LSystemPainter)); if (guiOn) { LSystemGui gui = (LSystemGui)lsys.AddComponent(typeof(LSystemGui)); } parse.initialize(variables, constants, start, rules, iteration, angle); }
/* ---------- * Axiom: A * Rules: * A --> L B F R A F A R F B L * B --> R A F L B F B L F A R * --------- * F=forward, L=turn left, R=turn right * **/ public static List <Module> Generate(int aOrder) { LSystemParser parser = new LSystemParser(); LSystem sys = parser.ParseSystem(@" Axiom: A Rules: A --> L; B; F; R; A; F; A; R; F; B; L B --> R; A; F; L; B; F; B; L; F; A; R "); sys.Iterate(aOrder); string last = ""; List <Module> result = new List <Module>(sys.symbols.Count); // Filter out the symbols "A" and "B" and also remove pointless rotations // So an "L" followed by a "R" is pointless so we can remove both. foreach (var m in sys.symbols) { if (m.Name == "L" || m.Name == "R" || m.Name == "F") { if ((last == "L" && m.Name == "R") || (last == "R" && m.Name == "L")) { result.RemoveAt(result.Count - 1); if (result.Count > 0) { last = result[result.Count - 1].Name; } else { last = ""; } } else { result.Add(m); last = m.Name; } } } return(result); }
void GenerateNewSystem(int windowID) { GUI.Label(new Rect(10, 15, 64, 32), "Start :"); startText = GUI.TextField(new Rect(64, 10, 240, 32), startText); GUI.Label(new Rect(10, 50, 64, 32), "Rules :"); ruleText = GUI.TextField(new Rect(64, 50, 240, 32), ruleText); GUI.Label(new Rect(10, 85, 64, 32), "Iterations :"); iterText = GUI.TextField(new Rect(104, 85, 200, 32), iterText); GUI.Label(new Rect(10, 120, 64, 32), "Angle :"); anglText = GUI.TextField(new Rect(104, 120, 200, 32), anglText); if (GUI.Button(new Rect(10, 280, 128, 32), "Generate")) { LSystemPainter paint = (LSystemPainter)this.GetComponent("LSystemPainter"); paint.reset(); LSystemParser parse = (LSystemParser)this.GetComponent("LSystemParser"); parse.initialize("", "", startText, ruleText, int.Parse(iterText), float.Parse(anglText)); parse.reset(); } }