Код: Выделить всё
# Dots
# importing
import simplegui
import math
width = 600
height = 600
ball_list = []
radius = 20
colour = "Yellow"
# position ditector
def distance(p,q) :
return math.sqrt((p[0]-q[0])**2 + (p[1]-q[1])**2)
# Mouse click -- Change the position
def click(pos) :
ball_list.append(pos)
# global position
# global colour
# if distance(pos, position) < radius :
# colour = "Blue"
# else :
# position = list(pos)
# colour = "Yellow"
# Drawing the ball
def draw(canvas) :
for position in ball_list :
canvas.draw_circle(position , radius , 2, "Black" , colour)
# Creating the frame
frame = simplegui.create_frame("Dots" , 600,600)
frame.set_canvas_background("White")
frame.set_draw_handler(draw)
# mouse click
frame.set_mouseclick_handler(click)
# Start
frame.start()
Если приведенный выше код не работает в вашей IDE, перейдите по адресу http://www.codeskulptor.org/#user38_VSZ0jZ0uTh_0.py
и запустите его. .
Подробнее здесь: https://stackoverflow.com/questions/265 ... -algorithm