Lab 6: Drawing with Functions

Use turtle graphics in our BTT CS 111 replit ( bit.ly/replitcs111 ) to draw squares using functions with parameters.

At the end of lab take a screen of your completed work paste it onto your group's page in today's shared google slides. Include a screen shot of the graphics as well as pasting the text of only the functions you implemented (not the rest of the program).

  • Results of running all six functions are shown at left.

  • You should implement the functions one at a time.

  • You may not have time to get to the last two, which is why they are considered extra credit.

Getting Started Python Code for the Lab (access on the replit site)

"""

Lab 6: Use a function to draw multiple squares. Take screen shots and store

the results from each step on your slide in the shared google slides deck.

Each implemented function is worth half a point.


See the Lab 6 Description on the course website at:

https://sites.google.com/view/bttcs111sp22/labs/lab-6-drawing-with-functions

See a summary of basic turtle commands on the course website at:

https://sites.google.com/view/bttcs111sp22/tools/turtle-graphics


Check out the official turtle graphics docs at:

https://docs.python.org/3/library/turtle.html

"""


import turtle # Do not remove this line

t = turtle.Turtle() # Do not remove this line

t.speed( 0)


# Set the starting location for drawings

x = -300

y = 300


# Move the turtle to the next drawing location by changing

# the global (shared) x,y values and moving the turtle there.

# Don't change this function.

def nextSpot( ):

global x,y # Change the shared global x,y values

t.penup()

x += 50

y -= 50

t.setposition(x, y)

t.pendown()


# --------------- Your changes should be below this line ---------------

# Draw a square using eight individual t.forward() and t.left() instructions

def square_original():

pass # Delete this line and put your code here


# Draw a square using the two t.forward() and t.left() instructions in a loop

def square_with_loop():

pass # Delete this line and put your code here


# Draw a square where the size of a side is a parameter

def square_with_size( size):

pass # Delete this line and put your code here


# Draw four squares, rotating left 90 degrees between each one

# (Hint: call the square_with_size() function you just wrote)

def rotate_four_squares( size):

pass # Delete this line and put your code here


# Draw some number of squares, rotating left some amount between each one

def rotate_some_squares( size, how_many, rotation):

pass # Delete this line and put your code here


# Draw some number of squares, rotating left some amount between each one

def rotate_squares_and_grow( size, size_increment, how_many, rotation):

pass # Delete this line and put your code here


# -------------------------- Main part of program ---------------------

# Don't change anything below this line.

t.color("black")

nextSpot( ) # Move the turtle to the next drawing position

square_original() # Draw a black square using a list of 8 instructions


t.color("blue")

nextSpot( ) # Move the turtle to the next drawing position

square_with_loop() # Draw a square, using 2 instructions in a loop


t.color("red")

nextSpot( ) # Move the turtle to the next drawing position

# Draw two squares, using a parameter for size

square_with_size( 20)

square_with_size( 40)


t.color("green")

nextSpot( ) # Move the turtle to the next drawing position

# Draw four squares of the given size, rotating left 90 degrees between them.

rotate_four_squares( 40)


t.color("dark orchid") # Color list is at tcl.tk/man/tcl8.5/TkCmd/colors.html

nextSpot( ) # Move the turtle to the next drawing position

nextSpot( ) # Move the turtle to the next drawing position

# Draw some number of squares, rotating between them.

# Send the size, number of squares, degrees to rotate left between each one

rotate_some_squares( 40, 10, 360/10)


t.color("turquoise") # Color list is at tcl.tk/man/tcl8.5/TkCmd/colors.html

nextSpot( ) # Move the turtle to the next drawing position

nextSpot( ) # Move the turtle to the next drawing position

# Draw four squares, rotating between them

# Send the size, size increment, number of squares, and the

# degrees to rotate left between each one.

rotate_squares_and_grow( 4, 4, 36, 10)