Skip to content

Instantly share code, notes, and snippets.

@phantamanta44
Created July 21, 2016 23:12
Show Gist options
  • Save phantamanta44/797d6303cac80e7aa1bddc3794e8e765 to your computer and use it in GitHub Desktop.
Save phantamanta44/797d6303cac80e7aa1bddc3794e8e765 to your computer and use it in GitHub Desktop.
somewhat fancy printing
#!/usr/bin/env python
from sys import stdin, stdout, exit
from math import floor
from random import randint, choice
from time import sleep
def randChar():
return unichr(65382 + randint(0, 55))
totalFrames, frameTime = 80, 0.05
lines = stdin.readlines()
if len(lines) == 0:
exit(0)
totalLineTime = totalFrames / len(lines)
resolveDelay = int(floor(totalLineTime * 0.3))
lineTime = totalLineTime - resolveDelay
for lineRaw in lines:
line = lineRaw.replace("\n", "").replace("\t", " ")
if len(line) == 0:
stdout.write("\n")
stdout.flush()
continue
charTime = lineTime / len(line)
state, left = [False] * len(line), range(0, len(line))
for i in range(0, resolveDelay):
stdout.write("\r")
for j in range(0, len(line)):
stdout.write(randChar())
stdout.flush()
sleep(frameTime)
timeToChar = charTime
while len(left) > 0:
if timeToChar == 0:
ind = choice(left)
left.remove(ind)
state[ind] = True
timeToChar = charTime
else:
timeToChar -= 1
stdout.write("\r")
for i in range(0, len(line)):
if state[i]:
stdout.write(line[i])
else:
stdout.write(randChar())
stdout.flush()
sleep(frameTime)
stdout.write("\n")
stdout.flush()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment