Compare commits
2 Commits
4f4f05532d
...
60da52df35
Author | SHA1 | Date | |
---|---|---|---|
|
60da52df35 | ||
|
d689a874f8 |
103
clitools/filters/colorcycle.py
Executable file
103
clitools/filters/colorcycle.py
Executable file
@ -0,0 +1,103 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# -*- mode: Python -*-
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
|
|
||||||
|
colorcycle
|
||||||
|
v0.1.0
|
||||||
|
|
||||||
|
A simple effect : cycle colors
|
||||||
|
|
||||||
|
LICENCE : CC
|
||||||
|
|
||||||
|
by cocoa
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
|
from __future__ import print_function
|
||||||
|
import sys
|
||||||
|
import ast
|
||||||
|
import os
|
||||||
|
import argparse
|
||||||
|
import random
|
||||||
|
import time
|
||||||
|
name = "filters::cycle"
|
||||||
|
|
||||||
|
argsparser = argparse.ArgumentParser(description="Redis exporter LJ")
|
||||||
|
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("-f","--fps",help="Frame Per Second",default=30,type=int)
|
||||||
|
argsparser.add_argument("-v","--verbose",action="store_true",help="Verbose")
|
||||||
|
|
||||||
|
args = argsparser.parse_args()
|
||||||
|
fps = args.fps
|
||||||
|
centerX = args.centerX
|
||||||
|
centerY = args.centerY
|
||||||
|
verbose = args.verbose
|
||||||
|
|
||||||
|
optimal_looptime = 1 / fps
|
||||||
|
|
||||||
|
UP = 5
|
||||||
|
DOWN = -5
|
||||||
|
currentColor = [0,0,0]
|
||||||
|
composant = 0
|
||||||
|
currentDirection = UP
|
||||||
|
|
||||||
|
def debug(*args, **kwargs):
|
||||||
|
if( verbose == False ):
|
||||||
|
return
|
||||||
|
print(*args, file=sys.stderr, **kwargs)
|
||||||
|
|
||||||
|
def rgb2int(rgb):
|
||||||
|
return int('0x%02x%02x%02x' % tuple(rgb),0)
|
||||||
|
|
||||||
|
def cycleColor( pl ):
|
||||||
|
|
||||||
|
global composant
|
||||||
|
global currentDirection
|
||||||
|
# debug(name,"pl:{}".format(pl))
|
||||||
|
value = currentColor[composant]
|
||||||
|
if currentDirection == UP:
|
||||||
|
target = 255
|
||||||
|
else:
|
||||||
|
target = 0
|
||||||
|
value += currentDirection
|
||||||
|
currentColor[composant] = value
|
||||||
|
|
||||||
|
debug(name,"currentColor:{}".format(currentColor))
|
||||||
|
for i in range( 0, len(pl)):
|
||||||
|
pl[i][2] = rgb2int( currentColor)
|
||||||
|
|
||||||
|
# change the composant if target reached
|
||||||
|
if value == target:
|
||||||
|
composant = random.randint( 0,2)
|
||||||
|
value = currentColor[composant]
|
||||||
|
if value == 0 :
|
||||||
|
currentDirection = UP
|
||||||
|
else:
|
||||||
|
currentDirection = DOWN
|
||||||
|
#debug( "pl:{}".format(pl))
|
||||||
|
return pl
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
start = time.time()
|
||||||
|
line = sys.stdin.readline()
|
||||||
|
if line == "":
|
||||||
|
time.sleep(0.01)
|
||||||
|
line = line.rstrip('\n')
|
||||||
|
pointsList = ast.literal_eval(line)
|
||||||
|
# Do the filter
|
||||||
|
result = cycleColor( pointsList )
|
||||||
|
print( result, flush=True )
|
||||||
|
looptime = time.time() - start
|
||||||
|
# debug(name+" looptime:"+str(looptime))
|
||||||
|
if( looptime < optimal_looptime ):
|
||||||
|
time.sleep( optimal_looptime - looptime)
|
||||||
|
# debug(name+" micro sleep:"+str( optimal_looptime - looptime))
|
||||||
|
except EOFError:
|
||||||
|
debug(name+" break")# no more information
|
||||||
|
|
@ -42,7 +42,7 @@ debug(name+" optimal looptime "+str(optimal_looptime))
|
|||||||
while True:
|
while True:
|
||||||
start = time.time()
|
start = time.time()
|
||||||
#print("[(100.0, 100.0, 65280), (100.0, 500.0, 65280), (500.0, 500.0, 65280), (500.0, 100.0, 65280), (100.0, 100.0, 65280)]", flush=True);
|
#print("[(100.0, 100.0, 65280), (100.0, 500.0, 65280), (500.0, 500.0, 65280), (500.0, 100.0, 65280), (100.0, 100.0, 65280)]", flush=True);
|
||||||
print("[(100.0, 100.0, 65280), (110.0, 500.0, 65280), (510.0, 500.0, 65280), (510.0, 100.0, 65280), (100.0, 110.0, 65280)]", flush=True);
|
print("[[100.0, 100.0, 65280], [110.0, 500.0, 65280], [510.0, 500.0, 65280], [510.0, 100.0, 65280], [100.0, 110.0, 65280]]", flush=True);
|
||||||
looptime = time.time() - start
|
looptime = time.time() - start
|
||||||
if( looptime < optimal_looptime ):
|
if( looptime < optimal_looptime ):
|
||||||
time.sleep( optimal_looptime - looptime)
|
time.sleep( optimal_looptime - looptime)
|
||||||
|
Loading…
Reference in New Issue
Block a user