Exemplo n.º 1
0
 public static void Turn(EBPrimitive angle)
 {
     Turtle.VerifyAccess();
     double animateTime = Math.Abs((double)angle.GetAsDecimal() * 200.0 / (double)(Turtle._speed * Turtle._speed));
     if (Turtle._speed == 10)
     {
         animateTime = 5.0;
     }
     Turtle._angle += angle;
     GraphicsWindow.Invoke(delegate
     {
         DoubleAnimation animation = new DoubleAnimation
         {
             To = new double?(Turtle._angle),
             Duration = new Duration(TimeSpan.FromMilliseconds(animateTime))
         };
         Turtle._rotateTransform.BeginAnimation(RotateTransform.AngleProperty, animation);
     });
     Turtle.WaitForReturn(animateTime);
 }
Exemplo n.º 2
0
 public static void Move(EBPrimitive distance)
 {
     Turtle.VerifyAccess();
     double animateTime = Math.Abs((double)distance.GetAsDecimal() * 320.0 / (double)(Turtle._speed * Turtle._speed));
     if (Turtle._speed == 10)
     {
         animateTime = 5.0;
     }
     double num = Turtle._angle / 180.0 * 3.1415926535897931;
     double newY = Turtle._currentY - distance * System.Math.Cos(num);
     double newX = Turtle._currentX + distance * System.Math.Sin(num);
     Shapes.Animate("_turtle", newX, newY, animateTime);
     if (Turtle._penDown)
     {
         GraphicsWindow.Invoke(delegate
         {
             string name = Shapes.GenerateNewName("_turtleLine");
             Line line = new Line
             {
                 Name = name,
                 X1 = Turtle._currentX,
                 Y1 = Turtle._currentY,
                 Stroke = GraphicsWindow._pen.Brush,
                 StrokeThickness = GraphicsWindow._pen.Thickness
             };
             GraphicsWindow.AddShape(name, line);
             DoubleAnimation animation = new DoubleAnimation
             {
                 From = new double?(Turtle._currentX),
                 To = new double?(newX),
                 Duration = new Duration(TimeSpan.FromMilliseconds(animateTime))
             };
             DoubleAnimation animation2 = new DoubleAnimation
             {
                 From = new double?(Turtle._currentY),
                 To = new double?(newY),
                 Duration = new Duration(TimeSpan.FromMilliseconds(animateTime))
             };
             line.BeginAnimation(Line.X2Property, animation);
             line.BeginAnimation(Line.Y2Property, animation2);
         });
     }
     Turtle._currentX = newX;
     Turtle._currentY = newY;
     Turtle.WaitForReturn(animateTime);
 }