private void GenerateImage()
        {
            animationTimer.Stop();
            pictureBox.Image = null;
            if ((pictureBox.Width > 0) && (pictureBox.Height > 0))
            {
                if (Content != null)
                {
                    var nodeStack  = new Stack <SymbolicExpressionTreeNode>();
                    int rows       = Content.World.Rows;
                    int columns    = Content.World.Columns;
                    var expression = Content.SymbolicExpressionTree;

                    DrawWorld();
                    using (Graphics graphics = Graphics.FromImage(pictureBox.Image)) {
                        float cellHeight = pictureBox.Height / (float)rows;
                        float cellWidth  = pictureBox.Width / (float)columns;

                        Interpreter interpreter = new Interpreter(Content.SymbolicExpressionTree, Content.World, Content.MaxTimeSteps);
                        int         currentAntLocationColumn;
                        int         currentAntLocationRow;
                        // draw initial ant
                        interpreter.AntLocation(out currentAntLocationRow, out currentAntLocationColumn);
                        DrawAnt(graphics, currentAntLocationRow, currentAntLocationColumn, interpreter.AntDirection, cellWidth, cellHeight);
                        // interpret ant code and draw trail
                        while (interpreter.ElapsedTime < interpreter.MaxTimeSteps)
                        {
                            interpreter.Step();
                            interpreter.AntLocation(out currentAntLocationRow, out currentAntLocationColumn);
                            DrawAnt(graphics, currentAntLocationRow, currentAntLocationColumn, interpreter.AntDirection, cellWidth, cellHeight);
                        }
                    }
                    pictureBox.Refresh();
                }
            }
        }
        private void playButton_Click(object sender, EventArgs e)
        {
            playButton.Enabled = false;

            animationInterpreter = new Interpreter(Content.SymbolicExpressionTree, Content.World, Content.MaxTimeSteps);

            DrawWorld();
            using (Graphics graphics = Graphics.FromImage(pictureBox.Image)) {
                float cellHeight = pictureBox.Height / (float)Content.World.Rows;
                float cellWidth  = pictureBox.Width / (float)Content.World.Columns;
                // draw initial ant
                int currentAntLocationColumn;
                int currentAntLocationRow;
                animationInterpreter.AntLocation(out currentAntLocationRow, out currentAntLocationColumn);
                DrawAnt(graphics, currentAntLocationRow, currentAntLocationColumn, animationInterpreter.AntDirection, cellWidth, cellHeight);
                pictureBox.Refresh();
            }

            animationTimer.Start();
        }
 private void animationTimer_Tick(object sender, EventArgs e)
 {
     using (Graphics graphics = Graphics.FromImage(pictureBox.Image)) {
         float cellHeight = pictureBox.Height / (float)Content.World.Rows;
         float cellWidth  = pictureBox.Width / (float)Content.World.Columns;
         int   currentAntLocationColumn;
         int   currentAntLocationRow;
         // interpret ant code and draw trail
         animationInterpreter.Step();
         animationInterpreter.AntLocation(out currentAntLocationRow, out currentAntLocationColumn);
         DrawAnt(graphics, currentAntLocationRow, currentAntLocationColumn, animationInterpreter.AntDirection, cellWidth, cellHeight);
         pictureBox.Refresh();
         if (animationInterpreter.ElapsedTime < animationInterpreter.MaxTimeSteps)
         {
             animationTimer.Start();
         }
         else
         {
             animationTimer.Stop();
             playButton.Enabled = true;
         }
     }
 }