LJ/examples/python/dummy.py

94 lines
2.6 KiB
Python
Raw Normal View History

2023-07-16 23:22:27 +00:00
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# -*- mode: Python -*-
'''
This is the most basic generator you can imagine: straight up static!
v0.1.0
LICENCE : CC
by cocoa
'''
import time
import argparse
import sys
import redis
argsparser = argparse.ArgumentParser(description="dummy generator")
argsparser.add_argument("-f","--fps",help="Frame Per Second (30)",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",default="True",help="Verbose output")
argsparser.add_argument("-a","--algo",help="Algorithm : mire, square,line",default="mire",type=str)
argsparser.add_argument("-i","--ip",help="IP address of the Redis server (127.0.0.1)",default="127.0.0.1",type=str)
argsparser.add_argument("-p","--port",help="Port of the Redis server (6379)",default="6379",type=str)
argsparser.add_argument("-k","--key",help="Redis key to update, default (/pl/0/0)",default="/pl/0/0",type=str)
args = argsparser.parse_args()
r=redis.StrictRedis(host=args.ip, port=args.port, db=0)
fps=args.fps
verbose=args.verbose
optimal_looptime = 1 / fps
color = 16777215
square = [(0.0, 0.0, color), (0.0, 300.0, color), (300.0, 300.0, color), (300.0, 0.0, color), (0.0, 0.0, color)]
line =[]
for i in range(00,800,int(800/120)):
line.append((i, 400, color))
mire = [
(600-400,600-400,0),
(600-400,600-400,color),
(700-400,600-400,color),
(700-400,700-400,color),
(600-400,700-400,color),
(600-400,600-400,color),
(100-400,100-400,0),
(100-400,100-400,color),
(200-400,100-400,color),
(200-400,200-400,color),
(100-400,200-400,color),
(100-400,100-400,color),
(0-400,0-400,0),
(0-400,0-400,color),
(800-400,0-400,color),
(800-400,800-400,color),
(0-400,800-400,color),
(0-400,0-400,color),
(350-400,400-400,0),
(350-400,400-400,color),
(450-400,400-400,color),
(400-400,350-400,0),
(400-400,350-400,color),
(400-400,450-400,color)
]
match args.algo:
case "mire":
shape = str(mire)
case 'line':
shape = str(line)
case "square":
shape = str(square)
def debug(text):
if args.verbose:
print(text)
while True:
start = time.time()
if r.set(args.key,shape)==True:
debug("redis set("+str(args.key)+") to "+shape)
looptime = time.time() - start
if( looptime < optimal_looptime ):
time.sleep( optimal_looptime - looptime)
debug("micro sleep: "+str( optimal_looptime - looptime))