forked from protonphoton/LJ
		
	[enh] adds a tunnel generator and a null output
This commit is contained in:
		
							parent
							
								
									9df9d66557
								
							
						
					
					
						commit
						e3361e9482
					
				
							
								
								
									
										46
									
								
								clitools/exports/toNull.py
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										46
									
								
								clitools/exports/toNull.py
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,46 @@ | ||||
| #!/usr/bin/python3 | ||||
| # -*- coding: utf-8 -*- | ||||
| # -*- mode: Python -*- | ||||
| 
 | ||||
| 
 | ||||
| ''' | ||||
| 
 | ||||
| The exporter that drops all traffic ! | ||||
| v0.1.0 | ||||
| 
 | ||||
| A basic exporter  | ||||
| 
 | ||||
| LICENCE : CC | ||||
| 
 | ||||
| by cocoa  | ||||
| 
 | ||||
| 
 | ||||
| ''' | ||||
| from __future__ import print_function | ||||
| import sys | ||||
| import os | ||||
| import argparse | ||||
| import redis | ||||
| import time  | ||||
| 
 | ||||
| argsparser = argparse.ArgumentParser(description="Null exporter LJ") | ||||
| argsparser.add_argument("-v","--verbose",action="store_true",help="Verbose") | ||||
| args = argsparser.parse_args() | ||||
| 
 | ||||
| verbose=args.verbose | ||||
| 
 | ||||
| name    = "exports::toNull" | ||||
| def debug(*args, **kwargs): | ||||
|     if( verbose == False ): | ||||
|         return | ||||
|     print(*args, file=sys.stderr, **kwargs) | ||||
| 
 | ||||
| try: | ||||
|     while True: | ||||
|       line = sys.stdin.readline() | ||||
|       if line == "": | ||||
|          time.sleep(0.01) | ||||
|       debug(name,"dumping: "+line) | ||||
| except EOFError: | ||||
|     debug("break")# no more information | ||||
| 
 | ||||
							
								
								
									
										111
									
								
								clitools/generators/tunnel.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										111
									
								
								clitools/generators/tunnel.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,111 @@ | ||||
| #!/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)) | ||||
|    | ||||
| 
 | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user