Example #1
0
        private void Form1_MouseClick(object sender, MouseEventArgs e)
        {
            //Transform windows coordinates to Turtle coordinates
            float  turtleX      = e.X - Width / 2 + 8;
            float  turtleY      = Height / 2 - e.Y - 19;
            string selectedItem = (string)comboBox1.SelectedItem;

            if (selectedItem == "Draw Triangle") //We will add more options later
            {
                var trg = new EquilateralTriangle(turtleX, turtleY, 50);
                shapes.Add(trg);
                mostRecent = trg;
            }

            if (selectedItem == "Draw Rectangle")
            {
                var rec = new Rectangle(turtleX, turtleY, 100, 50);
                shapes.Add(rec);
                mostRecent = rec;
            }
            if (selectedItem == "Move Shape")
            {
                mostRecent.MoveTo(turtleX, turtleY);
            }
            Turtle.Dispose();
            DrawAll();
        }
Example #2
0
 public void DrawAll()
 {
     Turtle.Dispose();
     foreach (var shape in Shapes)
     {
         shape.Draw();
     }
 }
Example #3
0
 public void DrawAll()
 {
     Turtle.Dispose(); //first clea all turtle tracks to start afresh
     foreach (var shape in shapes)
     {
         shape.Draw();
     }
 }
        private void runTurtle()
        {
            Turtle.Dispose();
            float minX, minY, maxX, maxY;

            minX = -400;
            minY = -250;
            maxX = 500;
            maxY = 250;
            System.Windows.Size  size     = PolyLine.getSize(polylines);
            System.Windows.Point position = PolyLine.getPosition(polylines);
            float scale;

            Turtle.Delay = (int)(Math.Pow(2.0, 10 - ((double)(trackBar1.Value))));
            if (size.Width / size.Height > (maxX - minX) / (maxY - minY))
            {
                scale = (float)size.Width / (maxX - minX);
            }
            else
            {
                scale = (float)size.Height / (maxY - minY);
            }
            Turtle.PenSize  = 2;
            Turtle.PenColor = Color.Green;
            Turtle.PenUp();
            Turtle.ShowTurtle = true;
            try
            {
                foreach (PolyLine polyline in polylines)
                {
                    List <Line> lines = polyline.getLines();
                    Turtle.MoveTo(maxX - (float)lines[0].X1 / scale + (float)position.X * scale, (float)lines[0].Y1 / scale + (float)position.Y * scale + minY);
                    Turtle.PenDown();
                    foreach (Line l in lines)
                    {
                        //Turtle.MoveTo((float)l.X1 / scale + (float)position.X * scale + minX, (float)l.Y1 / scale + (float)position.Y * scale +minY);
                        Turtle.MoveTo(maxX - (float)l.X2 / scale + (float)position.X * scale, (float)l.Y2 / scale + (float)position.Y * scale + minY);
                    }
                    Turtle.PenUp();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 private void buttonClose_Click(object sender, EventArgs e)
 {
     Turtle.Dispose();
     this.Close();
 }
Example #6
0
 public override void Dispose()
 {
     Turtle.Dispose();
 }