public void Generate(bool clean = false) { // save original sentence lSystem.SaveOriginalSentence(); if (clean) { CleanExistingLSystem(); } if (lSystem == null) { Debug.LogError("You must have an lSystem defined"); enabled = false; } if (lSystem.RuleCount == 0) { Debug.LogError("You must have at least one rule defined"); enabled = false; } lineRenderer = GetComponent <LineRenderer>(); lineRenderer.positionCount = 2; for (int i = 0; i < numberOfGenerations; i++) { savedState.Push(state.Clone()); lSystem.Generate(); state = savedState.Pop(); } DrawLines(); }
void DrawLines() { state = new LSystemState() { x = 0, y = 0, size = lineLength, angle = 0 }; string sentence = lSystem.GeneratedSentence; for (int i = 0; i < sentence.Length; i++) { char c = sentence[i]; switch (c) { case 'F': Line(); break; case 'G': Translate(); break; case '+': state.angle += angle; break; case '-': state.angle -= angle; break; case '[': savedState.Push(state.Clone()); break; case ']': state = savedState.Pop(); break; } } }
public void generate(bool once = false) { reset(); string sentence; if (once) { sentence = _lSystem.getNewSentence(); } else { sentence = _lSystem.getNewSentencebyStep(); } if (sentence == null) { return; } curState = new LSystemState(); for (int i = 0; i < sentence.Length; i++) { char c = sentence[i]; if (_drawSymbols.Contains(c)) { drawLine(); } else if (_leafSymbols.Contains(c)) { drawLeaf(_leafPath); } else if (_flowerSymbols.Contains(c)) { drawFlower(_flowerPath); } else { switch (c) { case '+': curState.angle += _angle; break; case '-': curState.angle -= _angle; break; case '[': stateStack.Push(curState.Clone()); break; case ']': curState = stateStack.Pop(); break; default: break; } } } }