Skip to content

Instantly share code, notes, and snippets.

@JoseitoOliveira
Last active January 17, 2023 20:12
Show Gist options
  • Save JoseitoOliveira/819ca7a0a58381210da260bf3720f3a9 to your computer and use it in GitHub Desktop.
Save JoseitoOliveira/819ca7a0a58381210da260bf3720f3a9 to your computer and use it in GitHub Desktop.
from itertools import cycle
from colorama import Fore, Back, Style, init as colorama_init
colorama_init()
def clear():
from os import system, name
if name == 'nt':
system('cls')
else:
system('clear')
class Widget:
_fore = Fore.WHITE
_back = Back.BLACK
_style = Style.NORMAL
def __init__(self, x, y, size, fore=None, back=None, style=None):
self.x = x
self.y = y
self.size = size
self.fore = fore if fore else Fore.WHITE
self.back = back if back else Back.BLACK
self.style = style if style else Style.NORMAL
def text(self, msg):
print("\033[%d;%dH" % (self.y, self.x), end='')
if Widget._back != self.back:
print(self.back, end='')
Widget._back = self.back
if Widget._fore != self.fore:
print(self.fore, end='')
Widget._fore = self.fore
if Widget._style != self.style:
print(self.style, end='')
Widget._style = self.style
print(f'{msg:<{self.size}}', end='')
backs = cycle([
Back.BLACK, Back.RED, Back.GREEN, Back.YELLOW,
Back.BLUE, Back.MAGENTA, Back.CYAN, Back.WHITE
])
widgets = []
clear()
for x in range(25):
widgets.append([])
for y in range(20):
widgets[x].append(Widget(x * 2 + 1, y + 1, 2))
i = 0
while True:
i += 1
for x in range(25):
back = next(backs)
for y in range(20):
widgets[x][y].back = back
widgets[x][y].text('')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment