Created
May 5, 2022 06:34
-
-
Save nvanderw/b86024b4039efbea22d8fec32da7ad82 to your computer and use it in GitHub Desktop.
A multi-colored blessed screensaver
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
from blessed import Terminal | |
from colorsys import hsv_to_rgb | |
from time import sleep | |
from random import randrange, choice | |
from sys import stdout | |
# Print with no trailing newline | |
def printn(*args, **kwargs): | |
kwargs['end'] = '' | |
print(*args, **kwargs) | |
if __name__ == "__main__": | |
term = Terminal() | |
all_chars = r"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`~!@#$%^&*()_+-=[]{}\|;':,./<>?" | |
printn(term.clear + term.home) | |
hue = 0 | |
width, height = term.width, term.height | |
pos_x, pos_y = randrange(width), randrange(height) | |
vx, vy = 1, 1 | |
with term.hidden_cursor(): | |
while True: | |
# printn(term.move_xy(pos_x, pos_y)) | |
# printn(" ") | |
pos_x, pos_y = pos_x + vx, pos_y + vy | |
if pos_x < 0: | |
pos_x = 1 | |
vx = 1 | |
elif pos_x >= width: | |
pos_x = width - 2 | |
vx = -1 | |
if pos_y < 0: | |
pos_y = 1 | |
vy = 1 | |
elif pos_y >= height: | |
pos_y = height - 2 | |
vy = -1 | |
printn(term.move_xy(pos_x, pos_y)) | |
red, green, blue = hsv_to_rgb(hue / 255, 1, 1) | |
color = term.color_rgb(int(red * 255), int(green * 255), int(blue * 255)) | |
printn(term.bold(color(choice(all_chars)))) | |
hue = (hue + 7) & 0xff | |
stdout.flush() | |
sleep(0.001) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment