private void startButton_Click(object sender, EventArgs e) { if (repBraPanel.BackColor == Color.Red) { System.Windows.Forms.MessageBox.Show("Check the pattern given !!\nInvalid character given (character allowed : a-zA-Z and parenthesis) or parenthesis not open/closed"); return; } else if (repBraPanel.BackColor == Color.Green) { DetectStartPosition(); DetectLength(); pattern.Userstr = patternBox.Text; centerPanel.Refresh(); g = centerPanel.CreateGraphics(); L_System system = new L_System(); // Creation String seed, add pattern textbox system.Seed = pattern.Userstr; // Creation Dictionnaty Rules, all Textbox rules into Store rules system.Rules = system.Store_Rules(ruleKey1, ruleKey2, ruleValue1, ruleValue2); // Creation Dictionnary Symbols, Stack All textbox and combobox for the symbols and related symbols TextBox[] textboxes = { symbol1, symbol2, symbol3, symbol4, symbol5, symbol6 }; Stack <TextBox> symbols = new Stack <TextBox>(textboxes); ComboBox[] comboboxes = { relatedSymbol1, relatedSymbol2, relatedSymbol3, relatedSymbol4, relatedSymbol5, relatedSymbol6 }; Stack <ComboBox> relatedSymbols = new Stack <ComboBox>(comboboxes); system.Symbols = system.Store_Symbols(symbols, relatedSymbols); // Creation Levels, get value from form system.Level = (short)repeatNumericUpDown.Value; BuildPath buildpath = new BuildPath(); buildpath.Buildingpath(system); Draw(buildpath, chosenAngle, chosenLength); } }
private void Draw(BuildPath allpath, int angle, int length) { string path = allpath.Path; Stack <int> stack_x = new Stack <int>(); Stack <int> stack_y = new Stack <int>(); Stack <int> stack_angle = new Stack <int>(); foreach (char action in path) { if (action.Equals('+')) { angle = angle + (int)angleNumericUpDown.Value; } else if (action.Equals('-')) { angle = angle + 360 - (int)angleNumericUpDown.Value; } else if (action.Equals('[')) { stack_x.Push(start_x); stack_y.Push(start_y); stack_angle.Push(angle); continue; } else if (action.Equals(']')) { start_x = stack_x.Pop(); start_y = stack_y.Pop(); angle = stack_angle.Pop(); continue; } Console.WriteLine(angle); if (action.Equals('+') || action.Equals('-') || action.Equals('F')) { // Modifiy Cos and Sin for each start end_x = (int)(start_x + Math.Cos(angle * .017453292519) * length); end_y = (int)(start_y + Math.Sin(angle * .017453292519) * length); Point[] points = { new Point(start_x, start_y), new Point(end_x, end_y), }; start_x = end_x; start_y = end_y; g.DrawLines(myPen, points); } else if (action.Equals('f')) { continue; } } return; }