Mise à jour et debug. Le programme retourne le code à copier oncalc.

This commit is contained in:
Dark-Storm 2018-08-18 23:45:21 +02:00
parent f53d5ab7c1
commit b273841465
Signed by: Darks
GPG Key ID: F61F10FA138E797C
1 changed files with 22 additions and 6 deletions

View File

@ -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!")