OLD: Turtle Design App
Last updated
Was this helpful?
Was this helpful?
from turtle import Turtle
from random import randint
class SuperTurtle(Turtle):
"""
Our wrapper class of the turtle.Turtle object
"""
def __init__(self, shape='turtle'):
"""
This is the turtle's constructor with a default shape of "turtle"
"""
Turtle.__init__(self)
self.color(rancolor())
self.shape(shape)
self.penup()
self.speed(9999)
self.goto_random()
def goto_random(self):
"""
Simple function that sends a turtle to a random location on
a 400x400 canvas
"""
self.goto(randint(-200,200), randint(-200,200))
def triangle(self, length=50):
"""
Draws an equilateral triangle with a default length of 50
"""
self.pendown()
self.forward(length)
self.left(120)
self.forward(length)
self.left(120)
self.forward(length)
def square(self, length=120):
"""
Draws a square with a default length of 120
"""
self.pendown()
for x in range(4):
self.forward(length)
self.left(90)
def home(self):
"""
Returns to center position
"""
self.goto(0,0)
def star(self):
"""
Draws a 5-point star with a fixed length of 140
"""
self.pendown()
for x in range(5):
self.forward(140)
self.left(145)from random import choice
def welcome():
for x in range(3):
print("**************")
if x == 0:
print("** WELCOME ***")
def print_options():
print("--- MENU ---")
print("1: Add turtle to gang")
print("2: Draw a picture")
print("Any other key will quit")
def rancolor():
""" This method returns a string from a list of colors available to Turtle's .color() method """
colors = ["brown", "darkorange", "maroon", "crimson", "navy", "salmon", "tomato", "khaki", "gold", "hotpink", "springgreen", "blue", "cyan", "purple", "green", "red", "pink", "yellow", "teal"]
return choice(colors)from superturtle import SuperTurtle
import helper
# our collection of turtles
gang = []
# welcome message
helper.welcome()
# menu loop
while True:
helper.print_options()
selection = input("You selection: ")
# analyize the selection
if "one" in selection or "1" in selection:
gang.append(SuperTurtle())
elif "two" in selection or "2" in selection:
# loop through all our turtles
for t in gang:
t.star()
# quit if no option is recognized
else:
breakdef super_star(gang):
for x in range(100):
for t in gang:
t.star() elif "three" in selection or "3" in selection:
helper.super_star(gang) # pass the gang over to helper