# 1. You construct at least 2 rg.SimpleTurtle objects. # 2. Each rg.SimpleTurtle object draws something # (by moving, using its rg.Pen). ANYTHING is fine! # 3. Each rg.SimpleTurtle moves inside a LOOP. # # Be creative! Strive for way-cool pictures! Abstract pictures rule! # # If you make syntax (notational) errors, no worries -- get help # fixing them at either this session OR at the NEXT session. # # Don't forget to COMMIT-and-PUSH when you are done with this module ############################################################################## import rosegraphics as rg window = rg.TurtleWindow() window.delay(20) t1 = rg.SimpleTurtle('turtle') t2 = rg.SimpleTurtle('turtle') t1.speed = 200 t2.speed = 200 t1.pen = rg.Pen('blue', 2) a = 3 t2.pen = rg.Pen('red', a) for k in range(100): a = a**0.9 t1.draw_circle(42 - k / 3) t1.left(30) t2.pen_down() t2.forward(30) t2.left(5 * k) window.close_on_mouse_click()
# # - Makes the SimpleTurtle's pen have color 'green' and thickness 10. # # - Makes the SimpleTurtle go 150 pixels straight DOWN. # # Don't forget to: # - import rosegraphics and construct a TurtleWindow # at the BEGINNING of your code, and to # - ask your TurtleWindow to close_on_mouse_click # as the LAST line of your code. # See the beginning and end of m4e_loopy_turtles for an example. # # As always, test by running the module. # As always, COMMIT-and-PUSH when you are done with this module. # ######################################################################## import rosegraphics as rg window = rg.TurtleWindow() turtle = rg.SimpleTurtle() turtle.pen = rg.Pen('blue', 1) turtle.left(90) turtle.forward(200) turtle.pen_up() turtle.go_to(rg.Point(100, -40)) turtle.pen_down() turtle.pen = rg.Pen('green', 10) turtle.right(180) turtle.forward(150) window.close_on_mouse_click()
def try_methods_and_functions(): # IMPORTANT: Read the NOTE below before you try to solve this TO-DO! """ Constructs a SimpleTurtle and sets its pen to a new rg.Pen that is 'blue' with thickness 5. Then makes the SimpleTurtle do the following (in the order listed): 1. Go backward 150 units. 2. Change its speed to 1 (slowest). Draw 2 squares whose size (width and height) are 100, each "twisted" from the previous by 30 degrees. 3. Change its speed to 5 (faster). Change its Pen's color to 'red'. Draw 10 squares whose size (width and height) are 50, each "twisted" from the previous by 15 degrees. 4. Change its speed to 100 (about the fastest possible). Change its Pen's thickness to 35. Draw 8 squares whose size (width and height) are 300, each "twisted" from the previous by 60 degrees. 5. Changes its Pen to be a NEW Pen whose color is 'black' and whose thickness is 3. 6. Goes backward 200 units. 7. Draw a CIRCLE whose radius is 30. 8. Draw a SQUARE whose sides are each of length 50. """ ########################################################################### # DONE: 5. Implement and test this function, per its doc-string above. # (To test it, put a statement in main that calls this function.) # # NOTE: This function should ** CALL ** the # draw_many_squares # function defined above. If you don't see why, ** ASK FOR HELP. ** # ########################################################################### blow = rg.SimpleTurtle() blow.pen = rg.Pen('blue', 5) blow.backward(150) blow.speed = 1 draw_many_squares(blow, 2, 100, 30) blow.speed = 5 blow.pen.color = 'red' draw_many_squares(blow, 10, 50, 15) blow.speed = 100 blow.pen.thickness = 35 draw_many_squares(blow, 8, 300, 60) blow.pen = rg.Pen('black', 3) blow.backward(200) blow.draw_circle(30) blow.draw_square(50)
############################################################################### # ----------------------------------------------------------------------------- # The next few lines show how to: # - CONSTRUCT (make and initialize) a TurtleWindow object for animation. # The definition of a TurtleWindow is in the rg # (shorthand for rosegraphics) module. # ----------------------------------------------------------------------------- window = rg.TurtleWindow() window.delay(20) # Bigger numbers mean slower animation. # ----------------------------------------------------------------------------- # The next few lines show how to: # - CONSTRUCT (make) a SimpleTurtle object and ASSIGN a NAME to the object. # ----------------------------------------------------------------------------- boris = rg.SimpleTurtle() # ----------------------------------------------------------------------------- # The next few lines show how to: # - Ask the SimpleTurtle object to do things by applying METHODs to it. # The numbers in the parentheses are called ARGUMENTS. # ----------------------------------------------------------------------------- boris.forward(100) boris.left(90) boris.forward(200) # ----------------------------------------------------------------------------- # The next few lines show how to: # - Construct a second SimpleTurtle, # set its pen and speed INSTANCE VARIABLES, and ask it to do things. # -----------------------------------------------------------------------------
def try_methods_and_functions(): """ Constructs a SimpleTurtle and sets its pen to a new rg.Pen that is 'blue' with thickness 5. Then makes the SimpleTurtle do the following (in the order listed): 1. Go backward 150 units. 2. Change its speed to 1 (slowest). Draw 2 squares whose size (width and height) are 100, each "twisted" from the previous by 30 degrees. 3. Change its speed to 5 (faster). Change its Pen's color to 'red'. Draw 10 squares whose size (width and height) are 50, each "twisted" from the previous by 15 degrees. 4. Change its speed to 100 (about the fastest possible). Change its Pen's thickness to 35. Draw 8 squares whose size (width and height) are 300, each "twisted" from the previous by 60 degrees. 5. Change its Pen to be a NEW Pen whose color is 'black' and whose thickness is 3. 6. Go backward 200 units. 7. Draw a CIRCLE whose radius is 30. 8. Draw a SQUARE whose sides are each of length 50. """ ########################################################################### # Done: 6. Implement and test this function, per its doc-string above. # The testing code (in main) is already written for you. # # NOTE: This function should ** CALL ** the # draw_many_squares # function defined above. If you don't see why, ** ASK FOR HELP. ** ########################################################################### big_boy = rg.SimpleTurtle('turtle') big_boy.pen = rg.Pen('blue', 5) big_boy.backward(150) big_boy.speed = 1 draw_many_squares(big_boy, 2, 100, 30) big_boy.speed = 5 big_boy.pen = rg.Pen('red', 5) draw_many_squares(big_boy, 10, 50, 15) big_boy.speed = 100 big_boy.pen = rg.Pen('red', 35) draw_many_squares(big_boy, 8, 300, 60) big_boy.pen = rg.Pen('black', 3) big_boy.backward(200) big_boy.draw_circle(30) big_boy.draw_square(50)
######################################################################## ######################################################################## # DONE: 2. # You should have RUN the m5e_loopy_turtles module and READ its code. # (Do so now if you have not already done so.) # # Below this comment, add ANY CODE THAT YOU WANT, as long as: # 1. You construct at least 2 rg.SimpleTurtle objects. # 2. Each rg.SimpleTurtle object draws something # (by moving, using its rg.Pen). ANYTHING is fine! # 3. Each rg.SimpleTurtle moves inside a LOOP. # # Be creative! Strive for way-cool pictures! Abstract pictures rule! # # If you make syntax (notational) errors, no worries -- get help # fixing them at either this session OR at the NEXT session. # # Don't forget to COMMIT-and-PUSH when you are done with this module. # ######################################################################## import rosegraphics as rg window = rg.TurtleWindow() frank = rg.SimpleTurtle() frank.draw_circle(100) frank.speed = 50 shane = rg.SimpleTurtle('turtle') shane.pen = rg.Pen('green', 5) shane.left(75) shane.forward(200)
# change this TO-DO to DONE and ** continue to the next TOD-DO (below). ** # ############################################################################### # ----------------------------------------------------------------------------- # CONSTRUCT (make) a TurtleWindow object and set it up for animation. # The definition of a TurtleWindow is in the rg (shorthand for # rosegraphics) module. # ----------------------------------------------------------------------------- window = rg.TurtleWindow() window.delay(20) # Bigger numbers mean slower animation. # ----------------------------------------------------------------------------- # CONSTRUCT (make) a SimpleTurtle object and ASSIGN a NAME to the object. # ----------------------------------------------------------------------------- boris = rg.SimpleTurtle() # ----------------------------------------------------------------------------- # Ask the SimpleTurtle object to do things by applying METHODs to it: # ----------------------------------------------------------------------------- boris.forward(100) boris.left(90) boris.forward(200) # ----------------------------------------------------------------------------- # Construct a second SimpleTurtle, # set its pen and speed INSTANCE VARIABLES, and ask it to do things. # ----------------------------------------------------------------------------- natasha = rg.SimpleTurtle('turtle') natasha.pen = rg.Pen('red', 30) # Second argument is the Pen's thickness natasha.speed = 10 # Faster
# # Don't forget to: # - import rosegraphics and construct a TurtleWindow # at the BEGINNING of your code, and to # - ask your TurtleWindow to close_on_mouse_click # as the LAST line of your code. # See the beginning and end of m4e_loopy_turtles for an example. # # As always, test by running the module. # As always, COMMIT-and-PUSH when you are done with this module. # ######################################################################## import rosegraphics as rg window = rg.TurtleWindow() window.delay(20) tom = rg.SimpleTurtle() tom = rg.SimpleTurtle('turtle') tom.pen = rg.Pen('blue', 20) tom.right(-90) tom.forward(200) tom.right(90) tom.pen_up() tom.forward(100) tom.right(-90) tom.forward(40) tom.pen_down() tom.pen = rg.Pen('green', 10) tom.backward(150) window.close_on_mouse_click()
# Below this comment, add ANY CODE THAT YOUR WANT, as long as: # 1. You construct at least 2 rg.SimpleTurtle objects. # 2. Each rg.SimpleTurtle object draws something # (by moving, using its rg.Pen). ANYTHING is fine! # 3. Each rg.SimpleTurtle moves inside a LOOP. # # Be creative! Strive for way-cool pictures! Abstract pictures rule! # # If you make syntax (notational) errors, no worries -- get help # fixing them at either this session OR at the NEXT session. # # Don't forget to COMMIT your work by using VCS ~ Commit and Push. ######################################################################## import rosegraphics as rg window = rg.TurtleWindow() red_turtle = rg.SimpleTurtle('turtle') red_turtle.pen = rg.Pen('red', 5) red_turtle.speed = 5 size=200 for j in range(5): red_turtle.right(50) red_turtle.forward(100) red_turtle.left(70) import rosegraphics as rg window = rg.TurtleWindow() black_turtle = rg.SimpleTurtle('turtle') black_turtle.pen = rg.Pen('black', 3) black_turtle.speed = 10
# - Tells the SimpleTurtle to go 150 pixels straight DOWN. # # Don't forget to: # - import rosegraphics and construct a TurtleWindow # at the BEGINNING of your code, and to # - ask your TurtleWindow to close_on_mouse_click # as the LAST line of your code. # See the beginning and end of m4e_loopy_turtles for an example. # # ** Nothing fancy is required. ** # ** The NEXT exercise will let you show your creativity. ** # # As always, test by running the module. # # As always, COMMIT-and-PUSH when you are done with this module. # ############################################################################### import rosegraphics as rg window = rg.TurtleWindow() stalin = rg.SimpleTurtle('circle') stalin.pen = rg.Pen('blue', 1) stalin.pen_up() stalin.left(90) stalin.forward(200) stalin.go_to(rg.Point(100, -40)) stalin.pen_down() stalin.pen = rg.Pen('green', 10) stalin.backward(150) window.close_on_mouse_click()
""" An exercise that summarizes what you have learned in this Session. Authors: David Mutchler, Dave Fisher, Valerie Galluzzi, Amanda Stouder, their colleagues and Todd Kuebelbeck. """ ######################################################################## # DONE: 1. # On Line 5 above, replace PUT_YOUR_NAME_HERE with your own name. ######################################################################## import rosegraphics as rg window = rg.TurtleWindow() # constructing a window as "window" todd = rg.SimpleTurtle() #constructing a SimpleTurtle object as assigned to "todd" and the shape is a dog todd.pen = rg.Pen('red', 5) for k in range(4): todd.pen_down() todd.draw_circle(40) todd.pen_up() todd.forward(20) window.close_on_mouse_click() ######################################################################## # DONE: 2. # Write code that constructs a SimpleTurtle with a red Pen
# (by moving, using its rg.Pen). ANYTHING is fine! # 3. Each rg.SimpleTurtle moves inside a LOOP. # # Be creative! Strive for way-cool pictures! Abstract pictures rule! # # If you make syntax (notational) errors, no worries -- get help # fixing them at either this session OR at the NEXT session. # # Don't forget to COMMIT-and-PUSH when you are done with this module. ############################################################################### import rosegraphics as rg window = rg.TurtleWindow() star = rg.SimpleTurtle() star.pen = rg.Pen('pink', 5) star.speed = 10 circle = rg.SimpleTurtle() circle.pen = rg.Pen('red', 5) circle.speed = star.speed size = 120 for k in range(10): circle.draw_circle(size) circle.pen_up() circle.left(90) circle.forward(12) circle.right(90)
# On Line 5 above, replace PUT_YOUR_NAME_HERE with your own name. ######################################################################## ######################################################################## # Done # Write code that constructs a SimpleTurtle with a red Pen # and makes it move around a bit. Don't forget to: # -- import rosegraphics and construct a TurtleWindow # at the BEGINNING of your code, and to # -- ask your TurtleWindow to close_on_mouse_click # as the LAST line of your code. # See the beginning and end of m4e_loopy_turtles for an example. # # ** Nothing fancy is required. ** # ** The NEXT exercise will let you show your creativity. ** # # As always, test by running the module. # # As always, COMMIT-and-PUSH when you are done with this module. # ############################################################################### import rosegraphics as rg window = rg.TurtleWindow() simon = rg.SimpleTurtle() simon.pen = rg.Pen('red', 3) simon.speed = 5 simon.forward(50) simon.right(90) simon.backward(100) window.close_on_mouse_click()
# 2. Each rg.SimpleTurtle object draws something # (by moving, using its rg.Pen). ANYTHING is fine! # 3. Each rg.SimpleTurtle moves inside a LOOP. # # Be creative! Strive for way-cool pictures! Abstract pictures rule! # # If you make syntax (notational) errors, no worries -- get help # fixing them at either this session OR at the NEXT session. # # Don't forget to COMMIT your work by using VCS ~ Commit and Push. ######################################################################## import rosegraphics as rg window = rg.TurtleWindow() red_turtle = rg.SimpleTurtle('turtle') red_turtle.pen = rg.Pen('red', 4) red_turtle.speed = 10 size = 300 for k in range(10): red_turtle.draw_square(size) red_turtle.pen_up() red_turtle.right(45) red_turtle.forward(10) red_turtle.left(45) red_turtle.pen_down() size = size - 45
############################################################################### # ----------------------------------------------------------------------------- # The next few lines show how to: # - CONSTRUCT (make and initialize) a TurtleWindow object for animation. # The definition of a TurtleWindow is in the rg # (shorthand for rosegraphics) module. # ----------------------------------------------------------------------------- window = rg.TurtleWindow() window.delay(20) # Bigger numbers mean slower animation. # ----------------------------------------------------------------------------- # The next few lines show how to: # - CONSTRUCT (make) a SimpleTurtle object and ASSIGN a NAME to the object. # ----------------------------------------------------------------------------- boris = rg.SimpleTurtle() # ----------------------------------------------------------------------------- # The next few lines show how to: # - Ask the SimpleTurtle object to do things by applying METHODs to it. # The numbers in the parentheses are called ARGUMENTS. # ----------------------------------------------------------------------------- boris.forward(100) boris.left(90) boris.forward(200) # ----------------------------------------------------------------------------- # The next few lines show how to: # - Construct a second SimpleTurtle, # set its pen and speed INSTANCE VARIABLES, and ask it to do things. # -----------------------------------------------------------------------------
######################################################################## # DONE: 2. # Write code that constructs a SimpleTurtle with a red Pen # and makes it move around a bit. Don't forget to: # -- import rosegraphics and construct a TurtleWindow # at the BEGINNING of your code, and to # -- ask your TurtleWindow to close_on_mouse_click # as the LAST line of your code. # See the beginning and end of m4e_loopy_turtles for an example. # # ** Nothing fancy is required. ** # ** The NEXT exercise will let you show your creativity. ** # # As always, test by running the module. # # As always, COMMIT-and-PUSH when you are done with this module. # ############################################################################### import rosegraphics as rg window = rg.TurtleWindow() window.delay(20) skovald = rg.SimpleTurtle() skovald.pen = rg.Pen('red', 30) skovald.left(120) skovald.forward(100) skovald.right(185) skovald.forward(120) skovald.left(270) skovald.forward(90) window.close_on_mouse_click()
############################################################################### # ----------------------------------------------------------------------------- # The next few lines show how to: # - CONSTRUCT (make and initialize) a TurtleWindow object for animation. # The definition of a TurtleWindow is in the rg # (shorthand for rosegraphics) module. # ----------------------------------------------------------------------------- window = rg.TurtleWindow() window.delay(20) # Bigger numbers mean slower animation. # ----------------------------------------------------------------------------- # The next few lines show how to: # - CONSTRUCT (make) a SimpleTurtle object and ASSIGN a NAME to the object. # ----------------------------------------------------------------------------- boris = rg.SimpleTurtle() # ----------------------------------------------------------------------------- # The next few lines show how to: # - Ask the SimpleTurtle object to do things by applying METHODs to it. # The numbers in the parentheses are called ARGUMENTS. # ----------------------------------------------------------------------------- boris.forward(100) boris.left(90) boris.forward(200) # ----------------------------------------------------------------------------- # The next few lines show how to: # - Construct a second SimpleTurtle, # set its pen and speed INSTANCE VARIABLES, and ask it to do things. # -----------------------------------------------------------------------------
############################################################################### # ----------------------------------------------------------------------------- # The next few lines show how to: # - CONSTRUCT (make and initialize) a TurtleWindow object for animation. # The definition of a TurtleWindow is in the rg # (shorthand for rosegraphics) module. # ----------------------------------------------------------------------------- window = rg.TurtleWindow() window.delay(20) # Bigger numbers mean slower animation. # ----------------------------------------------------------------------------- # The next few lines show how to: # - CONSTRUCT (make) a SimpleTurtle object and ASSIGN a NAME to the object. # ----------------------------------------------------------------------------- boris = rg.SimpleTurtle() # ----------------------------------------------------------------------------- # The next few lines show how to: # - Ask the SimpleTurtle object to do things by applying METHODs to it. # The numbers in the parentheses are called ARGUMENTS. # ----------------------------------------------------------------------------- boris.forward(100) boris.left(90) boris.forward(200) # ----------------------------------------------------------------------------- # The next few lines show how to: # - Construct a second SimpleTurtle, # set its pen and speed INSTANCE VARIABLES, and ask it to do things. # -----------------------------------------------------------------------------
# 3. Each rg.SimpleTurtle moves inside a LOOP. # # Be creative! Strive for way-cool pictures! Abstract pictures rule! # # If you make syntax (notational) errors, no worries -- get help # fixing them at either this session OR at the NEXT session. # # Don't forget to COMMIT-and-PUSH when you are done with this module. ############################################################################### import rosegraphics as rg window = rg.TurtleWindow() window.delay(10) alfred = rg.SimpleTurtle('turtle') alfred.pen_up() alfred.left(140) alfred.forward(450) alfred.right(140) rachel = rg.SimpleTurtle('arrow') rachel.pen_up() rachel.right(40) rachel.forward(450) rachel.right(140) jerry = rg.SimpleTurtle('square') jerry.pen_up() jerry.left(40) jerry.forward(450)
# - Makes the SimpleTurtle's pen have color 'green' and thickness 10. # # - Makes the SimpleTurtle go 150 pixels straight DOWN. # # Don't forget to: # - import rosegraphics and construct a TurtleWindow # at the BEGINNING of your code, and to # - ask your TurtleWindow to close_on_mouse_click # as the LAST line of your code. # See the beginning and end of m4e_loopy_turtles for an example. # # As always, test by running the module. # As always, COMMIT-and-PUSH when you are done with this module. # ######################################################################## import rosegraphics as rg window = rg.TurtleWindow() window.delay(30) ben = rg.SimpleTurtle('turtle') ben.pen = rg.Pen('blue', 10) ben.go_to(rg.Point(0, 200)) ben.pen_up() ben.go_to(rg.Point(100, -40)) ben.pen_down() ben.pen = rg.Pen('green', 10) ben.go_to(rg.Point(100, -140)) window.close_on_mouse_click()
* The DOT trick: Type expressions like the following, pausing after typing the DOT (period, full stop). The window that pops up give lots of clues for what you can do! rg. rg.SimpleTurtle(). rg.Pen(). rg.PaintBucket() Authors: David Mutchler, Dave Fisher, Valerie Galluzzi, Amanda Stouder, and their colleagues. """ import rosegraphics as rg window = rg.TurtleWindow() blue_turtle = rg.SimpleTurtle('turtle') blue_turtle.pen = rg.Pen('midnight blue', 3) blue_turtle.speed = 10 # Fast # The first square will be 300 x 300 pixels: size = 300 # Do the indented code 13 times. Each time draws a square. for k in range(13): # Put the pen down, then draw a square of the given size: blue_turtle.draw_square(size) # Move a little below and to the right of where the previous # square started. Do this with the pen up (so nothing is drawn). blue_turtle.pen_up()
############################################################################### # ----------------------------------------------------------------------------- # The next few lines show how to: # - CONSTRUCT (make and initialize) a TurtleWindow object for animation. # The definition of a TurtleWindow is in the rg # (shorthand for rosegraphics) module. # ----------------------------------------------------------------------------- window = rg.TurtleWindow() window.delay(20) # Bigger numbers mean slower animation. # ----------------------------------------------------------------------------- # The next few lines show how to: # - CONSTRUCT (make) a SimpleTurtle object and ASSIGN a NAME to the object. # ----------------------------------------------------------------------------- boris = rg.SimpleTurtle() # ----------------------------------------------------------------------------- # The next few lines show how to: # - Ask the SimpleTurtle object to do things by applying METHODs to it. # The numbers in the parentheses are called ARGUMENTS. # ----------------------------------------------------------------------------- boris.forward(100) boris.left(90) boris.forward(200) # ----------------------------------------------------------------------------- # The next few lines show how to: # - Construct a second SimpleTurtle, # set its pen and speed INSTANCE VARIABLES, and ask it to do things. # -----------------------------------------------------------------------------
# Then look at the code below. Raise your hand as you have questions # about what the code is doing. # ######################################################################## # ---------------------------------------------------------------------- # Set up a TurtleWindow object for animation. The definition of a # TurtleWindow is in the rg (shorthand for rosegraphics) module. # ---------------------------------------------------------------------- window = rg.TurtleWindow() window.delay(20) # Bigger numbers mean slower animation. # ---------------------------------------------------------------------- # Makes (constructs) a SimpleTurtle object. # ---------------------------------------------------------------------- dave = rg.SimpleTurtle() # ---------------------------------------------------------------------- # Ask the SimpleTurtle objects to do things: # ---------------------------------------------------------------------- dave.forward(100) dave.left(90) dave.forward(200) # ---------------------------------------------------------------------- # Construct a new turtle and ask it to do things. # ---------------------------------------------------------------------- matt = rg.SimpleTurtle('turtle') matt.pen = rg.Pen('red', 30) matt.speed = 10 # Faster matt.backward(50)
# Then look at the code below. Raise your hand as you have questions # about what the code is doing. # ######################################################################## # ---------------------------------------------------------------------- # Set up a TurtleWindow object for animation. The definition of a # TurtleWindow is in the rg (shorthand for rosegraphics) module. # ---------------------------------------------------------------------- window = rg.TurtleWindow() window.delay(20) # Bigger numbers mean slower animation. # ---------------------------------------------------------------------- # Makes (constructs) a SimpleTurtle object. # ---------------------------------------------------------------------- dave = rg.SimpleTurtle() # ---------------------------------------------------------------------- # Ask the SimpleTurtle objects to do things: # ---------------------------------------------------------------------- dave.forward(100) dave.left(90) dave.forward(200) # ---------------------------------------------------------------------- # Construct a new turtle and ask it to do things. # ---------------------------------------------------------------------- matt = rg.SimpleTurtle('turtle') matt.pen = rg.Pen('red', 30) matt.speed = 10 # Faster matt.backward(50)
############################################################################### # ----------------------------------------------------------------------------- # The next few lines show how to: # - CONSTRUCT (make and initialize) a TurtleWindow object for animation. # The definition of a TurtleWindow is in the rg # (shorthand for rosegraphics) module. # ----------------------------------------------------------------------------- window = rg.TurtleWindow() window.delay(20) # Bigger numbers mean slower animation. # ----------------------------------------------------------------------------- # The next few lines show how to: # - CONSTRUCT (make) a SimpleTurtle object and ASSIGN a NAME to the object. # ----------------------------------------------------------------------------- boris = rg.SimpleTurtle() # ----------------------------------------------------------------------------- # The next few lines show how to: # - Ask the SimpleTurtle object to do things by applying METHODs to it. # The numbers in the parentheses are called ARGUMENTS. # ----------------------------------------------------------------------------- boris.forward(100) boris.left(90) boris.forward(200) # ----------------------------------------------------------------------------- # The next few lines show how to: # - Construct a second SimpleTurtle # (using an optional argument that sets the shape displayed - try it!), # set its pen and speed INSTANCE VARIABLES, and ask it to do things.
# 2. Each rg.SimpleTurtle object draws something # (by moving, using its rg.Pen). ANYTHING is fine! # 3. Each rg.SimpleTurtle moves inside a LOOP. # # Be creative! Strive for way-cool pictures! Abstract pictures rule! # # If you make syntax (notational) errors, no worries -- get help # fixing them at either this session OR at the NEXT session. # # Don't forget to COMMIT-and-PUSH when you are done with this module. ############################################################################### import rosegraphics as rg window = rg.TurtleWindow() turtle1 = rg.SimpleTurtle('turtle') turtle1.pen = rg.Pen('purple', 5) turtle1.speed = 15 size = 300 for k in range(12): turtle1.draw_regular_polygon(3, size) turtle1.pen_up() turtle1.right(45) turtle1.forward(10) turtle1.left(45) turtle1.pen_down() size = size - 15 window.close_on_mouse_click()
# Then look at the code below. Raise your hand as you have questions # about what the code is doing. # ######################################################################## # ---------------------------------------------------------------------- # Set up a TurtleWindow object for animation. The definition of a # TurtleWindow is in the rg (shorthand for rosegraphics) module. # ---------------------------------------------------------------------- window = rg.TurtleWindow() window.delay(10) # Bigger numbers mean slower animation. # ---------------------------------------------------------------------- # Makes (constructs) a SimpleTurtle object. # ---------------------------------------------------------------------- dave = rg.SimpleTurtle("turtle") matt = rg.SimpleTurtle() # ---------------------------------------------------------------------- # Ask the SimpleTurtle objects to do things: # ---------------------------------------------------------------------- dave.forward(100) dave.left(90) dave.forward(200) dave.backward(50) dave.right(70) # ---------------------------------------------------------------------- # Construct a new turtle and ask it to do things. # ---------------------------------------------------------------------- matt = rg.SimpleTurtle('turtle') matt.pen = rg.Pen('blue', 15)
# Write code that constructs a SimpleTurtle with a red Pen # and makes it move around a bit. Don't forget to: # -- import rosegraphics and construct a TurtleWindow # at the BEGINNING of your code, and to # -- ask your TurtleWindow to close_on_mouse_click # as the LAST line of your code. # See the beginning and end of m4e_loopy_turtles for an example. # # ** Nothing fancy is required. ** # ** The NEXT exercise will let you show your creativity. ** # # As always, test by running the module. # # As always, COMMIT-and-PUSH when you are done with this module. # ############################################################################### import rosegraphics as rg window = rg.TurtleWindow() window.delay(20) tom = rg.SimpleTurtle() tom.pen = rg.Pen('red', 15) tom.forward(100) tom.right(90) tom.backward(70) window.close_on_mouse_click()
def try_methods_and_functions(): """ Constructs a SimpleTurtle and sets its pen to a new rg.Pen that is 'blue' with thickness 5. Then makes the SimpleTurtle do the following (in the order listed): 1. Go backward 150 units. 2. Change its speed to 1 (slowest). Draw 2 squares whose size (width and height) are 100, each "twisted" from the previous by 30 degrees. 3. Change its speed to 5 (faster). Change its Pen's color to 'red'. Draw 10 squares whose size (width and height) are 50, each "twisted" from the previous by 15 degrees. 4. Change its speed to 100 (about the fastest possible). Change its Pen's thickness to 35. Draw 8 squares whose size (width and height) are 300, each "twisted" from the previous by 60 degrees. 5. Changes its Pen to be a NEW Pen whose color is 'black' and whose thickness is 3. 6. Goes backward 200 units. 7. Draw a CIRCLE whose radius is 30. 8. Draw a SQUARE whose sides are each of length 50. """ #################################################################### # DONE: 5. Implement this function, per its doc-string above. # Put a statement in main to test this function # (by calling this function). IMPORTANT, IMPORTANT, IMPORTANT: # Keep reading the rest of this TO DO before doing the above! # # IMPORTANT: This function should ** CALL ** the # draw_many_squares # function defined above. If you don't see why, ** ASK FOR HELP. ** # #################################################################### angle = rg.SimpleTurtle() angle.pen = rg.Pen('blue', 5) angle.backward(150) angle.speed = 1 draw_many_squares(angle, 2, 100, 30) angle.speed = 5 angle.pen = rg.Pen('red', 5) draw_many_squares(angle, 10, 50, 15) angle.speed = 100 angle.pen = rg.Pen('red', 35) draw_many_squares(angle, 8, 300, 60) angle.pen = rg.Pen('black', 3) angle.backward(200) angle.draw_circle(30) angle.draw_square(50)
############################################################################### # ----------------------------------------------------------------------------- # The next few lines show how to: # - CONSTRUCT (make and initialize) a TurtleWindow object for animation. # The definition of a TurtleWindow is in the rg # (shorthand for rosegraphics) module. # ----------------------------------------------------------------------------- window = rg.TurtleWindow() window.delay(20) # Bigger numbers mean slower animation. # ----------------------------------------------------------------------------- # The next few lines show how to: # - CONSTRUCT (make) a SimpleTurtle object and ASSIGN a NAME to the object. # ----------------------------------------------------------------------------- boris = rg.SimpleTurtle() # ----------------------------------------------------------------------------- # The next few lines show how to: # - Ask the SimpleTurtle object to do things by applying METHODs to it. # The numbers in the parentheses are called ARGUMENTS. # ----------------------------------------------------------------------------- boris.forward(100) boris.left(90) boris.forward(200) # ----------------------------------------------------------------------------- # The next few lines show how to: # - Construct a second SimpleTurtle, # set its pen and speed INSTANCE VARIABLES, and ask it to do things. # -----------------------------------------------------------------------------