From b273841465c17dba1a9c20748db2fc738a1eb257 Mon Sep 17 00:00:00 2001 From: Dark-Storm Date: Sat, 18 Aug 2018 23:45:21 +0200 Subject: [PATCH] =?UTF-8?q?Mise=20=C3=A0=20jour=20et=20debug.=20Le=20progr?= =?UTF-8?q?amme=20retourne=20le=20code=20=C3=A0=20copier=20oncalc.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- process.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/process.py b/process.py index 42a776a..6b16210 100755 --- a/process.py +++ b/process.py @@ -7,7 +7,7 @@ from random import randint import sys -rand = lambda: randint(0,255) +rand = lambda: randint(0,200) def print_stats(img): @@ -25,7 +25,7 @@ def get_lines(img): print("Get lines:", end = "") for a in pixels: for b in pixels: - line = list(bresenham(b[0], b[1], a[0], a[1])) + line = list(bresenham(a[0], a[1], b[0], b[1])) r = len([0 for p in line if p not in pixels]) if not r: lines.append(line) @@ -100,11 +100,27 @@ def get_best_solution(img, lines): return results +def generate_code(lines, args): + str_x, str_y = "{", "{" + + for (xa, yb), (x, y) in lines: + x, y = x + int(args.offset[0]), y + int(args.offset[1]) + a, b = xa - x + int(args.offset[0]), yb - y + int(args.offset[1]) + str_x += "{}{:+}{}, ".format(x, a, "T" if a else "") + str_y += "{}{:+}{}, ".format(y, b, "T" if b else "") + + str_x = str_x[:-2] + "}" + str_y = str_y[:-2] + "}" + return "Graph(X,Y)=({}, {})".format(str_x, str_y) + if __name__ == "__main__": parser = ArgumentParser(description='Generate the Multi DrawStat code for an image.') parser.add_argument('path', type=str, help='path of the image to process') parser.add_argument('-d', '--draw', action='store_true', help='draw the result into a new file and display it') + parser.add_argument('-o', '--offset', nargs=2, default=(0, 0), help='offset for viewwindow. Default: (0, 0)') + # parser.add_argument('-q', '--quiet', action='store_true', help='return code only') + # parser.add_argument('-r', '--reverse', action='store_true', help='reverse y axis') args = parser.parse_args() @@ -122,12 +138,13 @@ if __name__ == "__main__": lines = get_lines(image) lines = removing_doubles(lines) lines = removing_useless(lines) - r = get_best_solution(image, lines) + lines = get_best_solution(image, lines) + code = generate_code(lines, args) if args.draw: export = Image.new('RGB', image.size, 'white') drawer = ImageDraw.Draw(export) - for ((a, b), (c, d)) in reversed(r): + for ((a, b), (c, d)) in reversed(lines): drawer.line((a, b, c, d), fill=(rand(), rand(), rand())) export = export.resize((export.width * 8, export.height * 8)) export.save(args.path[:-4] + "_gen.png") @@ -135,7 +152,6 @@ if __name__ == "__main__": print("\n\n=================================================\n\n") - for l in r: - print(l[0], l[1]) + print(code) print("\n\n=================================================\n\nDone!")