added rainbow.py

This commit is contained in:
iou1name 2017-11-26 00:15:05 -05:00
parent f56f3b9193
commit 315be48d01

26
rainbow.py Normal file
View File

@ -0,0 +1,26 @@
#! /usr/bin/env python3
# coding=utf-8
import sys, time
#timeStart = time.time()
rainbow = "rrooyyYYGGggccCCBBbbmmMM"
colorCode = {'r':5, 'o':4, 'y':7, 'Y':8, 'g':3, 'G':9, 'c':10, 'C':11, 'b':2, 'B':12, 'm':6, 'M':13, 0:1, 1:14, 2:15, 'w':0}
with open(sys.argv[1], 'r+', encoding="utf-8") as file:
lines = file.readlines()
rainbowified = ""
start = 0
for line in lines:
n = (start % len(rainbow))
for char in line:
rainbowified = rainbowified + '\x03' + str(colorCode[rainbow[(n % len(rainbow))]]) + char
n = n + 1
start = start + 1
print(rainbowified)
#with open('./test', 'w+') as file:
# file.write(rainbowified)
#timeEnd = time.time()
#print(timeEnd - timeStart)