DRAWING WITH TURTLES

  1. In repl.it, create a Python with TURTLE file (not the same as Python).
    
    

DRAWING WITH TURTLES

2. Name the file spirals

3. Type this to import the Turtle library

DRAWING WITH TURTLES

import turtle
A library is a group of functions that can be added on to a language. You need to import the library into your program before you can use any of its functions.
4. Create a turtle object and assign it to a variable of any name

DRAWING WITH TURTLES

import turtle

# create a turtle object and
# assign it to a variable
frank = turtle.Turtle()
5. Now, use this code to instruct your turtle to draw a square spiral

DRAWING WITH TURTLES

# draw a square spiral
for x in range(100):
    frank.forward(x)
    frank.left(90)
6. Play with the range to see if you can put more space between the lines

DRAWING WITH TURTLES

7. Experiment more: 

   - Change the left angle value
   - Add more commands to the for loop
   - Turtles can also go right, backward, 
     and in a circle.

DRAWING WITH TURTLES

8. Use this code to change the turtle's pen color and the screen's background color. Where should this go in the sequence of your program?

DRAWING WITH TURTLES

# set turtle's pen color
frank.pencolor("yellow")

# create a turtle Screen object
# assign it to any variable name
# and set background color
canvas = turtle.Screen()
canvas.bgcolor("blue")
​9. Incorporate 4 different colors in the same drawing by making the turtle change its color at various points along the way.

DRAWING WITH TURTLES

Drawing with Turtles

By Michelle Lim

Drawing with Turtles

  • 1,462