Turtle module of Python
— turtle is a module of python for drawing graphics —
Step 1: Import Turtle module
Step 2: Use the turtle pen and give the pen a nickname “t”
t = turtle.Pen()
Step 3: Give a function and define the function
def draw_line():
draw_line() is a function.
t.up() make the pen up.
t.down() make the pen down.
t.forward() make the pen move forward.
t.right() make the pen turn right.
At first, make the pen up, then move 20 steps. Make the pen down, then draw a line (50 steps long). Make the pen up again, then move 20 steps. Finally, make the pen turn at a angle of 90 degrees.
Q1: What a graphic will the pen draw, if using t.down() instead of t.up()?
Q2: How about using t.right(45)?
Step 4: Make the function do something
for x in range(1, 5):
The function, draw_line(), will work for 4 times.
Step 5: Make the pen having a color.
t.color(‘dark orange’)
t.color(‘dark orange’) can be in the first line under def draw_line().