Skip to content

Instantly share code, notes, and snippets.

@notionparallax
Created May 1, 2019 00:29
Show Gist options
  • Save notionparallax/48d1d09d5ffb54e78a07e856e24065ab to your computer and use it in GitHub Desktop.
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.
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)
@notionparallax
Copy link
Author

notionparallax commented May 1, 2019

Produces something like this:

░░▓▓  ░░▓▓░░░░░░
▓▓░░░░▒▒  ░░  ░░
▓▓▓▓  ░░▓▓  ██░░
██░░██████▓▓██▒▒
  ██▓▓▓▓▓▓░░████
▓▓  ░░▒▒██░░  ██
  ░░  ░░  ▓▓▒▒▓▓
▓▓▒▒██▒▒▒▒▓▓▓▓░░

But it looks better in a real terminal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment