Fork me on GitHub

Zach's Turtle Exercise

by Zachary Williams

16 Jan 2014

I drew a picture that I intend to use as my new Gravatar. It's a Superman logo with a "Z" instead of an "S", since I like my first initial so much. Here it is:

Turtle image

My code was brute force. I have a couple of for loops to make curves but for the most part I "freehanded" this picture by using Turtle's goto() method. Here's my code:

import turtle

wn = turtle.Screen()
wn.bgcolor('navy') #background color

zuperman = turtle.Turtle()
zuperman.color('red')
zuperman.speed(0)
i = 24
zuperman.pensize(i)      

#Draw the shield in red, fill with gold
zuperman.penup()
zuperman.fillcolor('gold')
zuperman.begin_fill()
zuperman.goto(0, -200)
zuperman.pendown()
zuperman.goto(-195, 75)
zuperman.goto(-150, 195)
zuperman.goto(150, 195)
zuperman.goto(195, 75)
zuperman.goto(0, -200)
zuperman.end_fill()

#Draw the letter's black outline, fill with red
zuperman.penup()
zuperman.goto(-150, 192)
zuperman.pendown()
zuperman.color('black')
zuperman.fillcolor('red')
zuperman.begin_fill()
zuperman.pensize(i/4)
zuperman.goto(150, 192)
zuperman.goto(150, 170)
zuperman.goto(0, -20)
for i in range(90): #draw a curve
    zuperman.forward(1)
   zuperman.left(0.5)
zuperman.right(45)
zuperman.forward(70)
zuperman.goto(70, -95)
zuperman.goto(-70,-95)
zuperman.goto(-140, 0)
zuperman.goto(0, 140)
zuperman.left(180)
for i in range(90):
    zuperman.forward(1)
    zuperman.left(0.5)
zuperman.right(45)
zuperman.goto(-150, 50)
zuperman.goto(-150, 192)
zuperman.end_fill()
zuperman.hideturtle()
wn.exitonclick()
Zach is a sophomore Information Science and Political Science double major at UNC. He hails from Fairfax, Virginia. Find Zachary Williams on Twitter, Github, and on the web.
comments powered by Disqus