Lesson 17: Drawing with Turtle

posted Apr 12, 2019, 8:08 AM by Attila Lengyel   [ updated Apr 12, 2019, 8:12 AM ]
import turtle

bob = turtle.Turtle()

bob.forward(50)
bob.left(90)
bob.forward(50)

bob.left(90)
bob.forward(50)

bob.left(90)
bob.forward(50)

bob.clear()

for i in range(4):
bob.forward(100)
bob.right(90)

bob.clear()

bob.pencolor("red")

num_side = 6
side_length = 100
angle = 360 / num_side

for i in range(num_side):
bob.forward(side_length)
bob.right(angle)

bob.clear()

for i in range(5):
if i == 1 or i == 3: bob.penup()
bob.forward(50)
bob.right(144)
if i == 1 or i == 3: bob.pendown()

bob.clear()

for i in range(10):
bob.forward(i * 20)
bob.right(144)

bob.clear()
bob.penup()
bob.setposition(0,0)
bob.pendown()

bob.speed(2)
colors = ['red', 'purple', 'blue', 'green', 'orange', 'yellow']
for x in range(100):
bob.pencolor(colors[x%6])
bob.circle(5*x)
bob.circle(-5*x)
bob.left(x)


Comments