示例#1
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
def make_world(constructor):

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

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

    return world
示例#3
0
    def wander(self):
        self.lt(randint(-90, 90))
        self.fd(10)
        #self.check_boundary()

    def check_boundary(self):
        # i think the boundary is at 200 for this world.
        if self.x < 300 and self.x > -300 and self.y < 300 and self.y > -300:
            pass
        else:
            self.undo()

    def other_turtles(self):
        return [animal for animal in self.world.animals if animal is not self]

if __name__ == '__main__':
    # create TurtleWorld
    world = TurtleWorld()
    world.delay = .01
    world.setup_run()

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

    world.mainloop()
示例#4
0
from swampy.TurtleWorld import *

def koch(t, x):
    if x < 3.0:
        fd(t, x)
        return
    koch(t, x/3.0)
    lt(t, 60)
    koch(t, x/3.0)
    rt(t, 120)
    koch(t, x/3.0)
    lt(t, 60)
    koch(t, x/3.0)


def snowflake(t, x):
    koch(t, x)
    rt(t, 120)
    koch(t, x)
    rt(t, 120)
    koch(t, x)
    
    
world = TurtleWorld()
world.delay = 0
bob = Turtle()
snowflake(bob, 500)
wait_for_user()