I am supposed to define a function, movingTurtle, that uses the Python turtle module, sets the turtle to an actual turtle shape, and moves that turtle up from the bottom of the screen towards the top, getting smaller as it moves along. Here is the code I currently have:
def movingTurtle(mTurtle, window):
'''
Create turtle that is the shape of an actual
turtle, then have it move from the bottom of screen
to the top, getting smaller as it moves along its path
'''
width = window.window_width()
height = window.window_height()
bottom = -height/2
top = height/2
mTurtle.shape("turtle")
mTurtle.penup()
mTurtle.setposition(0, bottom)
x = int(height/10)
y = int(height/10)
z = int(height/10)
for i in range(bottom, top):
mTurtle.setposition(0, i)
#x -= .1
#y -= .1
#z -= .1
#mTurtle.shapesize(x, y, z)
def main():
# set window size
width = int(input('Enter the width of the screen: '))
height = int(input('Enter the height of the screen: '))
turtle.setup(width,height)
print('='*50)
#========================================================
# get reference to turtle window
window = turtle.Screen()
# set window title bar
window.title('Lab20 - Turtle Object')
#========================================================
# Moving turtle
mTurtle = turtle.Turtle()
# function call
try:
movingTurtle(mTurtle,window)
except:
print('movingTurtle is not either defined or there is a',
'problem with the function')
#========================================================
main()
(The reason for the main() part is because I actually have several other functions - this is for a project)
Even with the bottom four lines commented out, I can't even get the turtle to move from the top to the bottom. At first, I had:
for i in range(-height, height):
mTurtle.setposition(0, i)
etc.
But I realized that that made it so that the turtle started way further down than the actual size of the window, I needed to cut that size in half. But when I had that code, the turtle did move from bottom to top at least.
I tried to put in for i in range(-height/2, height/2) and that's when my turtle stopped appearing at all.
So, then I tried to hold those values in the variables bottom and top, thinking that maybe for some reason I couldn't put them in the range parameters? For some reason this isn't working and I'm not sure why.
Before, when my turtle was moving from bottom to top, the last 4 lines were shrinking it, but it would get so small it would disappear by the time it reached the middle of the screen. I think this was because I didn't have the height divided by two.