width=line_width)
draw.line((corners[3], corners[0]), fill=color,
width=line_width)
+ l1 = half_line(corners)
+ draw.line(l1, fill=color, width=line_width)
+ l2 = half_line(corners[1:4] + [corners[0]])
+ draw.line(l2, fill=color, width=line_width)
+ c = center(corners)
+ draw.ellipse((c[0] - 1, c[1] - 1, c[0] + 1, c[1] + 1),
+ fill=(255, 64, 64))
+
screen.display_picture(im)
clock.tick(15)
+
+def half_line(corners):
+ c = center(corners)
+ d1 = intersection(line(corners[0], corners[3]),
+ line(corners[1], corners[2]))
+ p1 = intersection(line(c,d1), line(corners[0],
+ corners[1]))
+ p2 = intersection(line(c,d1), line(corners[2],
+ corners[3]))
+ return (p1, p2)
+
+def center(corners):
+ return intersection(line(corners[0], corners[2]), line(corners[1],
+ corners[3]))
+def line(x, y):
+ a = float(x[1] - y[1])
+ b = float(y[0] - x[0])
+ c = a * y[0] + b * y[1]
+ return (a, b, c)
+
+def intersection(p, q):
+ det = p[0] * q[1] - p[1] * q[0]
+ if det == 0:
+ return None
+ return (int(round((q[1] * p[2] - p[1] * q[2]) / det)), int(round((p[0] *
+ q[2] - q[0] * p[2]) / det)))