exam2-1 copy.py - from graphics import from time import...

This preview shows page 1 - 2 out of 2 pages.

from graphics import *from time import sleep# {insert your header here}### DO NOT MODIFY THE FUNCTIONS isClicked() or make() in any way. You must# use them as they are written. Add your main() function at the bottom# of this file#''' The function isClicked() accepts 2 arguments, a "mouse click" Pointand a shape which can be either a Circle or Rectangle. The functionwill return True if the click location is within either shape typeotherwise isClicked() will return False.'''def isClicked(click, shape):# verify that click is a Point object otherwise return Falseif not click:return False# get the X,Y coordinates of the mouse clickx,y = click.getX(), click.getY() # check if shape is a Circleif type(shape).__name__ == 'Circle':center = shape.getCenter()cx, cy = center.getX(), center.getY()# if click is within the Circle return Trueif ((x-cx)**2 + (y-cy)**2)**.5 <= 25:return True# shape must be a Rectangleelse:x1, y1 = shape.getP1().getX(), shape.getP1().getY()x2, y2 = shape.getP2().getX(), shape.getP2().getY()# if click is within the Rectangleif (x1 < x < x2) and (y1 < y < y2):return True

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture