Professional Documents
Culture Documents
Well continue using the Turtle set of functions in JES in order to illustrate these concepts.
Demo (5 min)
Show the finished program.
def m yTurtleProgram():
w = makeWorld()
t = makeTurtle(w)
f orward(t)
turnRight(t)
forward(t)
turnRight(t)
forward(t)
turnRight(t)
forward(t)
turnRight(t)
Theres an easier way, introducing loops, but first lets talk about arrays
Array as a collection of things
Demonstrate a for loop
Condition and body
def m yTurtleProgram():
w = makeWorld()
t = makeTurtle(w)
f or side in range(0,4):
forward(t)
turnRight(t)
Lets talk about how to approach animation, we need to update the screen instead of just
showing when its done, any ideas here?
def m yTurtleProgram():
w = makeWorld()
t = makeTurtle(w)
f or side in range(0,4):
for point in range(0, 100):
forward(t, 1)
turnRight(t)
Libraries, pre-built functions for you to use, which youve been using already, like print
import time
def m yTurtleProgram():
w = makeWorld()
t = makeTurtle(w)
f or side in range(0,4):
for point in range(0, 100):
forward(t, 1)
time.sleep(.005)
turnRight(t)
import time
def m yTurtleProgram():
w = makeWorld()
t = makeTurtle(w)
f or side in range(0,4):
for point in range(0, 100):
if point % 5 == 0:
penDown(t)
else:
penUp(t)
forward(t, 1)
time.sleep(.005)
turnRight(t)
Finished Program:
import time
def m yTurtleProgram():
w = makeWorld()
t = makeTurtle(w)
d rawSquare(t, 200)
drawSquare(t, 100)
drawSquare(t, 50)
drawSquare(t, 25)
spinTurtle(t)
def s pinTurtle(t):
# s pin the turtle
f or x in range(0,359):
turn(t, 1)
time.sleep(.002)