public Form1() { InitializeComponent(); mGen = new Generator(); mGen.AddRule('F', "FFF+F+FFF+F+F+FF-F-FFF-F-F"); mGen.AddAction('F', moveForward); mGen.AddAction('+', turnLeft); mGen.AddAction('-', turnRight); mGen.AddAction('[', pushToStack); mGen.AddAction(']', popFromStack); mGen.TraversalComplete += (() => { mDrawingPanel.Refresh(); }); mState = new CurrentState(); mState.currentLocation = new Point(256, 256); mState.currentAngle = 90.0f; targetLocation = mState.currentLocation; executionStack = new Stack <CurrentState>(); drawingBitmap = new Bitmap(mDrawingPanel.Width, mDrawingPanel.Height); mDrawingPanel.Paint += mDrawingPanel_Paint; }
static void Main(string[] args) { Generator gen = new Generator(); gen.AddRule('A', "AB"); gen.AddRule('B', "BA"); gen.AddAction('A', () => { Console.WriteLine("Visited A"); }); gen.AddAction('B', () => { Console.WriteLine("Visited B"); }); string generatedSystem = gen.GenerateSystem(3, "A"); Console.WriteLine("Generated System: " + generatedSystem); gen.TraverseSystem(generatedSystem); Console.ReadKey(); }
private static void Main(string[] args) { using (StreamReader sr = new StreamReader("grammar.txt")) { string text = sr.ReadToEnd(); Grammar g = Parser.ParseText(text); Console.WriteLine("== Symbols =="); foreach (SymbolType type in g.Symbols) { Console.WriteLine(type.Name); } Console.WriteLine("\n== Axioms =="); foreach (Graph <Symbol> axiom in g.Axioms) { Dump(axiom); } Console.WriteLine("\n== Rules =="); foreach (Rule rule in g.Rules) { Dump(rule.Left); Dump(rule.Right); } // TODO: accept additional axioms Generator gen = new Generator(g.Axioms.First()); foreach (Rule rule in g.Rules) { gen.AddRule(rule); } gen.Run(); } System.Console.ReadLine(); }
protected void Generate() { // Set parameters treeGenerator.InitialState.angleGrowth = 0.0f; treeGenerator.InitialState.sizeGrowth = 0.0f; treeGenerator.InitialState.windIntensity = 0.0f; treeGenerator.InitialState.angle = (float)Math.PI * 22.5f / 180f; treeGenerator.InitialState.diameter = 0; treeGenerator.InitialState.index = 0; treeGenerator.InitialState.heading = new Vector3(0f, -1f, 0f); treeGenerator.InitialState.left = new Vector3(1f, 0f, 0f); treeGenerator.InitialState.up = new Vector3(0f, 0f, 1f); treeGenerator.InitialState.size = 20f; treeGenerator.Input = @"F"; treeGenerator.AddRule("F", 1f, "F F - [ - F + F + F ] + [ + F - F - F ]"); treeGenerator.Generate(age); /*generator.Input = @"A"; * generator.AddRule("A", 1f, @"[ & F L ! A ] / / / / / ' [ & F L ! A ] / / / / / / / ' [ & F L ! A ]"); * generator.AddRule("F", 1f, @"S / / / / / F"); * generator.AddRule("S", 1f, @"F L"); * generator.AddRule("L", 1f, @"[ ' ' ' ^ ^ { - f + f + f - | - f + f + f } ]"); * generator.Generate(4); */ }