Skip to content

Instantly share code, notes, and snippets.

@Ishtiaq11
Created April 18, 2021 14:21
Show Gist options
  • Save Ishtiaq11/935cd634788ba2700ca1756b1222828a to your computer and use it in GitHub Desktop.
Save Ishtiaq11/935cd634788ba2700ca1756b1222828a to your computer and use it in GitHub Desktop.
Digital Stream by Ishtiaq Pias
import shutil,time,sys,random
MIN_STREAM_LENGTH = 5
MAX_STREAM_LENGTH = 15
DENSITY = 0.02
WIDTH = shutil.get_terminal_size()[0]
COLUMN = [0] * WIDTH
STREAM_CHARS = ['0', '1', '2', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F']
PAUSE = 0.1
print('Digital Streams by Ishtiaq Pias')
print('Press Ctrl-C to Stop')
time.sleep(1)
try:
while True:
for i, val in enumerate(COLUMN):
if val <= 0:
if random.random() <= DENSITY:
COLUMN[i] = random.randint(MIN_STREAM_LENGTH, MAX_STREAM_LENGTH)
print(' ', end='')
if val > 0:
print(random.choice(STREAM_CHARS), end='')
COLUMN[i] -= 1
# print(val, end='')
print()
time.sleep(PAUSE)
# input('Press Enter to continue')
except KeyboardInterrupt:
sys.exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment