add a raw output mode that prints line coordinates

This change adds a raw output mode enabled by -r or --raw, that outputs
line endpoints coordinates rather than CASIO Basic code, for whenever a
smart line-based drawing algorithm is used in another context.
This commit is contained in:
Lephe 2019-09-05 18:10:18 +02:00
parent ea7d2e035f
commit 7c6069c6ba
Signed by untrusted user: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
1 changed files with 18 additions and 1 deletions

View File

@ -141,6 +141,17 @@ def generate_code(lines, args):
return code
def generate_raw(lines, args):
"""Generate raw line coordinates"""
ox, oy = int(args.offset[0]), int(args.offset[1])
code = ""
for (x_end, y_end), (x_start, y_start) in lines:
code += f"{x_start} {y_start} {x_end} {y_end}\n"
return code
# From Zezeombye's BIDE
def get_coord(start, end):
"""Convert a pair of coordonates to the appropriate x+yT Multi DrawStat output"""
@ -174,6 +185,7 @@ if __name__ == "__main__":
parser.add_argument('-p', '--progress', action='store_true', help='print progress info')
parser.add_argument('-s', '--show', action='store_true', help='show the result')
parser.add_argument('-d', '--draw', action='store_true', help='draw the result into a new file')
parser.add_argument('-r', '--raw', action='store_true', help='print raw line coordinates')
args = parser.parse_args()
@ -194,10 +206,15 @@ if __name__ == "__main__":
if args.info:
print_stats(image)
lines = get_lines(image)
lines = removing_useless(lines)
lines = get_best_solution(image, lines)
code = generate_code(lines, args)
if args.raw:
code = generate_raw(lines, args)
else:
code = generate_code(lines, args)
if args.draw or args.show:
export = Image.new('RGB', image.size, 'white')