Skip to content

Instantly share code, notes, and snippets.

@uintdev
Created March 7, 2019 23:19
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 uintdev/1bd53d9de08df1e9be3b49b101045afd to your computer and use it in GitHub Desktop.
Save uintdev/1bd53d9de08df1e9be3b49b101045afd to your computer and use it in GitHub Desktop.
rainpix
# rainpix.py
# a random coloured dot loop (gnu/linux only)
# i.e. python3 ./rainpix.py 50
import sys
import random
def loopy(char, amount):
# initilise variables
spacing = ""
stringBuilder = ""
currentCol = None
colList = [91, 92, 93, 94, 95, 96]
prepend = None
token = False
append = "\033[0;37;40m"
for _ in range(amount):
for ii in list(char):
while token == False:
# avoid repeating the next colour
if currentCol == None:
currentCol = random.choice(colList)
tmpCol = random.choice(colList)
if currentCol != tmpCol:
currentCol = tmpCol
# release from 3rd loop
token = True
# set colour and put string together
prepend = "\033[1;" + str(currentCol) + ";40m"
stringBuilder += prepend + ii + append
print(spacing + stringBuilder)
# add spacing for next loop
spacing += " "
token = False
try:
loop = sys.argv[1]
except IndexError:
print("[error] specify amount of times to loop (as an integer):", sys.argv[0], "[loop_count]")
sys.exit()
try:
loop = int(loop)
except ValueError:
print("[error] loop argument must be an integer")
sys.exit()
if loop <= 0:
print("[error] loop argument must be larger than 0")
sys.exit()
loopy(".", loop)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment