Skip to content

Instantly share code, notes, and snippets.

@cppxor2arr
Created January 26, 2018 16:07
Show Gist options
  • Save cppxor2arr/7baad01974dc78137962fc9ec765cb82 to your computer and use it in GitHub Desktop.
Save cppxor2arr/7baad01974dc78137962fc9ec765cb82 to your computer and use it in GitHub Desktop.
Python IRC Extended Color Code Gradient Rainbow Script
#!/usr/bin/env python3
import random, itertools
from sys import argv
def main():
num_color_hue, num_brightness, min_color, max_color = 12, 6, 16, 76
color_hue, brightness = random.randint(0, num_color_hue - 1), random.randint(0, num_brightness - 1)
direction1, direction2 = random.choice([ -1, 1 ]), random.choice([-1, 1])
color = next(itertools.islice(range(min_color + color_hue, max_color + 1 + color_hue, num_color_hue),
brightness, brightness + 1))
if len(argv) < 2:
return 1
string, color_msg = ' '.join(argv[1:]), '\x02'
for i in range(len(string)):
if string[i] != ' ':
color_msg += "\x03" + str(color) + string[i]
color += direction1 * num_color_hue
if color < min_color + color_hue:
if color_hue == 0 and direction2 == -1:
color_hue = num_color_hue - 1
color = min_color + color_hue
elif color_hue == num_color_hue - 1 and direction2 == 1:
color_hue = 0
color = min_color + color_hue
else:
color_hue += direction2
color += num_color_hue + direction2
direction1 = -direction1
elif color > max_color + color_hue:
if color_hue == num_color_hue - 1 and direction2 == 1:
color_hue = 0
color = max_color + color_hue
elif color_hue == 0 and direction2 == -1:
color_hue == num_color_hue - 1
color = max_color + color_hue
else:
color_hue += direction2
color += -num_color_hue + direction2
direction1 = -direction1
else:
color_msg += ' '
print(color_msg)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment