LJ/clitools/generators/drawingTests/order_optimization.py

85 lines
1.9 KiB
Python
Raw Normal View History

#!/usr/bin/python3
# -*- coding: utf-8 -*-
# -*- mode: Python -*-
'''
This generator print a shape with best angle representation when the path is redraw
v0.1.0
LICENCE : CC
by lapin (aka nipal)
'''
from __future__ import print_function
import time
import argparse
import sys
import math
name="generator::endingPoint"
def debug(*args, **kwargs):
if( verbose == False ):
return
print(*args, file=sys.stderr, **kwargs)
def debug2(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
argsparser = argparse.ArgumentParser(description="dummy generator")
argsparser.add_argument("-f","--fps",help="Frame Per Second",default=30,type=int)
argsparser.add_argument("-s","--speed",help="point per frame progress",default=3,type=int)
argsparser.add_argument("-v","--verbose",action="store_true",help="Verbose output")
args = argsparser.parse_args()
fps=args.fps
verbose=args.verbose
optimal_looptime = 1 / fps
debug(name+" optimal looptime "+str(optimal_looptime))
width = 800
height = 800
white = 0xFFFFFF
blank = 0
point_offset = 250
point_width = 4
point_list = [
[8,7,6,10,7,3,6,2,7,11,6,9],
[5,6,1,],
[4,7,12,],
]
shape = []
# on ajoute des lilste de point
for l in point_list:
x = point_offset * ((l[0] - 1) % (point_width))
y = point_offset * int((l[0] - 1) / (point_width))
shape.append([x, y, blank])
debug2("=====")
debug2(f"id: {l[0]}\tx: {x}\ty: {y}\t\tpoint_width: {point_width}\t\n")
for p in l:
x = point_offset * ((p - 1) % (point_width))
y = point_offset * int((p - 1) / (point_width))
shape.append([x, y, white])
debug2(f"id: {p}\tx: {x}\ty: {y}\t\tpoint_width: {point_width}\t\n")
while True:
start = time.time()
print(shape, flush=True);
looptime = time.time() - start
if( looptime < optimal_looptime ):
time.sleep( optimal_looptime - looptime)
debug(name+" micro sleep:"+str( optimal_looptime - looptime))