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; }
private void pushToStack() { CurrentState stateToPush = new CurrentState(); stateToPush.currentAngle = mState.currentAngle; stateToPush.currentLocation = new Point(mState.currentLocation.X, mState.currentLocation.Y); executionStack.Push(stateToPush); }
private void popFromStack() { mState = executionStack.Pop(); }