From fc3d5d51934404731005a8538b3c998acbdab3a0 Mon Sep 17 00:00:00 2001 From: Tomas Musil Date: Sun, 7 Oct 2012 23:31:29 +0200 Subject: [PATCH] some more lines in manual mode --- manual.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/manual.py b/manual.py index a2c4f50..0ec6412 100644 --- a/manual.py +++ b/manual.py @@ -53,5 +53,39 @@ def find_lines(im_orig): 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))) -- 2.4.2