subject

6.7 Code Practice Instructions
You should see a large block of code in the programming environment below. First, run this code to see what it does.

You should see that running this code generates a graphics window with five buttons, labeled "Happy", "Sad", "Angry", "Surprised" and "Emoticon". Each of these can be clicked on. The starter code for the Happy (face1), Sad (face2) and Emoticon (face5) faces are left empty below, and and the code for Angry (face3) and Surprised (face4) faces show completed emoticons when you click. You can click on the buttons to turn them on and also to switch between them.

There is a lot provided in the starter code below - functions, variables, and more. One thing you might notice is the word "global". We'll look at this term in more detail in the next lesson. For now, you don't need to know what this word does. In short, the word global is used whenever there is a variable in a program that appears both inside and outside of a function. Your code may not run as you expect it to without a global variable, so the keyword is used to indicate to the computer that the same variable should be used every time it appears in the program. For now, we are just drawing your attention to this keyword, but you will be dealing with it in more detail soon.

Starter Code
import simplegui
import math

# Global Variables

width = 600
height = 600
face1 = False
face2 = False
face3 = False
face4 = False
face5 = False

# Event Handlers

def all_false():
global face1
global face2
global face3
global face4
global face5
face1 = False
face2 = False
face3 = False
face4 = False
face5 = False

def toggle_face1():
all_false()
global face1
face1 = not face1

def toggle_face2():
all_false()
global face2
face2 = not face2

def toggle_face3():
all_false()
global face3
face3 = not face3

if face5:
canvas. draw_circle((width/2, height/2), width/2 - 50, 10, "Yellow", "Yellow")

frame = simplegui. create_frame("Pictures", width, height)

frame. set_draw_handler(draw)
frame. add_button("Happy", toggle_face1, 100)
frame. add_button("Sad", toggle_face2, 100)
frame. add_button("Angry", toggle_face3, 100)
frame. add_button("Surprised", toggle_face4, 100)
frame. add_button("Emoticon", toggle_face5, 100)

# Remember to start the frame
frame. start()
Assignment
You will create three emoticons in this Code Practice. First, you should create faces for the Happy and Sad emoticons, which should display happy and sad faces. Then, you will create an emoticon for another expression on the Emoticon face (you can choose the emotion you want to display).

In the code above, face3 and face 4 are already completed for you, so use the blocks of code there as a reference as you make your new emoticons. For your emoticons, you must include at least 6 shapes (line, triangle, circle, etc.) in order to design the face.

You may notice that the Angry emoticon only uses the variables width and height in order to create the shapes, and the Surprised emoticon only uses numbers. This is okay - you can be creative as you create your three emoticons!

Benchmarks
As you work on this Code Practice, you may find it helpful to track your progress against the benchmarks listed below. Follow the steps in order to ensure that you are writing clear, concise code that will meet all of the criteria.

Sketch out your emoticon by hand before beginning (we recommend using a piece of graph paper).
Draw a 600 by 600 square to start, and then draw a circle inside the square.
Add the shapes for your face that will create the facial expression desired.
Try to identify the x and y coordinates you will need in order to create your shapes - where should each shape start? What points will it end at?
Line by line, in the if statement of the emoticon you are editing, start to build your face. Write lines of code that draw each of the shapes you sketched out earlier.
If there is an issue with how the shape appears, adjust the numbers that you used, and continue testing before moving to the next shape. Is your shape too large? Too narrow? Do you want to move it to the left or right? Adjust your code as you go.
Repeat this process for all three faces.
Remember to give a name to your final button: the default in the code is "Emoticon", so you should rename it to match the emoticon that you created.

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 01:00
What is added to the < meta > tag to describe the encoding type?
Answers: 2
question
Computers and Technology, 23.06.2019 10:20
Suppose there is a relation r(a, b, c) with a b+-tree index with search keys (a, b).1. what is the worst-case cost of finding records satisfying 10 < a < 50 using this index, in terms of the number of records n1, retrieved and the height h of the tree? 2. what is the worst-case cost of finding records satisfying 10 < a < 50 and 5 < b < 10 using this index, in terms of the number of records n2 that satisfy this selection, as well as n1 and h defined above? 3. under what conditions on n1 and n2, would the index be an efficient way of finding records satisfying the condition from part (2)?
Answers: 1
question
Computers and Technology, 23.06.2019 12:00
Which of these is a benefit of using objects in a powerpoint presentation? a. collaborators can create the external files while you create and edit the slide show. b. you can easily change the theme and design of the presentation. c. you can have older data in the source file while having up-to-date data in the presentation. d. collaborators can easily share the presentation.
Answers: 2
question
Computers and Technology, 24.06.2019 07:30
John recently worked on a project about various programming languages. he learned that though procedural language programs are useful, they have disadvantages too. what is a disadvantage of programs written in procedural languages? a. programs do not represent data complexity. b. programs take more time to execute. c. programs are prone to security threats. d. programs do not interface with multiple platforms.
Answers: 3
You know the right answer?
6.7 Code Practice Instructions
You should see a large block of code in the programming enviro...
Questions
question
Chemistry, 10.12.2020 16:50
question
Mathematics, 10.12.2020 16:50
question
Mathematics, 10.12.2020 16:50
question
Chemistry, 10.12.2020 17:00
Questions on the website: 13722361