Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
900 views

Python Turtle Cheat Sheet: Start Up Turtle Change Your Pen Colour & Size

This document provides a cheat sheet for using the Python turtle module. It outlines how to initialize the turtle window and create a turtle object. It then describes various turtle methods for drawing, changing the pen color and size, and moving the turtle to different coordinates and headings. The cheat sheet also mentions using help functions to view other available turtle methods.

Uploaded by

a
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
900 views

Python Turtle Cheat Sheet: Start Up Turtle Change Your Pen Colour & Size

This document provides a cheat sheet for using the Python turtle module. It outlines how to initialize the turtle window and create a turtle object. It then describes various turtle methods for drawing, changing the pen color and size, and moving the turtle to different coordinates and headings. The cheat sheet also mentions using help functions to view other available turtle methods.

Uploaded by

a
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Python Turtle Cheat Sheet

Start up turtle Change your pen colour & size


import turtle #go get the turtle module myTurtle.up() # put myTurtle's pen in the up position -- myTurtle won’t draw lines
wn = turtle.Screen() # create a turtle window myTurtle.down() # put myTurtle's pen in the down position -- myTurtle will draw lines
myTurtle = turtle.Turtle() # create a turtle name 'myTurtle' myTurtle.pensize(10) #Change the width of the pen

myTurtle.pencolor("blue") # Change the pen colour to blue


Draw with your turtle myTurtle.pencolor(“#33CC8C” ) # Change the pen colour to hex colour value
myTurtle.forward(dist) # move myTurtle 'dist' in the direction it's facing
myTurtle.pencolor(255,0,0) #Change pen colour to a RGB values.
myTurtle.backward(dist) # move myTurtle 'dist' in the direction opposite to where
it's facing This is either (0-255) or (0-1.0), depending on the colormode() set.
myTurtle.right(deg) # turn myTurtle 'deg' degrees to the right wn.colormode(255) # set the colormode to 255 / 1
myTurtle.left(deg) # turn myTurtle ‘deg’ degrees to the left
wn.bgcolor("lightgreen") # Change the screen’s background colour
myTurtle.dot() # Draw a dot under the myTurtle

Top tip - Use the shortcuts myTurtle.fd(), myTurtle.bd(),

myTurtle.rt() Other functions


myTurtle.delay(0) # Speed up turtle when drawing
Coordinates and direction
myTurtle.home() # Move the turtle back to the centre of the screen
x = myTurtle.xcor() #store myTurtle’s x-coordinate location in the x variable
y = myTurtle.ycor() #store myTurtle’s y-coordinate location in the y variable myTurtle.reset() # Clear the whole widow and start from scratch

myTurtle.setx(pos) # set myTurtle’s x pos wn.exitonclick() # Wait for the user to click on the window to close it
myTurtle.sety(pos) # set myTurtle’s y pos
Want to know more? Use help(turtle), help(wn) and help(myTurtle) to
dir = myTurtle.heading() # stores myTurtle’s heading in the dir variable
have a look at the other methods available.
myTurtle.setheading(dir) # sets myTurtle’s heading

You might also like