Docsity

Método Turtle no Python, Manuais, Projetos, Pesquisas de Programação Orientada a Objetos

Toggle sidebar
bg1
!
Python Turtle Cheat Sheets
Movement
Some other useful commands
Getting ready to draw
import turtle
Make all the turtle commands available to your program
turtle.mode(‘logo’)
Set the mode
turtle.speed(integer)
Set the animation speed of the turtle. 1 = slowest, 10 = fastest.
0 turns off animation completely
turtle.shape(‘turtle’)
Set the shape. You can also choose from:
arrow, square, circle, triangle and classic
turtle.forward(distance)
turtle.backward(distance)
turtle.right(angle)
turtle.left(angle)
turtle.home()
turtle.goto(x, y)
turtle.setheading(degrees)
An example:
import turtle!
!
turtle.mode('logo')!
turtle.speed(10)!
turtle.shape('turtle')!
!
# Draw a square!
turtle.forward(100)!
turtle.right(90)!
turtle.forward(100)!
turtle.right(90)!
turtle.forward(100)!
turtle.right(90)!
turtle.forward(100)
x, y = turtle.pos()
Sets the variables x and y to the turtle’s current position
turtle.resizemode(‘auto’)
Use this command at the start of your program to change the size of
the turtle when the pen size changes. Useful for stamping!
turtle.circle(radius)
Draw a circle with the given radius (a number). radius can be negative.
turtle.circle(radius, angle)
Draw a part of a circle with radius. The angle denotes how much of the
circle is drawn. For example, if angle is 180 then a semicircle will be
drawn. angle can be negative.
Use these
statements at the
start of every
program
pf3
pf4
pf5

Pré-visualização parcial do texto

Baixe Método Turtle no Python e outras Manuais, Projetos, Pesquisas em PDF para Programação Orientada a Objetos, somente na Docsity!

Python Turtle Cheat Sheets

Movement

Some other useful commands

Getting ready to draw

import turtle Make all the turtle commands available to your program

turtle.mode(‘logo’) Set the mode

turtle.speed( integer ) Set the animation speed of the turtle. 1 = slowest, 10 = fastest.

0 turns off animation completely

turtle.shape(‘turtle’) Set the shape. You can also choose from:

arrow , square , circle , triangle and classic

turtle.forward( distance ) Go forwards by amount distance

turtle.backward( distance ) Go backwards by amount distance

turtle.right( angle ) Turn right by angle degrees

turtle.left( angle ) Turn left by angle degrees

turtle.home() Go home (0, 0) and face north

turtle.goto( x , y ) Go to position x , y

turtle.setheading( degrees ) Point in compass direction degrees. 0

is north, 90 is east, 180 is south, 270 is

west

An example:

import turtle turtle.mode('logo') turtle.speed( 10 ) turtle.shape('turtle')

Draw a square

turtle.forward( 100 ) turtle.right( 90 ) turtle.forward( 100 ) turtle.right( 90 ) turtle.forward( 100 ) turtle.right( 90 ) turtle.forward( 100 )

x , y = turtle.pos() Sets the variables x and y to the turtle’s current position

turtle.resizemode(‘auto’) Use this command at the start of your program to change the size of

the turtle when the pen size changes. Useful for stamping!

turtle.circle( radius ) Draw a circle with the given radius (a number). radius can be negative.

turtle.circle( radius, angle ) Draw a part of a circle with radius. The angle denotes how much of the

circle is drawn. For example, if angle is 180 then a semicircle will be

drawn. angle can be negative.

Use these

statements at the

start of every

program

Time to paint!

turtle.begin_fill() Use this command before you start drawing the shape you want to

be filled

turtle.end_fill() Use this command when you have finished drawing the shape to be

filled.

turtle.pendown() Put the pen down to draw

turtle.penup() ‘Lift’ the pen from the screen

turtle.pensize( integer ) Set the size of the pen to the given integer.

turtle.pencolor( string ) Set the pen colour to the string given. Note the American spelling.

turtle.fillcolor( string ) Set the fill colour to the string given. See list of colours below.

turtle.color( string ) Set both the fill colour and pen colour to given string.

turtle.color( string1 , string2 ) Set the pen and fill colour at the same time. String1 should be the

name of the pen colour, and string2 is the fill colour.

Stamplicious

turtle.stamp() Stamp the current turtle shape onto the

screen.

turtle.clearstamps() Clear all of the stamps on the screen.

stampID = turtle.stamp() Stamps the turtle onto the screen, and sets

the variable stampID to an integer, unique to

each stamp.

turtle.clearstamp( stampID ) Clear the stamp with the given stampID

number.

Line of random stamps

import turtle import random random.seed() turtle.mode('logo') turtle.speed( 10 ) turtle.resizemode('auto') myColourList = ['red', 'black', 'orange', 'blue', 'purple'] myShapeList = ['turtle', 'arrow', 'square', 'circle', 'triangle', 'classic'] def makeStamp (): turtle.setheading(random.randint( 1 , 360 )) turtle.pensize(random.randint( 1 , 7 )) turtle.color(random.choice(myColourList)) turtle.shape(random.choice(myShapeList)) turtle.stamp()

Main program

turtle.penup() for i in range( 10 ): makeStamp() turtle.setheading( 90 ) turtle.forward( 50 )

C O L O U R L I S T chartreuse2 DarkOrchid4 goldenrod2 LightBlue chartreuse3 DarkRed goldenrod3 LightBlue AliceBlue chartreuse4 DarkSalmon goldenrod4 LightBlue AntiqueWhite chocolate DarkSeaGreen green LightCoral AntiqueWhite1 chocolate1 DarkSeaGreen1 green1 LightCyan AntiqueWhite2 chocolate2 DarkSeaGreen2 green2 LightCyan AntiqueWhite3 chocolate3 DarkSeaGreen3 green3 LightCyan AntiqueWhite4 chocolate4 DarkSeaGreen4 green4 LightCyan aquamarine coral DarkSlateBlue GreenYellow LightCyan aquamarine1 coral1 DarkSlateGray grey LightGoldenrod aquamarine2 coral2 DarkSlateGray1 greyX aquamarine3 coral3 DarkSlateGray2 honeydew LightGoldenrod aquamarine4 coral4 DarkSlateGray3 honeydew1 LightGoldenrod azure CornflowerBlue DarkSlateGray4 honeydew2 LightGoldenrod azure1 cornsilk DarkSlateGrey honeydew3 LightGoldenrod azure2 cornsilk1 DarkTurquoise honeydew4 LightGreen azure3 cornsilk2 DarkViolet HotPink LightGrey azure4 cornsilk3 DeepPink HotPink1 LightPink beige cornsilk4 DeepPink1 HotPink2 LightPink bisque cyan DeepPink2 HotPink3 LightPink bisque1 cyan1 DeepPink3 HotPink4 LightPink bisque2 cyan2 DeepPink4 IndianRed LightPink bisque3 cyan3 DeepSkyBlue IndianRed1 LightSalmon bisque4 cyan4 DeepSkyBlue1 IndianRed2 LightSalmon black DarkBlue DeepSkyBlue2 IndianRed3 LightSalmon blanchedalmond DarkCyan DeepSkyBlue3 IndianRed4 LightSalmon BlanchedAlmond DarkGoldenrod DeepSkyBlue4 ivory LightSalmon blue DarkGoldenrod1 DimGray ivory1 LightSeaGreen blue1 DarkGoldenrod2 DimGrey ivory2 LightSkyBlue blue2 DarkGoldenrod3 DodgerBlue ivory3 LightSkyBlue blue3 DarkGoldenrod4 DodgerBlue1 ivory4 LightSkyBlue blue4 DarkGray DodgerBlue2 khaki LightSkyBlue BlueViolet DarkGreen DodgerBlue3 khaki1 LightSkyBlue brown DarkGrey DodgerBlue4 khaki2 LightSlateBlue brown1 DarkKhaki firebrick khaki3 LightSlateGrey brown2 DarkMagenta firebrick1 khaki4 LightSteelBlue brown3 DarkOliveGreen firebrick2 lavender LightSteelBlue brown4 DarkOliveGreen1 firebrick3 LavenderBlush LightSteelBlue burlywood DarkOliveGreen2 firebrick4 LavenderBlush1 LightSteelBlue burlywood1 DarkOliveGreen3 FloralWhite LavenderBlush2 LightSteelBlue burlywood2 DarkOliveGreen4 ForestGreen LavenderBlush3 LightYellow burlywood3 DarkOrange gainsboro LavenderBlush4 LightYellow burlywood4 DarkOrange1 GhostWhite LawnGreen LightYellow CadetBlue DarkOrange2 gold LemonChiffon LightYellow CadetBlue1 DarkOrange3 gold1 LemonChiffon1 LightYellow CadetBlue2 DarkOrange4 gold2 LemonChiffon2 LimeGreen CadetBlue3 DarkOrchid gold3 LemonChiffon3 linen CadetBlue4 DarkOrchid1 gold4 LemonChiffon4 magenta chartreuse DarkOrchid2 goldenrod LightBlue magenta chartreuse1 DarkOrchid3 goldenrod1 LightBlue1 magenta X can be any integer between 1 & 100

magenta3 OrangeRed1 red2 snow magenta4 OrangeRed2 red3 snow maroon OrangeRed3 red4 SpringGreen maroon1 OrangeRed4 RosyBrown SpringGreen maroon2 orchid RosyBrown1 SpringGreen maroon3 orchid1 RosyBrown2 SpringGreen maroon4 orchid2 RosyBrown3 SpringGreen MediumAquamarine orchid3 RosyBrown4 SteelBlue MediumBlue orchid4 RoyalBlue SteelBlue MediumOrchid PaleGoldenrod RoyalBlue1 SteelBlue MediumOrchid1 PaleGreen RoyalBlue2 SteelBlue MediumOrchid2 PaleGreen1 RoyalBlue3 SteelBlue MediumOrchid3 PaleGreen2 RoyalBlue4 tan MediumOrchid4 PaleGreen3 SaddleBrown tan MediumPurple PaleGreen4 salmon tan MediumPurple1 PaleTurquoise salmon1 tan MediumPurple2 PaleTurquoise1 salmon2 tan MediumPurple3 PaleTurquoise2 salmon3 thistle MediumPurple4 PaleTurquoise3 salmon4 thistle MediumSeaGreen PaleTurquoise4 SandyBrown thistle MediumSlateBlue PaleVioletRed SeaGreen thistle MediumSpringGreen PaleVioletRed1 SeaGreen1 thistle MediumTurquoise PaleVioletRed2 SeaGreen2 tomato MediumVioletRed PaleVioletRed3 SeaGreen3 tomato MidnightBlue PaleVioletRed4 SeaGreen4 tomato MintCream PapayaWhip seashell tomato MistyRose PeachPuff seashell1 tomato MistyRose1 PeachPuff1 seashell2 turquoise MistyRose2 PeachPuff2 seashell3 turquoise MistyRose3 PeachPuff3 seashell4 turquoise MistyRose4 PeachPuff4 sienna turquoise moccasin peru sienna1 turquoise NavajoWhite pink sienna2 violet NavajoWhite1 pink1 sienna3 VioletRed NavajoWhite2 pink2 sienna4 VioletRed NavajoWhite3 pink3 SkyBlue VioletRed NavajoWhite4 pink4 SkyBlue1 VioletRed NavyBlue plum SkyBlue2 VioletRed OldLace plum1 SkyBlue3 wheat OliveDrab plum2 SkyBlue4 wheat OliveDrab1 plum3 SlateBlue wheat OliveDrab2 plum4 SlateBlue1 wheat OliveDrab3 PowderBlue SlateBlue2 wheat OliveDrab4 purple SlateBlue3 white orange purple1 SlateBlue4 WhiteSmoke orange1 purple2 SlateGrey yellow orange2 purple3 snow yellow orange3 purple4 snow1 yellow orange4 red snow2 yellow OrangeRed red1 snow3 yellow YellowGreen