Skip to content

Instantly share code, notes, and snippets.

@cmdneo
Last active Dec 31, 2019
Embed
What would you like to do?
Prints a bunch of random 24-bit colors(3 char width) to the terminal using ansi escsape codes.
r"""Prints random 24-bit colors(3 char width)
to the terminal using ansi escsape codes.
Use like:
python ansi-cols.py NO_OF_COLORED_CELLS
Example:
python ansi-cols.py 69_420
"""
import sys
import random
limit = 0
try:
limit = int(sys.argv[1])
except (IndexError, ValueError):
print("Give number of cells to print, like: python ansi-cols.py 69420")
sys.exit(1)
for _x in range(limit):
cols = [random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)]
print(f"\033[48;2;{cols[0]};{cols[1]};{cols[2]}m \033[0m", end="")
print("\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment