CSCI 1170 with Bucher OLA 5: Reviewing Functions with Turtle

CSCI 1170 with Bucher
OLA 5: Reviewing Functions with Turtle graphics
Due: Monday, April 6th by midnight, as day turns into Tuesday (WILL NOT BE ACCEPTED LATE)
Turnin Assignment id code: ola5program
Lab description:
The purpose of this lab is to help review creating a full program that contains multiple functions. You
will need to call these functions correctly in the main() function. Below are two sample runs of the
program you are to create.
Some things we have learned about the Turtle graphics:
import turtle
wn = turtle.Screen()
wn.bgcolor("black")
sam = turtle.Turtle()
sam.speed(200)
sam.pensize(3)
sam.color("lightblue")
#loads all the Turtle functions
#creates a variable for the Turtle window
#set the background color of the window
#creates and names the drawing turtle sam
#changes the speed of sam
#changes the width of the line sam draws
#changes the color of sam's lines
Full turtle documentation is here: https://docs.python.org/3.0/library/turtle.html
Here are some more important functions and some fun ones you might experiment with:
sam.forward(50)
sam.right(90)
sam.left(60)
sam.penup()
sam.pendown()
sam.goto(150, 150)
#moves sam straight distance of 50
#turns sam 90 degrees to the right
#turns sam 60 degrees to the left
#raises drawing marker
#lowers drawing marker
#moves sam 150 to right and 150 up
sam.setposition(100, 100) #moves sam to an absolute position, center is 0,0
sam.dot(20, "white") #sam can draw a filled circle of diameter 20
sam.shape("turtle")
#you can change the turtle’s shape
Every turtle can have its own shape. The ones available “out of the box”
are arrow, blank, circle, classic, square, triangle, turtle. The default is
classic
sam.stamp()
#sam can leave his shape stamped on screen
How to draw a star:
You should turn the turtle by 144 degrees at each point. The length of each line should be
the same.
Lab Requirements:


Your program MUST contain at least these 3 functions called: main(), drawStar(), and
setRandomPosition()
The function heading for main will look like this:
def main():








The function heading for drawStar() will look like this:
def drawStar(who,size):
where who is a parameter that will represent the name of the turtle and size is how big to draw
the star. This function’s purpose is to draw one star.
The function heading for setRandomPosition() will look like this:
def setRandomPosition(who):
where who is a parameter that will represent the name of the turtle
This function’s purpose is to move the turtle to a random position
You will interact with the user in the main() function
You will allow the user to choose how many stars they want drawn
You will then allow the user to choose if they want the stars all the same size, if they type y for
yes you will then ask the user what size they want the stars; if they type n for no you will draw
each star a random size (from about 20 to 200 seems to work well).
The stars will always be drawn at random positions. (0,0) is the center of the Turtle window, so
pick random positions for x from -300 to 300 and also for y , -300 to 300.
Be sure to include wn.exitonclick() at the bottom of your main() function so your picture will
stay on the screen until it is closed!
Your program must meet these requirements but feel free to add anything else, such as
changing colors or other drawn items to enhance the picture.
Remember to never change the default password for your class account, or share it!
OLA assignments are to be done on your own, on your own time. Help may only come from your
instructor, your GTA, the help desk workers, or other faculty, NOT from other students.
Remember, OLA assignments are 20% of your grade and you must not miss three or more.
Once logged into Ranger: Go to the terminal (ranger$ prompt) and type in idle3 &
Once in idle, go to File to New File and type in your python script here. Save the file as ola5.py and you
may want to save it inside the OLA directory.
Your program must include the following comments at the top:
#
#
#
#
Your Name
csci 1170-00x , replace x with your section number
ola5
Short description of program
Once you have finished the program and tested it to make sure it runs correctly, then go Back to the
Linux ranger$ prompt, type in ls (for list) to make sure your python file is listed in this directory. If not
you may need to change directory, such as cd OLA. (If you can’t type in anything at the ranger$ prompt
you will have to close the IDLE scripting window and the IDLE shell window)
You will not need to create a script log this time.
You will Submit the one program file using the turnin program at the ranger$ prompt. Be sure to watch
for the word SUBMITTED to know that it worked! Again, if your file is named differently, be sure to
replace with your correct filename.
turnin rbucher ola5program ola5.py