Checkpoint 10.8.1.
- a tuple with one x and one y coordinate
- Correct!
- x coordinate
- Incorrect, a two-dimensional space requires two integers for a position.
- y coordinate
- Incorrect, two integer values are required.
- a list of two integers
- Incorrect, the values for the x,y coordinates are sent by the system as a tuple based on where the user clicks the mouse within the canvas.
Review and run the code example located below.
Notice that when you click the mouse within the canvas, data is displayed within the mouse indicator box on the control panel.
import simplegui
import math
WIDTH = 450
HEIGHT = 300
ball_pos = [WIDTH / 2, HEIGHT / 2]
BALL_RADIUS = 15
ball_color = "Red"
def distance(pt1, pt2):
return math.sqrt( (pt1[0] - pt2[0]) ** 2 + (pt1[1] - pt2[1]) ** 2)
def click(pos):
global ball_pos, ball_color
if distance(pos, ball_pos) < BALL_RADIUS:
ball_color = "Green"
else:
ball_pos = list(pos)
ball_color = "Red"
def draw(canvas):
canvas.draw_circle(ball_pos, BALL_RADIUS, 1, "Black", ball_color)
frame = simplegui.create_frame("Mouse selection", WIDTH, HEIGHT)
frame.set_canvas_background("White")
frame.set_mouseclick_handler(click)
frame.set_draw_handler(draw)
frame.start()
What is the required parameter/argument for the mouse click event handler function?