diff --git a/clitools/generators/drawingTests/adjust_brightness.py b/clitools/generators/drawingTests/adjust_brightness.py new file mode 100644 index 0000000..060be26 --- /dev/null +++ b/clitools/generators/drawingTests/adjust_brightness.py @@ -0,0 +1,73 @@ + +#!/usr/bin/python3 +# -*- coding: utf-8 -*- +# -*- mode: Python -*- + + +''' + +This generator print different squar from big to small. +The purepose is to see the difference of brightness with the length + +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) + +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 +offset = 50 + +white = 0xFFFFFF +blank = 0x0 + +shape = [] + +def set_shape(): + nb_spire = int(width / (2 * offset)) - 1 + for i in range(1, nb_spire + 1): + shape.append([ i * offset, i * offset, blank]) + shape.append([ i * offset, i * offset, white]) + shape.append([ i * offset, height - i * offset, white]) + shape.append([width - i * offset, height - i * offset, white]) + shape.append([width - i * offset, i * offset, white]) + shape.append([ i * offset, i * offset, white]) + shape.append([ i * offset, i * offset, blank]) + +set_shape() + +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)) diff --git a/clitools/generators/drawingTests/angleInteractive.py b/clitools/generators/drawingTests/angleInteractive.py new file mode 100644 index 0000000..3fa8e30 --- /dev/null +++ b/clitools/generators/drawingTests/angleInteractive.py @@ -0,0 +1,262 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- +# -*- mode: Python -*- + + +''' + +This generator print diferent one angle but you can modify it interactively. +The key are: + * '' => *somthing* + * ... + +v0.1.0 + +LICENCE : CC + +by lapin (aka nipal) + +''' + +from __future__ import print_function +import time +import argparse +import math +import sys +# import for non-bloking input reading +#import sys +import select +import tty +import termios + +name="generator::endingPoint" + +def debug(*args, **kwargs): + if( verbose == False ): + return + print(*args, file=sys.stderr, **kwargs) + +def isData(): + return select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], []) + +def flush_input(): + try: + import msvcrt + while msvcrt.kbhit(): + msvcrt.getch() + except ImportError: + import sys, termios #for linux/unix + termios.tcflush(sys.stdin, termios.TCIOFLUSH) + +old_settings = termios.tcgetattr(sys.stdin) + + +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 = 0x0 + +seg1_length = 100 +seg2_length = 100 +ang = 50 + +incrLengthLittle= 5 +incrLengthLot= 20 +incrAngleLittle= 1 +incrAngleLot= 10 +angle_min = 0 +angle_max = 90 +length_min = 1 +length_max = 350 + +shape = [] + +# angle +def ang_add_1(): + global ang + + if ang + incrAngleLittle <= angle_max: + ang += incrAngleLittle + else: + ang = angle_max + +def ang_add_2(): + global ang + + if ang + incrAngleLot <= angle_max: + ang += incrAngleLot + else: + ang = angle_max + +def ang_sub_1(): + global ang + + if ang - incrAngleLittle >= angle_min: + ang -= incrAngleLittle + else: + ang = angle_min + +def ang_sub_2(): + global ang + + if ang - incrAngleLot >= angle_min: + ang -= incrAngleLot + else: + ang = angle_min + +# seg1 +def seg_1_add_1(): + global seg1_length + + if seg1_length + incrLengthLittle <= length_max: + seg1_length += incrLengthLittle + else: + seg1_length = length_max + +def seg_1_add_2(): + global seg1_length + + if seg1_length + incrLengthLot <= length_max: + seg1_length += incrLengthLot + else: + seg1_length = length_max + +def seg_1_sub_1(): + global seg1_length + + if seg1_length - incrLengthLittle >= length_min: + seg1_length -= incrLengthLittle + else: + seg1_length = length_min + +def seg_1_sub_2(): + global seg1_length + + if seg1_length - incrLengthLot >= length_min: + seg1_length -= incrLengthLot + else: + seg1_length = length_min + +# seg2 +def seg_2_add_1(): + global seg2_length + + if seg2_length + incrLengthLittle <= length_max: + seg2_length += incrLengthLittle + else: + seg2_length = length_max + +def seg_2_add_2(): + global seg2_length + + if seg2_length + incrLengthLot <= length_max: + seg2_length += incrLengthLot + else: + seg2_length = length_max + +def seg_2_sub_1(): + global seg2_length + + if seg2_length - incrLengthLittle >= length_min: + seg2_length -= incrLengthLittle + else: + seg2_length = length_min + +def seg_2_sub_2(): + global seg2_length + + if seg2_length - incrLengthLot >= length_min: + seg2_length -= incrLengthLot + else: + seg2_length = length_min + +action = { + # segment 1 + 'q': seg_1_sub_1, + 'w': ssg_1_add_1, + 'a': seg_1_sub_2, + 's': seg_1_add_2, + + # segment 2 + 'o': seg_2_sub_1, + 'p': seg_2_add_1, + 'l': seg_2_sub_2, + ';': seg_2_add_2, + + # angle + 't': ang_sub_1, + 'y': ang_add_1, + 'g': ang_sub_2, + 'h': ang_add_2, + } + +def print_param(): + debug("\n\n===") + debug("segment 1 length:", seg1_length) + debug("segment 2 length:", seg2_length) + debug("angle:", ang) + +def set_shape(): + global shape + shape.clear() + + cx = width / 2 + cy = height / 2 + + px1 = int(seg1_length * math.cos(math.radians(ang))) + py1 = int(seg1_length * math.sin(math.radians(ang))) + px2 = int(seg2_length * math.cos(math.radians(ang))) + py2 = int(seg2_length * math.sin(math.radians(ang))) + + # line up + shape.append([-px1 + cx, -py1 + cy, blank]) + shape.append([-px1 + cx, -py1 + cy, white]) + shape.append([ cx, + cy, white]) + shape.append([ px2 + cx, -py2 + cy, white]) + shape.append([ px2 + cx, -py2 + cy, blank]) + + # line down + shape.append([ px1 + cx, py1 + cy, blank]) + shape.append([ px1 + cx, py1 + cy, white]) + shape.append([ cx, + cy, white]) + shape.append([-px2 + cx, py2 + cy, white]) + shape.append([-px2 + cx, py2 + cy, blank]) + +def update_param(c): + if c in action: + action[c]() + print_param() + set_shape() + +try: + tty.setcbreak(sys.stdin.fileno()) + + set_shape() + print_param() + print(shape, flush=True); + while 1: + if isData(): + c = sys.stdin.read(1) + update_param(c) + + 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)) + +finally: + termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings) diff --git a/clitools/generators/drawingTests/keyborad_input.py b/clitools/generators/drawingTests/keyborad_input.py new file mode 100644 index 0000000..88a357d --- /dev/null +++ b/clitools/generators/drawingTests/keyborad_input.py @@ -0,0 +1,77 @@ +# code exemple find at : https://stackoverflow.com/questions/2408560/python-nonblocking-console-input + +import sys +import select +import tty +import termios + +def isData(): + return select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], []) + +old_settings = termios.tcgetattr(sys.stdin) + +try: + tty.setcbreak(sys.stdin.fileno()) + + i = 0 + while 1: + #if i % 100000 == 0: + # print("i", i) + #i += 1 + if isData(): + c = sys.stdin.read(1) + print(c) + if c == '\x1b': # x1b is ESC + break + +finally: + termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings) + + + +### for windows +#import msvcrt +# +#num = 0 +#done = False +#while not done: +# print(num) +# num += 1 +# +# if msvcrt.kbhit(): +# print "you pressed",msvcrt.getch(),"so now i will quit" +# done = True +# + +## cross platforme (but may be a bit huge to import pygame...) +#import pygame +#from pygame.locals import * +# +#def display(str): +# text = font.render(str, True, (255, 255, 255), (159, 182, 205)) +# textRect = text.get_rect() +# textRect.centerx = screen.get_rect().centerx +# textRect.centery = screen.get_rect().centery +# +# screen.blit(text, textRect) +# pygame.display.update() +# +#pygame.init() +#screen = pygame.display.set_mode( (640,480) ) +#pygame.display.set_caption('Python numbers') +#screen.fill((159, 182, 205)) +# +#font = pygame.font.Font(None, 17) +# +#num = 0 +#done = False +#while not done: +# display( str(num) ) +# num += 1 +# +# pygame.event.pump() +# keys = pygame.key.get_pressed() +# if keys[K_ESCAPE]: +# done = True +# +