├── biggerblocks.png ├── colorblocks.py ├── default.png ├── default2.png ├── gapprob0.png ├── gapprobhigh.png ├── min1_max4.png ├── poundchar.png ├── readme.md └── samecolorrow.png /biggerblocks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zzggbb/colorblocks/47f1cadcf168c1b157058ab0a2f18366d515fbc8/biggerblocks.png -------------------------------------------------------------------------------- /colorblocks.py: -------------------------------------------------------------------------------- 1 | #!/bin/env python3 2 | """colorblocks.py - output random colored blocks 3 | 4 | Usage: 5 | colorblocks.py [-m MIN] [-M MAX] [-g GAP] [-c CH] [-s] 6 | 7 | Options: 8 | -m MIN, --min MIN Set the min width of a block 9 | [default: 4] 10 | -M MAX, --max MAX Set the max width of a block 11 | [default: 10] 12 | -g GAP, --gap GAP Set the probability of a block being a gap 13 | [default: 0.3] 14 | -c CH, --char CH Set the character that composes a block. 15 | [default: ] 16 | -s, --same Make all blocks within a row have the same color 17 | 18 | """ 19 | from docopt import docopt 20 | import random 21 | import subprocess 22 | 23 | echo = lambda s: print(s, end="") 24 | rand_fg = lambda: random.choice(range(31,38)) 25 | 26 | class canvas(): 27 | def __init__(self): 28 | self.size = map(int, subprocess.check_output(['stty','size']).split()) 29 | def __enter__(self): 30 | echo('\033[?25l') 31 | return self.size 32 | def __exit__(self, type, value, traceback): 33 | subprocess.call('tput reset'.split()) 34 | return True 35 | 36 | def distribute(min, max, total): 37 | """ 38 | generate a list of numbers between `min` and `max` that adds up to `total` 39 | """ 40 | if total < max: 41 | return [total] 42 | block = random.choice(range(min, max+1)) 43 | return [block] + distribute(min, max, total-block ) 44 | 45 | if __name__ == '__main__': 46 | args = {k[2:]:v for k,v in docopt(__doc__).items()} 47 | min,max,gap = int(args['min']),int(args['max']), float(args['gap']) 48 | same, char = args['same'],args['char'] 49 | 50 | if min > max: 51 | raise ValueError('min must be less than max') 52 | 53 | with canvas() as (rows, cols): 54 | for row in range(rows): 55 | row_color = rand_fg() 56 | for size in distribute(min, max, cols): 57 | colored = gap <= random.random() 58 | color = (row_color if same else rand_fg()) if colored else 49 59 | char = char if colored else " " 60 | if colored and char == " ": 61 | color+=10 62 | echo("\033[{}m{}".format(color, char * size)) 63 | input() 64 | -------------------------------------------------------------------------------- /default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zzggbb/colorblocks/47f1cadcf168c1b157058ab0a2f18366d515fbc8/default.png -------------------------------------------------------------------------------- /default2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zzggbb/colorblocks/47f1cadcf168c1b157058ab0a2f18366d515fbc8/default2.png -------------------------------------------------------------------------------- /gapprob0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zzggbb/colorblocks/47f1cadcf168c1b157058ab0a2f18366d515fbc8/gapprob0.png -------------------------------------------------------------------------------- /gapprobhigh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zzggbb/colorblocks/47f1cadcf168c1b157058ab0a2f18366d515fbc8/gapprobhigh.png -------------------------------------------------------------------------------- /min1_max4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zzggbb/colorblocks/47f1cadcf168c1b157058ab0a2f18366d515fbc8/min1_max4.png -------------------------------------------------------------------------------- /poundchar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zzggbb/colorblocks/47f1cadcf168c1b157058ab0a2f18366d515fbc8/poundchar.png -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | ## colorblocks 2 | 3 | a script that outputs randomly colored and sized blocks 4 | 5 | ``` 6 | Usage: 7 | colorblocks.py [-m MIN] [-M MAX] [-g GAP] [-c CH] [-s] 8 | 9 | Options: 10 | -m MIN, --min MIN Set the min width of a block 11 | [default: 4] 12 | -M MAX, --max MAX Set the max width of a block 13 | [default: 10] 14 | -g GAP, --gap GAP Set the probability of a block being a gap 15 | [default: 0.3] 16 | -c CH, --char CH Set the character that composes a block. 17 | [default: ] 18 | -s, --same Make all blocks within a row have the same color 19 | ``` 20 | 21 | ![default](https://github.com/zzggbb/colorblocks/raw/master/default.png) 22 | -------------------------------------------------------------------------------- /samecolorrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zzggbb/colorblocks/47f1cadcf168c1b157058ab0a2f18366d515fbc8/samecolorrow.png --------------------------------------------------------------------------------