public void BuildThirdPlant() { m_currentLSystem = new LSystem("FX", "+-[]", "X"); m_currentLSystem.AddRule('X', "F[+X][-X]FX"); m_currentLSystem.AddRule('F', "FF"); m_initialAngle = 3.141592f / 2.0f; m_angleValue = 3.141592f / 10.0f; BuildMesh(); }
public void BuildFractalPlant() { m_currentLSystem = new LSystem("XF", "+-[]", "X"); m_currentLSystem.AddRule('X', "F-[[X]+X]+F[+FX]-X"); m_currentLSystem.AddRule('F', "FF"); m_initialAngle = 3.141592f / 3.0f; m_angleValue = 3.141592f / 10.0f; BuildMesh(); }
public void BuildOtherFractalPlant() { m_currentLSystem = new LSystem("F", "+-[]", "F"); m_currentLSystem.AddRule('F', "F[+F]F[-F]F"); m_initialAngle = 3.141592f / 2.0f; m_angleValue = 3.141592f / 10.0f; BuildMesh(); }
public int[,] Activate(string axiom, int simulationCount) { LSystem lsys = new LSystem(); lsys.AddRule('A', "AB[<BA"); lsys.AddRule('B', "AA>AB]<"); Vector2 max, min; plots = Plot(lsys.Simulate(axiom, simulationCount), out max, out min); Vector2 minAbs = new Vector2(Mathf.Abs(min.x), Mathf.Abs(min.y)); int[,] grid = new int[(int)(max.x + minAbs.x) + 5, (int)(max.y + minAbs.y) + 5]; for (int i = 0; i < plots.Length; i++) { grid[(int)(minAbs.x + plots[i].x) + 2, (int)(minAbs.y + plots[i].y) + 2] = 1; } return(grid); }
public override void OnInspectorGUI() { EditorGUI.BeginChangeCheck(); lSystem.axiom = EditorGUILayout.TextField("Axiom", lSystem.axiom); lSystem.numberOfIterations = EditorGUILayout.IntSlider("Iterations", lSystem.numberOfIterations, 0, 10); List <char> keyz = lSystem.demRulz.Keys.ToList(); foreach (var key in keyz) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(key + " = "); var value = EditorGUILayout.TextField(lSystem.demRulz[key]); lSystem.EditRule(key, value); if (GUILayout.Button("X")) { lSystem.DeleteRule(key); } EditorGUILayout.EndHorizontal(); } newRule = EditorGUILayout.TextField(newRule); if (GUILayout.Button("AddRule")) { lSystem.AddRule(newRule); newRule = "Yo bling rule here, n***a!"; } EditorGUILayout.Separator(); turtle.angle = EditorGUILayout.Slider("Angle", turtle.angle, 0f, 360f); turtle.distance = EditorGUILayout.Slider("Distance", turtle.distance, -10f, float.MaxValue); EditorGUILayout.Separator(); if (GUILayout.Button("Benjamin")) { lSystemBehaviour.generatedString = lSystem.Generate(); } if (EditorGUI.EndChangeCheck()) { SceneView.RepaintAll(); } }
// Start is called before the first frame update void Start() { Module a = new Module('A', new List<float>{ 1.0f }); LSystem lSys = new LSystem(a); lSys.SetVar("c", 1.0f); lSys.SetVar("p", 0.3f); lSys.SetVar("q", lSys.GetVar("c") - lSys.GetVar("p")); lSys.SetVar("h", Mathf.Pow(lSys.GetVar("p") * lSys.GetVar("q"), 0.5f)); lSys.SetVar("R", 1.456f); Module m = new Module('F', new List<float> { 1.0f }, (float[] f) => { return f; }); Module m1 = new Module('A', new List<float> { 1.0f }, (float[] f) => { float[] s = new float[f.Length]; s[0] = f[0] / lSys.GetVar("R"); return s; }); Module m11 = new Module('A', new List<float> { 1.0f }, (float[] f) => { float[] s = new float[f.Length]; s[0] = f[0] / lSys.GetVar("R"); return s; }); Module m2 = new Module('F', new List<float> { 1.0f }, (float[] f) => { f[0] *= lSys.GetVar("q"); return f; }); Module mPlus = new Module('+'); Module mMinus = new Module('-'); Module mOpen = new Module('['); Module mClose = new Module(']'); List<Module> suc = new List<Module> { new Module(m), mOpen, mPlus, new Module('A', new List<float> { 1.0f }, (float[] f) => { float[] s = new float[f.Length]; s[0] = f[0] / lSys.GetVar("R"); return s; }), mClose, mOpen, mMinus, new Module('A', new List<float> { 1.0f }, (float[] f) => { float[] s = new float[f.Length]; s[0] = f[0] / lSys.GetVar("R"); return s; }), mClose }; lSys.AddRule(a, suc); List<Module> mods = lSys.RunSystem(3); Debug.Log(mods.Count); string str_out = ""; foreach(Module mod in mods) { str_out += mod; } Debug.Log(str_out); }
// Start is called before the first frame update void Start() { LSystem seed = new LSystem("FA"); seed.AddRule("A", "![&FA!![^L]]/'[&FA!![^L]]/'[&FA!![^L]]"); seed.AddRule("F(x)", "F(x*1.2)"); seed.AddRule("F", "F(.95)/S"); seed.AddRule("^^^<L>]", "q"); seed.AddRule("S", "F[^L]"); seed.AddRule("L", "^^L"); for (int i = 0; i < 5; i++) { seed.Grow(); TreeBuilder(seed.ToString()); topTurtle.Set(Vector3.zero, Quaternion.LookRotation(Vector3.up, Vector3.back), Vector3.one); this.transform.position = new Vector3(0, 0, 5.0f * (i + 1)); //Debug.Log(seed.ToString()); } //TreeBuilder(seed.ToString()); }
/* * EditorGUILayout.BeginHorizontal(); * scrollPos = * EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Width(100), GUILayout.Height(100)); * GUILayout.Label(t); * EditorGUILayout.EndScrollView(); */ private void OnGUI() { // if(isInit) // { // //lSys = new LSystem(); // //rules.Add(""); // //varsCreated = variables.Count; // //serObj = new SerializedObject(this); // isInit = false; // } lSys.Clear(); //Could do this first thing on clicking "Generate"? Will that keep adding production rules... scrollPos = EditorGUILayout.BeginScrollView(scrollPos); //scrollPos = EditorGUILayout.BeginVertical(GUILayout.Height(100)); GUILayout.Label("L-Systems:", EditorStyles.boldLabel); //SerializedObject obj = new SerializedObject(this); // SerializedProperty keyProp = obj.FindProperty("keyList"); // EditorGUILayout.PropertyField(keyProp, new GUIContent("Names: "), true); // SerializedProperty valProp = obj.FindProperty("valList"); // EditorGUILayout.PropertyField(valProp, new GUIContent("Values: "), true); DrawVariableMap(); //GUILayout.Space(VariableDrawer.propHeight); // int lowCount = keyList.Count; // if (valList.Count < lowCount) // { // lowCount = valList.Count; // } //change to just copy dict? foreach (KeyValuePair <string, float> kv in variables) { //Debug.Log("Key: " + kv.Key + " = " + kv.Value); lSys.SetVar(kv.Key, kv.Value); // lSys.SetVar(variables[i].key, variables[i].value); } axiom = EditorGUILayout.DelayedTextField("Axiom: ", lSys.GetAxiom()); lSys.SetAxiom(axiom); DrawProductionRules(); serObj.ApplyModifiedProperties(); foreach (ProductionRule pr in pRules) { pr.suc.Clear(); if (pr.sucRep.Length > 0) { List <Module> mods = ModuleParser.StringToModuleList(pr.sucRep, lSys); pr.suc.InsertRange(0, mods); } } stepSize = EditorGUILayout.FloatField("Segment Length: ", stepSize); width = EditorGUILayout.FloatField("Segment Width: ", width); angle = EditorGUILayout.FloatField("Angle: ", angle); num = EditorGUILayout.IntField("Iterations: ", num); numOut = EditorGUILayout.IntField("Output Count: ", numOut); turtlePos = (Interpreter.TurtlePos)EditorGUILayout.EnumPopup("Turtle Position: ", turtlePos); GUILayout.FlexibleSpace(); if (GUILayout.Button("Generate")) { //Debug.Log("Generating..."); //Debug.Log(pRules.Count); foreach (ProductionRule r in pRules) { lSys.AddRule(r); } float xOffset = 10f; Material mat = new Material(Shader.Find("Sprites/Default")); mat.color = new Color(0.0f, 0.0f, 0.0f, 1.0f); AssetDatabase.CreateAsset(mat, "Assets/GeometryMaterial.mat"); List <Mesh> meshes = new List <Mesh>(); dupCount = 0; dupMap.Clear(); //string symbols = "Ff+-[]|"; for (int i = 0; i < numOut; ++i) { EditorUtility.DisplayProgressBar("Generating Geometry...", "Generating Geometry...", ((float)i / numOut)); List <Module> mods = lSys.RunSystem(num); string str_out = ""; foreach (Module m in mods) { str_out += m; //if (symbols.IndexOf(m.sym) != -1) } //str_out = Regex.Replace(str_out, "[^Ff+*/ ()0-9|,-]", "", RegexOptions.Compiled); //str_out.Replace("^[Ff+-()[][0-9]", ""); //Debug.Log(str_out); if (dupMap.ContainsKey(str_out)) { dupMap[str_out] += 1; } else { dupMap.Add(str_out, 1); } //Debug.Log(str_out); Interpreter intptr = new Interpreter(); GameObject go = new GameObject("Geometry" + i); //go.transform.position = Vector3.zero; go.transform.position = new Vector3(0f, 0f, 0f); MeshFilter mf = go.AddComponent <MeshFilter>(); MeshRenderer mr = go.AddComponent <MeshRenderer>(); //Material mat = new Material(Shader.Find("Sprites/Default")); mr.sharedMaterial = mat; //mr.sharedMaterial.color = Color.black; Mesh newMesh = intptr.InterpretSystem(mods, turtlePos, stepSize, width, angle); mf.mesh = newMesh; //Dictionary<Vector3, int> vertexCount = new Dictionary<Vector3, int>(); //foreach (Vector3 v in newMesh.vertices) //{ // if (vertexCount.ContainsKey(v)) // { // vertexCount[v] += 1; // } // else // { // vertexCount.Add(v, 1); // } //} //bool isDuplicate = false; //foreach (Mesh m in meshes) //{ // Dictionary<Vector3, int> vCount = new Dictionary<Vector3, int>(); // foreach (Vector3 v in m.vertices) // { // if (vCount.ContainsKey(v)) // { // vCount[v] += 1; // } // else // { // vCount.Add(v, 1); // } // } // bool isDup = true; // if (vertexCount.Keys.Count == vCount.Keys.Count) // { // foreach (KeyValuePair<Vector3, int> kv in vertexCount) // { // if (!vCount.ContainsKey(kv.Key)) // { // isDup = false; // break; // } // else if (vCount[kv.Key] != kv.Value) // { // isDup = false; // break; // } // } // if (isDup) // { // isDuplicate = true; // ++dupCount; // } // } //} //if (!isDuplicate) // meshes.Add(newMesh); ++createdCount; AssetDatabase.CreateAsset(mf.sharedMesh, "Assets/NewGO" + createdCount + ".mesh"); //AssetDatabase.CreateAsset(mr.sharedMaterial, "Assets/NewGO" + createdCount + ".mat"); PrefabUtility.SaveAsPrefabAssetAndConnect(go, "Assets/NewGO" + createdCount + ".prefab", InteractionMode.AutomatedAction); } EditorUtility.ClearProgressBar(); foreach (KeyValuePair <string, int> kv in dupMap) { if (kv.Value > 1) { dupCount += kv.Value - 1; Debug.Log("Duplicate Reuslt: " + kv.Key + "\nTimes Generated: " + kv.Value); } } Debug.Log("Num Duplicates: " + dupCount); } EditorGUILayout.EndScrollView(); }