-
-
Save damncabbage/a84d37ffa192c1d102c1431abdc83c6f to your computer and use it in GitHub Desktop.
This file contains 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 sys | |
from time import sleep | |
import random | |
import cursor | |
class Renderer: | |
def __init__(self, width, height): | |
self.width = int(width) | |
self.height = int(height) | |
self.content = [ width * ' ' for i in range(0,height) ] | |
self.currentX = 0 | |
self.currentY = 0 | |
def render(self): | |
self.moveToOrigin() | |
sys.stdout.write('\n'.join(self.content)) | |
sys.stdout.flush() | |
self.currentX = len(self.content[0]) | |
self.currentY = len(self.content) - 1 | |
def moveToOrigin(self): | |
self.moveBy(-self.currentX,-self.currentY) | |
def moveBy(self,x,y): | |
self.currentX += x | |
self.currentY += y | |
if x < 0: | |
xMove = '\033[%iD' % -x | |
elif x > 0: | |
xMove = '\033[%iC' % x | |
else: | |
xMove = '' | |
if y < 0: | |
yMove = '\033[%iA' % -y | |
elif y > 0: | |
yMove = '\033[%iB' % y | |
else: | |
yMove = '' | |
#print(x,y) | |
sys.stdout.write(xMove + yMove) | |
def setChar(self, char): | |
self.setCharAt(self.currentX, self.currentY, char) | |
def setCharAt(self, x, y, char): | |
self.content[y] = self.content[y][0:x] + char[0] + self.content[y][x+1:] | |
def setContent(self, content): | |
self.content = content | |
cursor.hide() | |
try: | |
print() | |
w = 80 | |
h = 7 | |
framerate = 3 | |
renderer = Renderer(w,h) | |
spoke_hole = '◌' | |
data_holes = ' ●' | |
lines = [[],[],[],[],[],[],[]] | |
while True: | |
renderer.setContent([ ''.join(lines[i]) for i in range(0,h) ]) | |
renderer.render() | |
for i in range(0,h): | |
if i == 6: | |
lines[i] += [' ',' '] | |
elif i == 2: | |
lines[i] = [spoke_hole,' '] + lines[i] | |
else: | |
lines[i] = [random.choice(data_holes),' '] + lines[i] | |
lines[i] = lines[i][0:w] | |
sleep(1/framerate) | |
except KeyboardInterrupt: pass | |
except Exception: pass | |
cursor.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment