xxxxxxxxxx
#import turtle
import turtle
b=turtle.Pen()
b.speed(50)
for i in range(4):
for i in range(4):
for i in range(4):
for i in range(8):
for i in range(3):
for i in range(6):
b.fd(10)
b.lt(60)
b.lt(120)
b.fd(30)
for i in range(2):
b.lt(90)
b.fd(30)
b.lt(-90)
b.fd(10)
b.lt(90)
b.fd(200)
b.lt(90)
xxxxxxxxxx
import turtle
colors = ['red', 'purple', 'blue', 'green', 'orange', 'yellow']
t = turtle.Pen()
turtle.bgcolor('black')
for x in range(360):
t.pencolor(colors[x%6])
t.width(x//100 + 1)
t.forward(x)
t.left(59)
xxxxxxxxxx
# Python program to draw square
# using Turtle Programming
import turtle
skk = turtle.Turtle()
for i in range(4):
skk.forward(50)
skk.right(90)
turtle.done()
xxxxxxxxxx
"""
TURTLE COMMANDS
command shortcut makes the turtle """
goto(x, y) setpos(x, y) # go to x, y coordinates
forward(d) fd(d) # go forward d units
back(d) bk(d) # go backward d units
left(a) lt(a) # rotate left a degrees
right(a) rt(a) # rotate right a degrees
setheading(h) seth(h) # set heading to h degrees
write(text) # write text in the screen
xxxxxxxxxx
import turtle # imports it
whateverYouWantToCallIt = turtle.Turtle() # adds it to the project
#code
whateverYouWantToCallIt.forward(10) # moves whateverYouWantToCallIt forward
whateverYouWantToCallIt.color("purple") # color
whateverYouWantToCallIt.left(90) # turns him 90 degrees
whateverYouWantToCallIt.right(90) # turns him 90 degrees the other direction
xxxxxxxxxx
>>> turtle.position()
(0.00,240.00)
>>> turtle.setx(10)
>>> turtle.position()
(10.00,240.00)
xxxxxxxxxx
import turtle
myTurtle = turtle.Turtle()
myTurtle.forward(100)
myTurtle.right(90)
myTurtle.forward(100)
xxxxxxxxxx
import turtle
#creating a square with turtle
t = turtle.Turtle()
t.forward(100)
t.color('blue')
t.right(90)
t.forward(100)
t.right(90)
t.forward(100)
t.right(90)
t.forward(100)
xxxxxxxxxx
>>> turtle.heading()
22.0
>>> turtle.right(45)
>>> turtle.heading()
337.0