Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # import turtle library
- import turtle
- ''' global Constants and variables'''
- XOFFSET = 12 # Do not change margin offsets
- YOFFSET = 14 # Do not change margin offsets
- NORTH = 90
- EAST = 0
- SOUTH = 270
- WEST = 180
- width = 300 # Width of window drawing area
- height = 300 # height of window drawing area
- '''
- example: turtle.setheading(NORTH)
- '''
- def reposition(pen, position):
- ''' Moves the turtle to one of the window corners '''
- pen.pu()
- if position == "topright":
- pen.setpos(width * 0.5 - XOFFSET * 0.2, height * 0.5 + YOFFSET * 0.2)
- elif position == "topleft":
- pen.setpos(-width * 0.5 - XOFFSET * 0.2, height * 0.5 + YOFFSET * 0.2)
- elif position == "bottomright":
- pen.setpos(width * 0.5 - XOFFSET * 0.2, -height * 0.5 + YOFFSET * 0.2)
- elif position == "bottomleft":
- pen.setpos(-width * 0.5 - XOFFSET * 0.2, -height * 0.5 + YOFFSET * 0.2)
- pen.pd()
- def main():
- global width, height # allow changing value of width and height
- ''' Set Window size and background colour '''
- width = 400 # set window width here
- height = 400 # set window height here
- window = turtle.Screen() # create a window
- window.setup(width + XOFFSET, height + YOFFSET) # allow for title and borders
- turtle.colormode(255)
- turtle.bgcolor((200, 255, 255)) # change background colour
- ''' example for green arrow shaped turtle facing east top left corner '''
- fred = turtle.Pen() # create a new turtle called 'fred'
- fred.shape('arrow') # choose 'arrow', 'turtle', 'circle', 'square'. 'triangle', 'classic'
- fred.color('green') # set colour to green
- ''' add your code here '''
- # reposition(fred, 'topleft') # set position to top left of the window
- # fred.setheading(EAST) # set to face east
- turtle.done() # MUST BE LAST STATEMENT!
- main()
Add Comment
Please, Sign In to add comment