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 17:30
How do you make a lenny face? plz, brailiest to who can answer first.
Answers: 1
question
Computers and Technology, 23.06.2019 14:00
Need ! will choose brainliest! discuss the role of abstraction in the history of computer software.
Answers: 1
question
Computers and Technology, 24.06.2019 12:50
What percentage of teens plays video games? a.97% b.100% c.74% d.50%
Answers: 1
question
Computers and Technology, 24.06.2019 13:30
What process should be followed while giving a reference? sam has given a reference of his previous manager in his resume. sam should him in advance that the potential employers will him.
Answers: 1
You know the right answer?
6.7 Code Practice Instructions
You should see a large block of code in the programming enviro...
Questions
question
Mathematics, 28.01.2020 12:31
Questions on the website: 13722359