3/6/23, 7:45 AM about:blank
Exercise: Create Performance Task 1 | CMU CS Academy
1 ### Citations ###
2
3 # 1. Image of a coffee cup with heart
4 # Original Source: media.istockphoto.com
# URL to Original: https://media.istockphoto.com/id/1163942162/vector/coffee-cup-with-h
5
eart.jpg?s=612x612&w=0&k=20&c=Vi78CuHTataRXGfNGbw3JCivBdlRFNRhG2ji6rG_qpk=
6 # First Use: Line 35
7
8 # 1. Sound of tada
9 # Original Source: s3.amazonaws.com
10 # URL to Original: https://s3.amazonaws.com/cmu-cs-academy.lib.prod/sounds/tada.mp3
11 # First Use: Line 25
12
13 # 1. Sound of pop
14 # Original Source: codeskulptor-demos.commondatastorage.googleapis.com
# URL to Original: http://codeskulptor-demos.commondatastorage.googleapis.com/pang/pop.
15
mp3
16 # First Use: Line 26
17
18 ###CODE STARTS HERE###
19 import random
20
21 ###backround###
22
23 backround= Rect(0, 0, 400, 400, fill= 'lightcyan')
Label('Pick a Coffee Size!', 200, 25, size=45, fill='Gray', bold=True, font='Sacrament
24
o')
25 tadaSound = Sound('https://s3.amazonaws.com/cmu-cs-academy.lib.prod/sounds/tada.mp3')
ButtonSound = Sound('http://codeskulptor-demos.commondatastorage.googleapis.com/pang/po
26
p.mp3')
27
28 ###Receipt
29
30 receipt= Group (
31 Rect(0, 0, 400, 400, fill='White'),
32 Label("Receipt", 200, 40, size=50, fill='Gray', font='monospace'),
33 Label("THANKS FOR PURCHASING", 200, 280, size=30, fill='Gray', font='monospace'),
34 )
app.url= 'https://media.istockphoto.com/id/1163942162/vector/coffee-cup-with-heart.jpg?
35
s=612x612&w=0&k=20&c=Vi78CuHTataRXGfNGbw3JCivBdlRFNRhG2ji6rG_qpk='
36 Image1= Image(app.url, 125, 80, width=150, height=150)
37 receipt.visible=False
38 Image1.visible=False
39
40 ###Buttons###
41
42 SButton= Circle(360, 150, 30, fill='lightpink', border='White', borderWidth=3, opacity=
0)
MButton= Circle(360, 230, 30, fill='lavender', border='White', borderWidth=3, opacity=
43
0)
LButton= Circle(360, 310, 30, fill='PaleGreen', border='White', borderWidth=3, opacity=
44
0)
45
46
about:blank 1/6
3/6/23, 7:45 AM about:blank
47 PayButton= Group(
48 Rect(155, 70, 90, 40, fill='papayawhip'),
49 Label( 'PAY!', 200, 90, fill='gray', size=20, bold=True, font='montserrat')
50 )
51 PayButton.visible=False
52
53 ###Cups
54
55 cupS= Group(
56 Circle(120, 280, 45, fill='lightpink'),
57 Circle(120, 280, 25, fill='lightCyan'),
58 Rect(120, 200, 160, 160, fill='lightpink', visible=False),
59 Label('Small', 200, 280, size=25, fill='gray', bold=True, visible=False, font='mont
serrat'),
60 Oval(200, 200, 160, 30, fill='sienna')
61 )
62 cupS.visible=False
63 cupM= Group(
64 Circle(120, 250, 60, fill='lavender'),
65 Circle(120, 250, 35, fill='lightCyan'),
66 Rect(120, 160,160, 200, fill="lavender", visible=True),
67 Label('Medium', 200, 250, size=25, fill='gray', bold=True, font='montserrat'),
68 Oval(200, 160, 160, 30, fill='sienna')
69 )
70 cupM.visible=False
71 cupL= Group(
72 Circle(120, 220, 60, fill='paleGreen'),
73 Circle(120, 220, 35, fill='lightCyan'),
74 Rect(120, 120, 160, 240, fill ='paleGreen', visible=False),
Label('Large', 200, 220, size=25, fill='gray', bold=True, visible=False, font='mont
75
serrat'),
76 Oval(200, 120, 160, 30, fill='sienna')
77 )
78 cupL.visible=False
79
80 ###Cup Labels
81
SCupLabel=Label('1 cup', 200, 360, size =20, fill='white',bold=True, font='monospace',
82
visible=False)
MCupLabel=Label('2 cups', 200, 350, size =20, fill='white',bold=True, font='monospace',
83
visible=False)
LCupLabel=Label('3 cups', 200, 340, size =20, fill='white',bold=True, font='monospace',
84 visible=False)
85
86
87
88
89
90
91
92
93
94
95
96
97
98
about:blank 2/6
3/6/23, 7:45 AM about:blank
99 ### Whip Cream
100
101 WhipCream =Group(
102 Oval(200, 200, 160, 30, fill=gradient('white', 'papayawhip', start='bottom')),
103 Oval(200, 185, 150, 25, fill=gradient('white', 'papayawhip', start='bottom')),
104 Oval(200, 170, 120, 20, fill=gradient('white', 'papayawhip', start='bottom')),
105 Oval(200, 155, 90, 17,fill=gradient('white', 'papayawhip', start='bottom'))
106 )
107 WhipCream.visible=False
108
109 def WhipS():
110
111 responseS=app.getTextInput('would you like whipped cream? (Type yes or no)')
112 if (responseS == "yes" or "Yes"):
113 WhipCream.visible=True
114 if (responseS == "no"):
115 WhipCream.visible=False
116 WhipCream.centerY=220
117
118 def WhipM():
119
120 responseM=app.getTextInput('would you like whipped cream? (Type yes or no)')
121 if (responseM == "yes" or "Yes"):
122 WhipCream.visible=True
123 if (responseM == "no"):
124 WhipCream.visible=False
125 WhipCream.centerY=200
126
127 def WhipL():
128
129 responseL=app.getTextInput('would you like whipped cream? (Type yes or no)')
130 if (responseL == "yes" or "Yes"):
131 WhipCream.visible=True
132 if (responseL == "no"):
133 WhipCream.visible=False
134 WhipCream.centerY = 180
135
136 ###Caffeine List
137
138 app.caffeine = ['95 mg of caffeine', '190 mg of caffeine', '285 mg of caffeine']
139 app.index=0
140
CaffeineL = Label('', 200, 150, size =20, fill='Gray',bold=True, font='montserrat', vis
141
ible=False)
142 CaffeineL.value = app.caffeine[app.index]
143
144 ### buttons-list, loop, and custom def
145
146 colors = [ 'Lightpink', 'Lavender', 'PaleGreen']
147
148 SBL=Label('SMALL', 360, 150, size=10, fill='gray', bold=True, font='montserrat')
149 MBL=Label('MEDIUM', 360, 230, size=10, fill='gray', bold=True, font='montserrat')
150 LBL=Label('LARGE', 360, 310, size=10, fill='gray', bold=True, font='montserrat')
151
152
153
about:blank 3/6
3/6/23, 7:45 AM about:blank
154 def drawButtons(centerY, index):
155
156 for x in colors:
157 x = colors[index]
158 Circle( 360, centerY, 30, fill=x, border='white', borderWidth=3, visible=True)
159 if (cupS.visible==True) and (centerY <= 200):
160 SBL.size=20
161 MBL.size=10
162 LBL.size=10
163 if cupM.visible==True and (centerY <= 240):
164 MBL.size=15
165 SBL.size=10
166 LBL.size=10
167 elif (cupL.visible==True) and (centerY <= 320):
168 LBL.size=20
169 MBL.size=10
170 SBL.size=10
171
172 drawButtons(150, 0)
173 drawButtons(230, 1)
174 drawButtons(310, 2)
175 SBL.toFront()
176 MBL.toFront()
177 LBL.toFront()
178
179
180 ###Update Screen
181
182 def UpdateScreen():
183
184 PayButton.visible=False
185 SCupLabel.visible=False
186 MCupLabel.visible=False
187 CaffeineL.visible=False
188 LCupLabel.visible=False
189 cupL.visible=False
190 cupM.visible=False
191 cupS.visible=False
192 WhipCream.visible=False
193 SBL.size=10
194 MBL.size=10
195 LBL.size=10
196
197
198
199
200
201
202
203
204
205
206
207
208
209
about:blank 4/6
3/6/23, 7:45 AM about:blank
210 ###Functions
211 def onMousePress(mouseX, mouseY):
212
213 ###Small cup Function
214
215 if(SButton.hits(mouseX, mouseY)):
216 ButtonSound.play()
217 WhipCream.visible=False
218 CaffeineL.visible=False
219 PayButton.visible=False
220 SCupLabel.visible=True
221 MCupLabel.visible=False
222 LCupLabel.visible=False
223 cupL.visible=False
224 cupM.visible=False
225 cupS.visible=True
226 cupS.centerY =320
227 WhipS()
228 PayButton.visible=True
229 CaffeineL.visible=True
230 CaffeineL.visible=True
231 CaffeineL.centerY = 150
232 CaffeineL.value = app.caffeine[0]
233 drawButtons(150, 0)
234 drawButtons(230, 1)
235 drawButtons(310, 2)
236 SBL.toFront()
237 MBL.toFront()
238 LBL.toFront()
239
240
241 ###Medium cup Function
242
243 if(MButton.hits(mouseX, mouseY)):
244 ButtonSound.play()
245 WhipCream.visible=False
246 CaffeineL.visible=False
247 PayButton.visible=False
248 SCupLabel.visible=False
249 MCupLabel.visible=True
250 LCupLabel.visible=False
251 cupL.visible=False
252 cupS.visible=False
253 cupM.visible=True
254 cupM.centerY=320
255 WhipM()
256 PayButton.visible=True
257 CaffeineL.visible=True
258 CaffeineL.centerY =140
259 CaffeineL.value = app.caffeine[1]
260 drawButtons(150, 0)
261 drawButtons(230, 1)
262 drawButtons(310, 2)
263 SBL.toFront()
264 MBL.toFront()
265 LBL.toFront()
about:blank 5/6
3/6/23, 7:45 AM about:blank
266 ###Large cup Function
267
268 if(LButton.hits(mouseX, mouseY)):
269 ButtonSound.play()
270 WhipCream.visible=False
271 CaffeineL.visible=False
272 PayButton.visible=False
273 SCupLabel.visible=False
274 MCupLabel.visible=False
275 LCupLabel.visible=True
276 cupS.visible=False
277 cupM.visible=False
278 cupL.visible=True
279 cupL.centerY=320
280 WhipL()
281 PayButton.visible=True
282 CaffeineL.visible=True
283 CaffeineL.centerY =130
284 CaffeineL.value = app.caffeine[2]
285 drawButtons(150, 0)
286 drawButtons(230, 1)
287 drawButtons(310, 2)
288 SBL.toFront()
289 MBL.toFront()
290 LBL.toFront()
291
292 ###Receipt Functions
293
294 if (PayButton.hits(mouseX, mouseY)):
295 receipt.visible=True
296 Image1.visible=True
297 receipt.toFront()
298 Image1.toFront()
299 tadaSound.play()
300 UpdateScreen()
301 else:
302 receipt.visible=False
303 Image1.visible=False
about:blank 6/6