Пример #1
0
def main():
    world = TurtleWorld()

    bob = Turtle()
    bob.delay = 0.001

    # draw a pie
    #make 5 triangles and have them created in rotation

    rt(bob, 200)
    pd(bob)
    polygon(bob, 3, 150)
    lt(bob, 60.1)
    pd(bob)
    polygon(bob, 3, 150)
    lt(bob, 61)
    pd(bob)
    polygon(bob, 3, 150)
    lt(bob, 60.1)
    pd(bob)
    polygon(bob, 3, 150)
    lt(bob, 60.1)
    pd(bob)
    polygon(bob, 3, 150)
    lt(bob, 60.1)
    pd(bob)
    polygon(bob, 3, 150)

    wait_for_user()
Пример #2
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()
Пример #3
0
def main():
    world = TurtleWorld()

    bob = Turtle()
    bob.delay = 0.001

    # draw a square
    polygon(bob, 4, 40)

    # draw a circle centered on the origin
    radius = 25
    pu(bob)
    fd(bob, radius)
    lt(bob)
    pd(bob)
    circle(bob, radius)

    my_start = (0, 10)

    # draw a circle centered on the origin
    radius = 50
    pu(bob)
    fd(bob, radius)
    lt(bob)
    pd(bob)
    circle(bob, radius)
    pu(bob)

    #draw triangle
    fd(bob, 50)
    pd(bob)
    polygon(bob, 3, 30)
Пример #4
0
def setup_canvas(numturtles):
    canvas = TurtleWorld()
    turtles = []
    for i in range(numturtles):
        bob = Turtle()
        turtles.append(bob)
    return turtles
Пример #5
0
def main():
    world = TurtleWorld()    

    bob = Turtle()
    bob.delay = 0.001
    
    # Move the turtle into place
    pu(bob)
    lt(bob, 180)
    fd(bob, 150)
    pd(bob)
    # draw pie 1
    polypie(bob, 5, 50)
    # Move the turtle into place
    pu(bob)
    lt(bob, 180)
    fd(bob, 150)
    pd(bob)
    # draw pie 2
    polypie(bob, 6, 50)
    # Move the turtle into place
    pu(bob)
    fd(bob, 150)
    pd(bob)
    # draw pie 3
    polypie(bob, 7, 50)
    
    wait_for_user()
Пример #6
0
def drawFlower(n):
    world = TurtleWorld()
    bob = Turtle()
    bob.delay=0.0001
    for i in range(1,n+1):
        petal(bob,200,360/n)
        lt(bob,360/n)
    wait_for_user()
Пример #7
0
def main():

    world = TurtleWorld()    

    bob = Turtle()
    bob.delay = 0.000001

    pumpkin(bob)
Пример #8
0
def drawTriangle(n):
    world = TurtleWorld()
    bob = Turtle()
    # bob.delay=0.0001
    for i in range(n):
        rt(bob,180)
        triangle(bob,360.0/n,50)
    wait_for_user()
Пример #9
0
 def test_turtle_world(self):
     tw = TurtleWorld.TurtleWorld(interactive=True)
     tw.setup_run()
     tw.delay = 0.01
     control = tw.make_turtle()
     control.set_color('magenta')
     control.move_turtle(-1)
     tw.clear()
     tw.quit()
Пример #10
0
def exercise_1():
    def square(t):
        for _ in range(4):
            fd(t, 200)
            lt(t)

    world = TurtleWorld()
    bob = Turtle()

    square(bob)
Пример #11
0
def initTurtle(delay=0.01):
    """
  Initializes a turtle object
  :param delay: Delay before each action of the turtle. Lower it is the faster the turtle moves.
  :return: turtle object
  """
    TurtleWorld()
    t = Turtle()
    t.delay = delay
    return t
Пример #12
0
def exercise_3():
    def polygon(t, l, n):
        for _ in range(n):
            fd(t, l)
            rt(t, 360.0 / n)

    world = TurtleWorld()
    bob = Turtle()
    length = 50

    polygon(bob, length, 8)
Пример #13
0
def exercise_2():
    def square(t, l):
        for _ in range(4):
            fd(t, l)
            rt(t)

    world = TurtleWorld()
    bob = Turtle()
    length = 200

    square(bob, length)
Пример #14
0
def make_square(init_x, init_y, side):
    world = TurtleWorld()
    pat = Turtle()
    pat.set_delay(.001)

    for i in range(400):
        pat.x = init_x - (i * 5 / 2)
        pat.y = init_y - (i * 5 / 2)
        for j in range(4):
            pat.fd(side + i * 5)
            pat.lt(90)
    wait_for_user()
Пример #15
0
def world():

    global turtle
    global world

    world = TurtleWorld()
    turtle = Turtle()

    world.wm_minsize(width=800, height=800)

    turtle.delay = 0.00000001

    start(turtle, (0, 0))
Пример #16
0
def exercise_5():
    def arc(t, r, a):
        for _ in range(a % 360):
            fd(t, 2 * math.pi * r * (1 / 360))
            rt(t, 1)

    world = TurtleWorld()
    bob = Turtle()
    bob.delay = 0.01
    radius = 50
    angle = 180

    arc(bob, radius, angle)
Пример #17
0
def make_polygon(init_x, init_y, sides, length):
    world = TurtleWorld()
    pat = Turtle()
    pat.set_delay(.001)
    angle_int = 360 / sides

    pat.x = init_x
    pat.y = init_y
    for i in range(sides):
        pat.fd(length)
        pat.lt(angle_int)

    wait_for_user()
Пример #18
0
def main():
    world = TurtleWorld()
    bob = Turtle()
    bob.delay = 0.005
    # square(bob,45)
    # square(bob,100)
    # square(bob,180)
    # polygon(bob,15,30)
    # square(bob,60)
    circle(bob, 60)
    #arc(bob,80,180)
    polyline
    wait_for_user()
Пример #19
0
def setup_canvas(numturtles):
    canvas = TurtleWorld()
    turtles = [canvas]
    angle = 360.0 / float(numturtles)

    for i in range(numturtles):
        bob = Turtle()
        bob.delay = 0
        turtles.append(bob)
        pu(bob)
        lt(bob, angle * i)
        fd(bob, 100)
        pd(bob)

    return turtles
Пример #20
0
def make_world(constructor):

    # create TurtleWorld
    world = TurtleWorld()
    world.delay = .01
    world.setup_run()

    # make three Wobblers with different speed and clumsiness attributes
    colors = ['orange', 'green', 'purple']
    i = 1.0
    for color in colors:
        t = constructor(world, i, i * 30, color)
        i += 0.5

    return world
Пример #21
0
def main():
    world = TurtleWorld()

    bob = Turtle()
    bob.delay = 0.001

    # draw a circle centered on the origin
    radius = 100
    pu(bob)
    fd(bob, radius)
    lt(bob)
    pd(bob)
    circle(bob, radius)

    wait_for_user()
Пример #22
0
def main():

    world = TurtleWorld()

    bob = Turtle()
    bob.delay = 0.000001

    # draw a circle centered on the origin
    radius = 100
    pu(bob)
    fd(bob, radius)
    lt(bob)
    pd(bob)
    circle(bob, radius)

    pu(bob)
    lt(bob, 90)
    fd(bob, 100)

    radius = 50
    pu(bob)
    fd(bob, radius)
    lt(bob)
    pd(bob)
    circle(bob, radius)

    pu(bob)
    lt(bob, 90)
    fd(bob, 150)
    lt(bob, 90)
    pd(bob)

    for i in range(4):
        fd(bob, 100)
        lt(bob, )
        fd(bob, 100)

    lt(bob, 60)
    for c in range(3):
        fd(bob, 180)
        lt(bob, 120)

    wait_for_user()
Пример #23
0
def main():
    world = TurtleWorld()

    bob = Turtle()
    bob.delay = 0.0001

    # draw a circle centered on the origin
    radius = 100
    pu(bob)
    fd(bob, radius)
    lt(bob)
    pd(bob)
    circle(bob, radius)

    pu(bob)
    lt(bob)
    fd(bob, radius / 2)
    rt(bob)
    fd(bob, radius / 32)
    pd(bob)
    circle(bob, radius / 2)

    pu(bob)
    rt(bob)
    fd(bob, radius / 2)
    rt(bob)
    fd(bob, radius)
    lt(bob, 180)
    pd(bob)
    square(bob, radius * 2)

    pu(bob)
    lt(bob)
    fd(bob, radius)
    rt(bob)
    fd(bob, radius)
    rt(bob)
    fd(bob, radius)
    pd(bob)
    polyline(bob, 3, radius, 120)
    wait_for_user()
Пример #24
0
def main():
    world = TurtleWorld()

    bob = Turtle()
    bob.delay = 0.001

    pu(bob)
    fd(bob, -150)
    pd(bob)
    pie(bob, 5, 60)

    pu(bob)
    fd(bob, 150)
    pd(bob)
    pie(bob, 6, 55)

    pu(bob)
    fd(bob, 150)
    pd(bob)
    pie(bob, 7, 50)

    wait_for_user()
Пример #25
0
def main():
    world = TurtleWorld()

    bob = Turtle()
    bob.delay = 0.001

    # draw a circle centered on the origin
    radius = 100
    pu(bob)
    fd(bob, radius)
    lt(bob)
    pd(bob)
    circle(bob, radius)

    # draws a square
    rt(bob)
    square(bob, 100)
    lt(bob)

    # resets turtle for problem 2
    lt(bob)
    pu(bob)
    fd(bob, 200)

    # draws triangle
    pd(bob)
    polygon(bob, 3, 100)

    # sets turtle for next circle
    pu(bob)
    fd(bob, -50)
    lt(bob)

    # draws second circle within first
    pd(bob)
    circle(bob, radius / 2)

    wait_for_user()
Пример #26
0
def main():
    """ I don't know what I'm doing"""

    world = TurtleWorld()

    bob = Turtle()
    bob.delay = 0.000001

    print("-----Menu-----".center(40))
    print(" Task 1: Turtle draws 2 cirlces, a square, and a triangle.")
    print(" Task 2: Turtle draws 3 different pies.")

    choice = input("Pick a task: ")

    if choice == "1":
        illuminati(bob)
    elif choice == "2":
        pu(bob)
        lt(bob, 180)
        fd(bob, 125)
        rt(bob, 180)
        five_pie(bob)
        six_pie(bob)
        seven_pie(bob)
Пример #27
0
def main():
    world = TurtleWorld()

    bob = Turtle()
    bob.delay = 0.001

    # draw a circle centered on the origin
    radius = 100
    pu(bob)
    fd(bob, radius)
    lt(bob)
    pd(bob)

    circle(bob, radius)
    pu(bob)
    fd(bob, -radius)
    pd(bob)

    square(bob, radius * 2)
    pu(bob)
    fd(bob, radius)
    pd(bob)

    bob.lt(60)
    polygon(bob, 3, radius * (1 + (35 / 48)))
    pu(bob)
    bob.rt(60)
    lt(bob)
    fd(bob, radius)
    rt(bob)
    fd(bob, radius / 2)
    lt(bob)
    pd(bob)
    circle(bob, radius / 2)

    wait_for_user()
Пример #28
0
    The turtle starts and ends at the peak, facing the middle of the base.

    t: Turtle
    r: length of the equal legs
    angle: peak angle in degrees
    """
    y = r * sin(angle * pi / 180)

    rt(t, angle)
    fd(t, r)
    lt(t, 90 + angle)
    fd(t, 2 * y)
    lt(t, 90 + angle)
    fd(t, r)
    lt(t, 180 - angle)


if __name__ == '__main__':

    world = TurtleWorld()
    bob = Turtle()
    bob.delay = 0.01

    size = 40
    draw_pie(bob, 5, size)
    draw_pie(bob, 6, size)
    draw_pie(bob, 7, size)
    draw_pie(bob, 8, size)
    wait_for_user()
Пример #29
0
from swampy.TurtleWorld import  *

world1 = TurtleWorld()
bob = Turtle()

print bob
for i in range(4):
    fd(bob,100)
    lt(bob)

wait_for_user()
Пример #30
0
def clear_bob(delay):
    world = TurtleWorld()
    bob = Turtle()
    bob.delay = delay
    return bob