-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDrawTurkeyAndHat.py
More file actions
164 lines (137 loc) · 5.37 KB
/
DrawTurkeyAndHat.py
File metadata and controls
164 lines (137 loc) · 5.37 KB
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
164
import turtle
#Pre: aTurtle, aColor, and radius exist and are valid.
#Post: A full circle is drawn with a specific color filling.
def drawCircle(aTurtle,aColor,radius,degrees):
if aColor != "none":
aTurtle.fillcolor(aColor)
aTurtle.begin_fill()
aTurtle.circle(radius,degrees)
aTurtle.end_fill()
else:
aTurtle.circle(radius,degrees)
#Pre: aTurtle, sideLen, and aColor are valid and exist.
#Post: A triangle (the turkey's beak) is drawn.
def drawBeak(aTurtle,sideLen,aColor):
aTurtle.fillcolor(aColor)
aTurtle.begin_fill()
aTurtle.forward(sideLen)
aTurtle.right(120)
aTurtle.forward(sideLen)
aTurtle.right(120)
aTurtle.forward(sideLen)
aTurtle.end_fill()
#Pre: aTurtle exists and is valid.
#Post: The turkey's feathers are drawn with different color filling.
def drawFeathers(aTurtle,InitialX,InitialY):
aTurtle.left(35)
for aColor in ["orange","yellow","light blue","green","light pink"]:
moveTurtle(aTurtle,InitialX,InitialY)
drawOvalShape(25,160,aTurtle,190,aColor)
aTurtle.right(165)
#Pre: circRadius, AmntFrwd, aTurtle, circDegrees, and aColor all exist and are valid.
#Post: An oval shape (straight line, part of a circle, straight line) is drawn.
def drawOvalShape(circRadius,AmntFrwd,aTurtle,circDegrees,aColor):
aTurtle.fillcolor(aColor)
aTurtle.begin_fill()
aTurtle.forward(AmntFrwd)
drawCircle(aTurtle,"none",circRadius,circDegrees)
aTurtle.forward(AmntFrwd)
aTurtle.end_fill()
#Pre: aTurtle exists and is valid.
#Post: One of the turkey's legs is drawn.
def drawLeg(aTurtle):
aTurtle.left(50)
drawOvalShape(8,40,aTurtle,180,"yellow")
aTurtle.right(90)
CurrentX,CurrentY = aTurtle.position()
moveTurtle(aTurtle,CurrentX-8,CurrentY+8)
drawOvalShape(8,40,aTurtle,180,"yellow")
aTurtle.right(40)
drawOvalShape(8,45,aTurtle,180,"yellow")
drawOvalShape(8,45,aTurtle,180,"yellow")
#Pre: aTurtle,Xcoord, and Ycoord exist and are valid.
#Post: Two turkey legs are drawn.
def drawTurkeyLegs(aTurtle,Xcoord,Ycoord):
moveTurtle(aTurtle,Xcoord,Ycoord)
drawLeg(aTurtle)
CurrentX,CurrentY = aTurtle.position()
moveTurtle(aTurtle,CurrentX+130,CurrentY)
aTurtle.left(105)
drawLeg(aTurtle)
#Pre: aTurtle exists and is valid.
#Post: The problem statement is solved and a turkey is drawn.
def drawTurkey(aTurtle,initialX,initialY):
drawFeathers(aTurtle,initialX,initialY)
drawTurkeyLegs(aTurtle,initialX-70,initialY-120)
aTurtle.right(105)
aTurtle.color("black")
moveTurtle(aTurtle,initialX,initialY-110)
drawCircle(aTurtle,"brown",100,360) #body
aTurtle.right(100)
moveTurtle(aTurtle,initialX-10,initialY+80) #neck
drawOvalShape(25,100,aTurtle,200,"dark red")
aTurtle.right(100)
moveTurtle(aTurtle,initialX,initialY+40)
drawCircle(aTurtle,"maroon",40,360) #head
for i in [-15,15]:
moveTurtle(aTurtle,initialX+i,initialY+88)
drawCircle(aTurtle,"grey",8,360) #eye
moveTurtle(aTurtle,initialX-10,initialY+80) #beak
drawBeak(aTurtle,20,"yellow")
#Pre: aTurtle exists and is valid.
#Post: Top of hat is drawn.
def drawTopofHat(aTurtle):
aTurtle.begin_fill()
aTurtle.left(5)
CurrentX,CurrentY = aTurtle.position()
moveTurtle(aTurtle,CurrentX-30,CurrentY)
aTurtle.forward(100)
aTurtle.left(80)
aTurtle.forward(110)
aTurtle.left(80)
aTurtle.forward(100)
aTurtle.end_fill()
#Pre: aTurtle exists and is valid.
#Post: The problem statement is solved and a Pilgrim hat is drawn.
def drawPilgrimHat(aTurtle,initialX,initialY):
moveTurtle(aTurtle,150,-150)
drawOvalShape(100,0,aTurtle,190,"black") #hat bottom
drawTopofHat(aTurtle)
FirstPosX,FirstPosY = aTurtle.position()
aTurtle.color("brown") #brown buckle strap
aTurtle.pensize(5)
SemiCylinderShape(aTurtle,FirstPosX,FirstPosY,18,75,160,20,20,30,205,70,150)
aTurtle.color("gold") #buckle
aTurtle.pensize(8)
moveTurtle(aTurtle,initialX+80,initialY-20)
SemiCylinderShape(aTurtle,initialX+80,initialY-20,270,70,50,240,0,40,71,70,50)
moveTurtle(aTurtle,initialX+80,initialY-45) #Little buckle knob
aTurtle.right(35)
aTurtle.forward(15)
#Pre: aTurtle,xcoord,ycoord,FirstLTurn,radius,degrees,LTurn2,RghtTurn,FrwdAmnt,Left3,radius2,and
# degrees2 all exist and are valid.
#Post: Part of a cylinder is drawn.
def SemiCylinderShape(aTurtle,xcoord,ycoord,FirstLTurn,radius,degrees,LTurn2,RghtTurn,FrwdAmnt,Left3,radius2,degrees2):
aTurtle.left(FirstLTurn)
drawCircle(aTurtle,"none",radius,degrees)
aTurtle.left(LTurn2)
aTurtle.forward(FrwdAmnt)
moveTurtle(aTurtle,xcoord,ycoord)
aTurtle.right(RghtTurn)
aTurtle.forward(FrwdAmnt)
aTurtle.left(Left3)
drawCircle(aTurtle,"none",radius2,degrees2)
#Pre: aTurtle, xcoord, and ycoord exist and are valid.
#Post: aTurtle is moved to the desired spot.
def moveTurtle(aTurtle,xcoord,ycoord):
aTurtle.penup()
aTurtle.goto(xcoord,ycoord)
aTurtle.pendown()
def main():
window = turtle.Screen()
aTurtle = turtle.Turtle()
aTurtle.shape("blank")
drawTurkey(aTurtle,-150,120)
aTurtle.right(215)
drawPilgrimHat(aTurtle,150,-150)
window.exitonclick()