Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
September 24, 2021 07:36 pm GMT

Matrix Console Screensaver

Console Output
GitHub Repo

# 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

Verify my Python Skills

Photo by Markus Spiske on Unsplash


Original Link: https://dev.to/sagordondev/matrix-console-screensaver-59ih

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To