Ejemplo n.º 1
0
        public void TestChangeColor()
        {
            var turtle = new Turtle(new Vector(0, 0), 0.0, ImmutableStack<Turtle.TurtleState>.Empty, dummy, Colors.Black);
            var colorChanged = turtle.ChangeColor(Colors.Green);

            Assert.AreEqual(colorChanged.DrawColor, Colors.Green);
        }
Ejemplo n.º 2
0
        public void TestRotate()
        {
            var turtle = new Turtle(new Vector(0, 0), 0.0, ImmutableStack<Turtle.TurtleState>.Empty, dummy, Colors.Black);
            var rotated = turtle.Rotate(Math.PI / 2);

            var expected = Math.PI / 2;
            var actual = rotated.Angle;

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 3
0
        public void TestForward()
        {
            var turtle = new Turtle(new Vector(0, 0), 0.0, ImmutableStack<Turtle.TurtleState>.Empty, dummy, Colors.Black);
            var forward = turtle.Forward(15);

            var expected = new Vector(15, 0);
            var actual = forward.Position;

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 4
0
        public void TestPop()
        {
            var state = new Turtle.TurtleState(new Vector(2, 2), Math.PI / 4, Colors.Black);
            var stack = ImmutableStack<Turtle.TurtleState>.Empty.Push(state);
            var turtle = new Turtle(new Vector(0, 0), 0.0, stack, dummy, Colors.Black);
            var popped = turtle.Pop();

            Assert.AreEqual(popped.Position, state.Position);
            Assert.AreEqual(popped.Angle, state.Angle);
            Assert.AreEqual(popped.DrawColor, state.DrawColor);
        }
Ejemplo n.º 5
0
        public void TestPush()
        {
            var turtle = new Turtle(new Vector(0, 0), 0.0, ImmutableStack<Turtle.TurtleState>.Empty, dummy, Colors.Black);
            var pushed = turtle.Push();
            var first = pushed.Stack.Peek();
            var pos = first.Position;
            var angle = first.Angle;
            var color = first.DrawColor;

            Assert.AreEqual(turtle.Position, pos);
            Assert.AreEqual(turtle.Angle, angle);
            Assert.AreEqual(turtle.DrawColor, color);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Draws the L-System to a WriteableBitmap. First computes the state string,
 /// then computes a starting turtle position and then does a fold over the
 /// state string, interpreting the characters as turtle commands. 
 /// </summary>
 /// <param name="image"></param>
 public void Draw(WriteableBitmap image)
 {
     var state = this.Step();
     var start = new Turtle(
         StartPos,
         0.0,
         ImmutableStack<Turtle.TurtleState>.Empty,
         (a, b, c, d, color) => image.DrawLine(a, b, c, d, color),
         Colors.Black);
     state.Aggregate(start, (t, c) => {
         switch (c) {
             case 'F': return t.Forward(this.Distance);
             case '+': return t.Rotate(this.Angle);
             case '-': return t.Rotate(-this.Angle);
             case '[': return t.Push();
             case ']': return t.Pop();
             case '1': return t.ChangeColor(Color.FromRgb(140, 80, 60));
             case '2': return t.ChangeColor(Color.FromRgb(24, 180, 24));
             case '3': return t.ChangeColor(Color.FromRgb(48, 220, 48));
             default: return t;
         }
     });
 }
Ejemplo n.º 7
0
 public void TestBadPop()
 {
     var turtle = new Turtle(new Vector(0, 0), 0.0, ImmutableStack<Turtle.TurtleState>.Empty, dummy, Colors.Black);
     turtle.Pop();
 }