Checkpoint 10.7.1.
- A circle will be drawn where the user clicked.
- It’s reasonable to expect this, but CodeSkulptor3 has unique handlers for both individual mouse clicks and for dragging the mouse click.
- A circle is drawn where the user initially clicked, and continues to draw circles on the position of the mouse around the canvas.
- Mouse drag handlers only register continuous dragging inputs and not individual clicks. Even if the mouse drag handler recognized the initial click, without dragging the mouse on the canvas there are no more inputs to keep drawing circles.
- This code does not run, it contains an error.
- Incorrect. Try running this code in CodeSkulptor3 to test what happens yourself.
- Nothing happens.
- Correct! Mouse drag handlers do not recieve inputs from individual clicks and so nothing is drawn on the canvas.
import simplegui
CANVAS_WIDTH = 400
CANVAS_HEIGHT = 400
circle_list = []
canvas_col = "White"
# GUI Control Handlers
def draw(canvas):
for index in range(len(circle_list)):
canvas.draw_circle(circle_list[index], 10, 3, "Black", "Red")
def clear_handler():
clear_canvas()
def drag(pos):
add_circle(pos)
def add_circle(pos):
circle_list.append(pos)
def clear_canvas():
circle_list.clear()
# Frame
frame = simplegui.create_frame("COMP 1000 Demo", CANVAS_WIDTH, CANVAS_HEIGHT)
frame.set_canvas_background(canvas_col)
# Register Keyboard and Mouse Event Handlers
frame.set_draw_handler(draw)
frame.set_mousedrag_handler(drag)
frame.add_button('Clear', clear_handler)
# Show the frame and start listening
frame.start()
What would happen if a user was running this code in CodeSkulptor3 and clicked on the canvas once?