Created
June 18, 2017 06:31
-
-
Save matfournier/0a243576de72cd23514f2bce6a201c61 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' print out binary place value patterns ''' | |
''' glitchy infinite scroll version ''' | |
''' hit any key to exit ''' | |
''' see https://github.com/mouse-reeve/placevalue_ascii ''' | |
import math | |
import argparse | |
import time | |
import sys | |
import os | |
import select | |
def placevalue_patterner(function, height, width, placevalue, offset_y=0,): | |
''' create a visualization of a place value pattern ''' | |
visual = [] | |
for i in range(offset_y, offset_y + height): | |
row = '' | |
for j in range(width): | |
value = function(i, j) | |
binary = '{0:b}'.format(int(value)) | |
if len(binary) > placevalue and binary[-1 * placevalue] == '1': | |
row += '*' | |
else: | |
row += ' ' | |
visual.append(row) | |
return '\n'.join(visual) | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser() | |
parser.add_argument('function', | |
help='The function to plot, e.g. "x ** 2 * y ** 2"', | |
type=lambda s: eval('lambda x, y: {}'.format(s))) | |
parser.add_argument('placevalue', type=int) | |
parser.add_argument('width', type=int) | |
parser.add_argument('delay', type=float) | |
args = parser.parse_args() | |
i = 0 | |
while True: | |
os.system('cls' if os.name == 'nt' else 'clear') | |
if sys.stdin in select.select([sys.stdin], [], [], 0)[0]: | |
line = input() | |
break | |
print(placevalue_patterner(args.function, i, args.width, | |
args.placevalue)) | |
time.sleep(args.delay) | |
i += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
python placevalue_inf.py "x2 - y2" 6 100 0.25