112 lines
3.0 KiB
Python
112 lines
3.0 KiB
Python
|
#!/usr/bin/python3
|
||
|
# -*- coding: utf-8 -*-
|
||
|
# -*- mode: Python -*-
|
||
|
|
||
|
|
||
|
'''
|
||
|
|
||
|
Woooh! I'm progressing in a tunnel !
|
||
|
v0.1.0
|
||
|
|
||
|
Use it to test your filters and outputs
|
||
|
|
||
|
LICENCE : CC
|
||
|
|
||
|
by cocoa
|
||
|
|
||
|
'''
|
||
|
|
||
|
from __future__ import print_function
|
||
|
import time
|
||
|
import argparse
|
||
|
import sys
|
||
|
name="generator::tunnel"
|
||
|
|
||
|
def debug(*args, **kwargs):
|
||
|
if( verbose == False ):
|
||
|
return
|
||
|
print(*args, file=sys.stderr, **kwargs)
|
||
|
|
||
|
|
||
|
argsparser = argparse.ArgumentParser(description="tunnel generator")
|
||
|
argsparser.add_argument("-x","--centerX",help="geometrical center X position",default=300,type=int)
|
||
|
argsparser.add_argument("-y","--centerY",help="geometrical center Y position",default=300,type=int)
|
||
|
argsparser.add_argument("-s","--speed",help="point per frame progress",default=3,type=int)
|
||
|
argsparser.add_argument("-i","--interval",help="point per form interval",default=30,type=int)
|
||
|
argsparser.add_argument("-m","--max-size",help="maximum size for objects",default=300,type=int)
|
||
|
argsparser.add_argument("-f","--fps",help="Frame Per Second",default=30,type=int)
|
||
|
argsparser.add_argument("-c","--color",help="Color",default=65280,type=int)
|
||
|
argsparser.add_argument("-v","--verbose",action="store_true",help="Verbose output")
|
||
|
|
||
|
args = argsparser.parse_args()
|
||
|
color = args.color
|
||
|
fps = args.fps
|
||
|
centerX = args.centerX
|
||
|
centerY = args.centerY
|
||
|
interval = args.interval
|
||
|
max_size = args.max_size
|
||
|
speed = args.speed
|
||
|
verbose = args.verbose
|
||
|
|
||
|
optimal_looptime = 1 / fps
|
||
|
square = [
|
||
|
[-1,1],
|
||
|
[1,1],
|
||
|
[1,-1],
|
||
|
[-1,-1],
|
||
|
[-1,1]
|
||
|
]
|
||
|
|
||
|
class polylineGenerator( object ):
|
||
|
|
||
|
def __init__( self ):
|
||
|
self.polylineList = [0]
|
||
|
self.buf = []
|
||
|
|
||
|
def draw( self ):
|
||
|
self.buf = []
|
||
|
for it_pl, size in enumerate(self.polylineList):
|
||
|
for it_sqr, point in enumerate(square):
|
||
|
x = centerX + point[0]*size
|
||
|
y = centerY + point[1]*size
|
||
|
# Add an invisible point in first location
|
||
|
if 0 == it_sqr:
|
||
|
self.buf.append([x,y,0])
|
||
|
self.buf.append([x,y,color])
|
||
|
debug( name, "buf size:", str(len(self.buf)) )
|
||
|
return self.buf
|
||
|
|
||
|
def increment(self):
|
||
|
self.buffer = []
|
||
|
min_size = 9999
|
||
|
delList = []
|
||
|
for i, size in enumerate(self.polylineList):
|
||
|
size += speed
|
||
|
if size < min_size : min_size = size
|
||
|
if size > max_size : delList.append(i)
|
||
|
self.polylineList[i] = size
|
||
|
for i in delList:
|
||
|
del self.polylineList[i]
|
||
|
if min_size >= interval: self.polylineList.append(0)
|
||
|
debug(name, "polyline:",self.polylineList)
|
||
|
|
||
|
pgen = polylineGenerator()
|
||
|
|
||
|
|
||
|
while True:
|
||
|
start = time.time()
|
||
|
|
||
|
# Generate
|
||
|
pgen.increment()
|
||
|
|
||
|
# send
|
||
|
print(pgen.draw(), flush=True);
|
||
|
|
||
|
|
||
|
looptime = time.time() - start
|
||
|
if( looptime < optimal_looptime ):
|
||
|
time.sleep( optimal_looptime - looptime)
|
||
|
debug(name+" micro sleep:"+str( optimal_looptime - looptime))
|
||
|
|
||
|
|