Beispiel #1
0
    def test_turtle(self):
        tw = TurtleWorld.TurtleWorld()
        t = TurtleWorld.Turtle()
        t.delay = 0.01
        t.step()

        t.bk(10)
        t.rt(10)
        t.lt(-10)
        t.pu()
        t.pd()
        t.set_color('papaya whip')
        t.set_pen_color('yellow')

        TurtleWorld.fd(t, 10)
        TurtleWorld.bk(t, 10)
        TurtleWorld.lt(t, 10)
        TurtleWorld.rt(t, 10)
        TurtleWorld.pu(t)
        TurtleWorld.pd(t)
        TurtleWorld.set_color(t, 'cyan')
        TurtleWorld.set_pen_color(t, 'magenta')

        x = t.get_x()
        self.assertAlmostEqual(x, -9.0)

        y = t.get_y()
        self.assertAlmostEqual(y, 0.0)

        heading = t.get_heading()
        self.assertAlmostEqual(heading, -20)

        tw.quit()
Beispiel #2
0
import TurtleWorld
import math as m

world = TurtleWorld.TurtleWorld()
bob = TurtleWorld.Turtle()
print(bob)
"""
for i in range(4):
    print ('Hello!')

for num in range(4):
   fd(bob, 100)
  rt(bob)
"""


def square(t, length):
    """ Draw a square with sides of given length
    :param t:
    :param length:
    :return: returns the turtle to staring position or location
    """
    for num in range(4):
        TurtleWorld.fd(t, length)
        TurtleWorld.rt(t)


def polyline(t, n, length, angle):
    for i in range(n):
        TurtleWorld.fd(t, length)
        TurtleWorld.rt(t, angle)