Created
May 1, 2019 00:29
-
-
Save notionparallax/48d1d09d5ffb54e78a07e856e24065ab to your computer and use it in GitHub Desktop.
A nicer way to view the output from a GridEye in the terminal. Useful for headless debugging.
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
import random | |
import math | |
import time | |
low = 19.0 | |
high = 25.0 | |
def randInRange(): | |
spread = high - low | |
return (random.random() * spread) + low | |
def make_a_fake_grid(x=8, y=8): | |
outer = [] | |
for i in range(x): | |
outer.append([randInRange() for _ in range(y)]) | |
return outer | |
def displayChar(value, low=low, high=high, px_width=2): | |
# img_chars = "$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1[]?-_+~<>i!lI;:,^`'. " | |
# img_chars = " .:;+=xX$&" | |
img_chars = " ░▒▓█" | |
spread = high - low | |
transformedValue = value - low | |
pc = transformedValue / spread | |
i = math.floor(pc * len(img_chars)) | |
return img_chars[i] * px_width | |
while True: | |
grid = make_a_fake_grid() | |
for row in grid: | |
print("".join([displayChar(v) for v in row])) | |
print() | |
time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Produces something like this:
But it looks better in a real terminal.