In: Computer Science
Create a python graphics of a smiley face that includes hair and eyebrows.
must start with : from graphics import * or import graphics
code must include these dimensions:
Head: Circle(Point(400,400), 200)
R Eye: Circle(Point(350,350), 20)
L Eye: Circle(Point(450,350), 20)
Mouth1: Oval(Point(300,500),Point(500,400))
Mouth2: Oval(Point(315,475), Point(485,375))
Code :
from graphics import *
def main():
#Draw Data:
win = GraphWin("Smiley Face", 800, 800) # Create Graphics Windows
& give title and dimensions
head = Circle(Point(400,400), 200) # set center and radius
head.draw(win) # Draw head in Graphics Windows
reye = Circle(Point(350,350), 20) # set center and radius
reye.draw(win) # Draw right eye in Graphics Windows
leye = Circle(Point(450,350), 20) # set center and radius
leye.draw(win) # Draw left eye in Graphics Windows
mt1 = Oval(Point(300,500),Point(500,400)) # set corners of
bounding box
mt1.draw(win) # Draw mouth 1 in Graphics Windows
mt2 = Oval(Point(315,475), Point(485,375)) # set corners of
bounding box
mt2.draw(win) # Draw mouth 2 in Graphics Windows
# Draw Right Evebrow
line1 = Line(Point(315, 350), Point(350, 320)) # set
endpoints
line1.draw(win) # Draw line
line2 = Line(Point(350, 320), Point(385, 350)) # set
endpoints
line2.draw(win) # Draw line
# Draw Left Evebrow
line3 = Line(Point(415, 350), Point(450, 320)) # set
endpoints
line3.draw(win) # Draw line
# Draw Hairs
line4 = Line(Point(450, 320), Point(485, 350)) # set
endpoints
line4.draw(win) # Draw line
line5 = Line(Point(225, 300), Point(300, 100)) # set
endpoints
line5.draw(win) # Draw line
line6 = Line(Point(575, 300), Point(500, 100)) # set
endpoints
line6.draw(win) # Draw line
line7 = Line(Point(300, 100), Point(400, 150)) # set
endpoints
line7.draw(win) # Draw line
line8 = Line(Point(500, 100), Point(400, 150)) # set
endpoints
line8.draw(win) # Draw line
message = Text(Point(win.getWidth()/2, 20), 'Click anywhere to
quit.') # Set text position
message.draw(win) # Draw the prompting text
win.getMouse() # waits for a mouse click
win.close() # closes the graphics window
main()
Output:
Please thumbs up for my solution.