/// <summary> /// Constructor (overloaded) /// </summary> /// <param name="parser">Grammar parser instance</param> /// <param name="startPoint">Starting point</param> public LSystem(Parser parser, PointF startPoint, float startAngle = 0.0f, float step = 10.0f, float delta = ((float) Math.PI / 2), float angleDelta = 0.0f, float stepDelta = 0.0f, int seed = 0, Pen pen = null) { _expandedGrammar = parser.Expand(); _startPoint = new PointF(startPoint.X, startPoint.Y); _startAngle = startAngle; _step = step; _delta = delta; _angleDelta = angleDelta; _stepDelta = stepDelta; _random = new Random(seed); _pen = pen ?? new Pen(Color.Black); _stateStack = new Stack<State>(); }
/// <summary> /// Generate image (L-System) /// </summary> public void GenerateImage() { Backend.Parser parser = new Backend.Parser(Axiom, Rules, Iterations); string expandedGrammar = ""; try { expandedGrammar = parser.Expand(); } catch (OutOfMemoryException) { System.Windows.MessageBox.Show("Not enough memory, try decrease number of iterations."); return; } Backend.LSystem lsystem = new Backend.LSystem(expandedGrammar, new PointF(StartX * ((float)Renderer.WIDTH / Renderer.PREVIEW_WIDTH), StartY * ((float)Renderer.HEIGHT / Renderer.PREVIEW_HEIGHT)), (float)(StartAngle / 180 * Math.PI), StepSize, (float)(Delta / 180 * Math.PI), (AngleDelta / 100.0f), (StepDelta / 100.0f), Seed, new Pen(new SolidBrush(Color.Black), LineWidth)); List <Backend.IDrawable> polylist = lsystem.Generate(); _renderer.Clear(SelectedBackgroundColor); _renderer.Paint(polylist); // cleanup polylist.Clear(); // update gui InvokePropertyChanged("Image"); }
/// <summary> /// Generate image (L-System) /// </summary> public void GenerateImage() { Backend.Parser parser = new Backend.Parser(Axiom, Rules, Iterations); string expandedGrammar = ""; try { expandedGrammar = parser.Expand(); } catch (OutOfMemoryException) { System.Windows.MessageBox.Show("Not enough memory, try decrease number of iterations."); return; } Backend.LSystem lsystem = new Backend.LSystem(expandedGrammar, new PointF(StartX * ((float)Renderer.WIDTH / Renderer.PREVIEW_WIDTH), StartY * ((float)Renderer.HEIGHT / Renderer.PREVIEW_HEIGHT)), (float)(StartAngle / 180 * Math.PI), StepSize, (float)(Delta / 180 * Math.PI), (AngleDelta / 100.0f), (StepDelta / 100.0f), Seed, new Pen(new SolidBrush(Color.Black), LineWidth)); List<Backend.IDrawable> polylist = lsystem.Generate(); _renderer.Clear(SelectedBackgroundColor); _renderer.Paint(polylist); // cleanup polylist.Clear(); // update gui InvokePropertyChanged("Image"); }