Skip to content

Instantly share code, notes, and snippets.

@cmdneo
Last active December 31, 2019 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmdneo/57421dba388297797cfb8d5366e34d69 to your computer and use it in GitHub Desktop.
Save cmdneo/57421dba388297797cfb8d5366e34d69 to your computer and use it in GitHub Desktop.
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