@_RealUnderscor/

Shape Generator

Python (with Turtle)

Enter a shape and watch it print! Some of it is copied (square & triangle) by another Repl, I don't know who.

fork
loading
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import turtle
wn = turtle.Screen()
t = turtle.Turtle()
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
""" Functions """
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
def generateShapes():
  def doNewShapeStuffs():
    newShapeInstructions = "Scroll right in \"result\" and then type in a new shape to continue."
    t.speed(0)
    t.color("white")
    t.forward(200)
    t.color("black")
    print(newShapeInstructions)

  defineAllShapes = ("square", "triangle", "circle", "rectangle", "star", "diamond", "random")
  shapes = str(defineAllShapes)
  shapes = shapes.lower()
#  print("The current available inputs are "+ shapes)

  shape_input = input("\nPlease enter a shape here (no period) ->")
  shape = str(shape_input)
  shape = shape.lower()

  def printErrorMessage():
 
    print "Error! Invalid shape."

  def printShapeInput():
    print "\nPrinting! Go back to \"result\" to watch it print."
    
  if shape in shapes:
   if shape == "random":
     import random
     randShape = random.randint(1, 6)
     printShapeInput()
     print "Your shape is shape "+ str(randShape) + ". Go back to \"result\" to watch it print!"
     if randShape == 1:
       def drawSquare(t, sz):
         t.speed(2)
         for i in range(4):
           t.forward(sz)
           t.left(90)
       drawSquare(t, 90)
       t.forward(91)
       doNewShapeStuffs()
     if randShape == 2:
       t.speed(2)
       for i in range(3):
         t.forward(100)
         t.left(120)
       t.forward(100)
       doNewShapeStuffs()
     if randShape == 3:
       t.speed(2)
       t.circle(60)
       doNewShapeStuffs()
     if randShape == 4:
       t.speed(4)
       for i in range(2):
         t.forward(240)
         t.left(90)
         t.forward(120)
       t.forward(241)
       doNewShapeStuffs()
     if randShape == 5:
       t.speed(6)
       for i in range(19):
         t.forward(i * 10)
         t.right(144)
       t.left(220)
       doNewShapeStuffs()
     if randShape == 6:
       t.speed(3)
       for i in range(2):
         t.left(60)
         t.forward(120)
       t.left(120)
       doNewShapeStuffs()
       for j in range(2):
         t.forward(120)
         t.left(60)
         doNewShapeStuffs()

   if shape == "square":
    printShapeInput()
    def drawSquare(t, sz):
      t.speed(2)
      for i in range(4):
          t.forward(sz)
          t.left(90)
    drawSquare(t, 90)
    t.forward(91)
    doNewShapeStuffs()

   if shape == "triangle":
    printShapeInput()
    t.speed(2)
    for i in range(3):
      t.forward(100)
      t.left(120)
    t.forward(100)
    doNewShapeStuffs()

   if shape == "circle":
    printShapeInput()
    t.speed(2)
    t.circle(60)
    doNewShapeStuffs()

   if shape == "rectangle":
    printShapeInput()
    t.speed(4)
    t.forward(240)
    t.left(90)
    t.forward(120)
    t.left(90)
    t.forward(240)
    t.left(90)
    t.forward(120)
    t.speed(4)
    t.left(90)
    t.forward(241)
    doNewShapeStuffs()

   if shape == "star":
     printShapeInput()
     t.speed(6)
     for i in range(19):
       t.forward(i * 10)
       t.right(144)
     t.left(220)
     doNewShapeStuffs()

   if shape == "diamond":
     printShapeInput()
     t.speed(3)
     for i in range(2):
       t.left(60)
       t.forward(120)
     t.left(120)
     for j in range(2):
       t.forward(120)
       t.left(60)
       doNewShapeStuffs()
  
   if shape == "hexagon":
     printShapeInput()
  else:
    printErrorMessage()
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
""" Main Routine """
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
print("The current available shapes are \"square\", \"triangle\", \"circle\", \"rectangle\", \"star\", \"diamond\", and for a random shape, type in \"random\"")

for i in range(2):
  generateShapes()
t.left(90)
for k in range(4):
  generateShapes()
t.left(90)
for l in range(3):
  generateShapes()
result
console