Example #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()
Example #2
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()
Example #3
0
def crossover(): # very clever!
    print ("What is this, a crossover episode?")
    time.sleep(1.5)

    world= TurtleWorld()

    bob = Turtle()
    bob.delay = 0.0001
    bob.pen_color = "black"
    symbol(bob, 15)


    wait_for_user()
Example #4
0
def main():
    # Create TurtleWorld object
    world = TurtleWorld()
    # Create Turtle object
    t = Turtle()
    t.delay = 0.001

    # Draw graphics
    pyramid(t, 5)

    # Press enter to exit
    key = input('Press enter to exit')
    world.destroy()
Example #5
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
Example #6
0
def main():
    # Create TurtleWorld object
    world = TurtleWorld()
    # Create Turtle object
    crush = Turtle()
    crush.delay = 0.001

    # Draw graphics
    square(crush, 10)
    lt(crush, 45)
    fd(crush, sqrt(2) * 10)
    rt(crush, 45)
    square(crush, 20)
    lt(crush, 45)
    fd(crush, sqrt(2) * 20)
    rt(crush, 45)
    square(crush, 30)
    lt(crush, 45)
    fd(crush, sqrt(2) * 30)
    rt(crush, 45)

    # Press enter to exit
    key = input('Press enter to exit')
    world.destroy()
Example #7
0
from TurtleWorld import *
world = TurtleWorld()
bob = Turtle()

from koch_curve import koch

t = bob
x = 360
bob.delay = .01

koch(t, x)
rt(t, 120)

koch(t, x)
rt(t, 120)

koch(t, x)
rt(t, 120)

# def koch(t,x):
# 	if x<3:

# 		return

# 	pd(t)
# 	fd(t,x/3)
# 	lt(t, 60)
# 	fd(t,x/3)
# 	rt(t,120)
# 	fd(t,x/3)
# 	lt(t,60)
Example #8
0
def main():
    world = TurtleWorld()
    turtle = Turtle()

    #################################################################################################################
    # Problem 2: Grades
    # TODO: create a for loop that runs until all grades have been entered
    #       The body of the for loop gets a numerical grade from the user, and then passes that numerical grade
    #       to getLetterGrade, which outputs the letter grade, and returns True, if the numerical grade is valid,
    #       and False if the numerical grade was invalid.
    #
    #       The loop should keep separate counts of the valid and invalid grades entered.  Make sure to properly
    #       initialize the two variables that track the counts
    #          If getLetterGrade returns True, update valid_cnt, gpa, and output "Valid grade entered"
    #          If getLetter Grade returns False, update invalid_cnt, and output "Invalid grade entered"
    #       The loop should also accumulate the valid grades in gpa.  make sure to properly initialize gpa, as well.
    #
    # After the for loop terminates, calculate the gpa from the valid grades accumulated in gpa / valid grade count

    # number of grades to enter
    grades = int(
        input('Enter the number of numerical grades to be converted: '))

    # TODO P2-1: Provide an appropriate initialization value for valid_cnt
    # count of valid grades
    valid_cnt = 0

    # TODO P2-1: Provide an appropriate initialization value for invalid_cnt
    # count of invalid grades
    invalid_cnt = 0

    # TODO P2-1: Provide an appropriate initialization value for gpa
    # accumulate valid grades and then calculate gpa
    gpa = 0

    # TODO P2-2: for loop starts here, embed the following lines in the loop, down to line that says "Loop ends here"
    #            the for loop should process all grades entered by the user
    for i in range(grades):
        grade = float(input('\nEnter next numerical grade: '))

        # TODO P2-3: Pass the grade entered above to getLetterGrade
        # TODO P2-4: Provide an if statement that checks the return value of getLetterGrade,
        #            updates valid_cnt, gpa, invalid_cnt, as necessary, and outputs the appropriate message from below
        if (getLetterGrade(grade)):
            gpa = gpa + grade
            valid_cnt = valid_cnt + 1
            print('Valid grade entered')
        else:
            invalid_cnt = invalid_cnt + 1
            print('Invalid grade entered')
    # TODO P2-2: for loop ends here

    # TODO P2-5: Calculate the gpa for the valid grades
    gpa = gpa / valid_cnt

    # After the loop terminates, output the counts of valid and invalid grades, and the gpa
    print('\nValid grades:', valid_cnt, ', Invalid grades:', invalid_cnt,
          ', gpa', gpa, '\n')

    ################################################################################################################
    # Problem 3:

    # TODO P3-2: Validate the user input such that it is greater than 0
    length = 0

    while length <= 0:
        length = int(input('Enter a length value greater than 0: '))

    #TODO P3-3: Call the draw_star function if the user input a value greater than 50
    if length > 50:
        draw_star(turtle, length)
    #        otherwise print an error message
    else:
        print('Length must be greater than 50 to draw a star')

    key = input('Press any key to exit')
    world.destroy()