An Interest In:
Web News this Week
- April 24, 2024
- April 23, 2024
- April 22, 2024
- April 21, 2024
- April 20, 2024
- April 19, 2024
- April 18, 2024
September 24, 2021 07:36 pm GMT
Original Link: https://dev.to/sagordondev/matrix-console-screensaver-59ih
Matrix Console Screensaver
# digital_stream.py# This program emulates a screensaver in the style of the Matrix movie's visuals.# by: Scott Gordonimport randomimport shutilimport sysimport timeMIN_STREAM_LENGTH = 6MAX_STREAM_LENGTH = 14PAUSE = 0.1STREAM_CHARS = ['0', '1']# Density can range from 0.0 to 1.0DENSITY = 0.02WIDTH = shutil.get_terminal_size()[0]WIDTH -= 1 # To prevent newlineMATRIX_GREEN = '\033[92m'print('***** Digital Stream *****')print('Press Ctrl-C to quit.')time.sleep(2)try: columns = [0] * WIDTH while True: for i in range(WIDTH): if columns[i] == 0: if random.random() <= DENSITY: columns[i] = random.randint( MIN_STREAM_LENGTH, MAX_STREAM_LENGTH) if columns[i] > 0: print(MATRIX_GREEN + random.choice(STREAM_CHARS), end='') columns[i] -= 1 else: print(' ', end='') print() sys.stdout.flush() # Make sure text appears on the screen. time.sleep(PAUSE)except KeyboardInterrupt: sys.exit() # Exit with Ctrl-C
Photo by Markus Spiske on Unsplash
Original Link: https://dev.to/sagordondev/matrix-console-screensaver-59ih
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To