Skip to content

Instantly share code, notes, and snippets.

Created August 15, 2012 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/3360969 to your computer and use it in GitHub Desktop.
Save anonymous/3360969 to your computer and use it in GitHub Desktop.
Convert text to rainbow BBCode
class RainbowText:
def colours(self):
return ['ff00ff','ff00cc','ff0099','ff0066','ff0033','ff0000','ff3300','ff6600','ff9900','ffcc00','ffff00','ccff00','99ff00','66ff00','33ff00','00ff00','00ff33','00ff66','00ff99','00ffcc','00ffff','00ccff','0099ff','0066ff','0033ff','0000ff','3300ff','6600ff','9900ff','cc00ff']
def dividor(self, text):
return float(len(self.colours())) / float(len(text))
def convert(self, text):
code = ""
for i in range(0, len(text)):
code += self.bbcode(text[i], self.colours()[int(self.dividor(text) * i)])
return code
def bbcode(self, text, colour):
return "[color='#" + colour + "']" + text + "[/color]" if text != " " else " "
rainbow_text = RainbowText()
print rainbow_text.convert("Hello my name is Alex/Artificial. I'm just testing the convert function.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment