Redlands Conservatory Robotics
Moving around in PYTHON using "Turtle."
We'll be using the Python programming language in the future to control a robot.
To get used to using python, there is a wonderful feature called "Turtle." whicj will let us move a virtual turtle on the screen.
Later, we'll move our robot in a similar way!
Welcome to PYTHON programming!
Visit this link to try out today's turtle code on line!
Click Here for a fun program to modify.
The code for both programs is below:
Simple drawing commands demo:
import turtle
t = turtle.Turtle()
t.color('brown')
# Move up
t.penup()
t.left(90)
t.forward(50)
t.pendown()
# Draw a triangle manually
t.right(30)
t.forward(50)
t.right(120)
t.forward(50)
t.right(120)
t.forward(50)
# Move left
t.penup()
t.forward(50)
t.pendown()
# Draw a square
for i in xrange(4):
t.forward(50)
t.left(90)
# add the code to move your turtle through the maze
import turtle
t = turtle.Turtle()
t.color('brown')
# draw maze
t.right(90)
t.forward(250)
t.right(90)
t.forward(250)
t.right(90)
t.forward(450)
t.right(90)
t.forward(250)
t.right(90)
t.forward(50)
t.right(90)
t.forward(150)
t.left(90)
t.forward(250)
# move turtle outside maze
t.penup()
t.backward(170)
t.left(90)
t.forward(160)
t.pendown()
# Draw a square
#for i in xrange(4):
# t.forward(50)
# t.left(90)