Rainbowonify your Kiwifarms posts! - Rainbows!!!

I don't want to do it so you have to: Can you re-write it to use HSL instead of RGB?
I don't think Kiwifarms' BBCode allows for HSL format (I'm not sure), but I think it's only 6-digit hex, 3-digit-hex, or the official color name, like Crimson, AliceBlue, Chocolate, DarkSeaGreen, etc.

But if you want to make it for HTML span tags, then it's far easier than the RGB format, because all you need to do is cycle through 360 degrees/values for the input's length. And because it's a rainbow, saturation is always 100%, and lighting is always 50% (for a true rainbow at maximum power).

Then this would be the code, it's super simple but for HTML, not Kiwifarms' BBCode.
Python:
import re

start = "<span style=\"color:hsl("
between = ", 100%, 50%);\">"
end = "</span>"

user_input = input("Enter your word/message:\n")
user_input_length = len(user_input)
user_input_no_space = ""

for x in user_input:
  is_space = bool(re.search(r"[\s]", x))
  if is_space:
    continue
  user_input_no_space += x

user_input_no_space_length = len(user_input_no_space)

count = 0
user_input_index = 0

adjust = 360 / user_input_no_space_length
hue = 1
hue_track = hue

while count < user_input_length:

  space_char = bool(re.search(r"[\s]", user_input[user_input_index]))
  if space_char:
    print(" ", end="")
    user_input_index += 1
    count += 1
    continue

  print(f"{start}{hue}{between}{user_input[user_input_index]}{end}", end="")
  user_input_index += 1

  hue_track += adjust
  hue_add = round(hue_track)
  hue = hue_add

  count += 1
how do you make it pastel :)
Right now I'm not sure how to make a pastel rainbow in RGB so that it can be used in Kiwifarms, but if it's for HTML, while using the HSL format then it's pretty easy.

Pastel is generally less saturated and "whiter", so this means that in the code above, if you change the 100% (which is for saturation) to like 60%, and then the 50% (which is for lightness) to like 85%, it will give you a more pastel rainbow, like the first half in this image:

pastel.png

Again, this is very easy to do in HTML, for Kiwifarms' RGB format, some adjustments would need to be done to up every channel so that the result is whiter and less saturated.
 
how do you make it pastel :)
And this is why HSL rules.
Now that I think about it, instead of reinventing the wheel, there's already a basic module that can change HSL to RGB:

So that you can do things like these, this rainbow is somewhat pastel because its saturation is set at 60% and its lightness at 80%.


I think the code is properly written as I'm not very acquainted with this module, but it was capable to produce these strings in rainbow pastel.

It's
already set to use for Kiwifarms' BBCode, if you want to try more pastels, you can just change the "sat" and "light" values in lines 11-12. For pastel you probably want less than a 100 in saturation and more than 50 in lightness.
Python:
import re
import colorsys

#############[EDIT]############# which type of string you want----------------------------------------------(Edit as wanted)
# 1 >>> for HTML
# 2 >>> for Kiwifarms' BBCode
choice = 2

#############[EDIT]############# Enter saturation and lightness---------------------------------------------(Edit as wanted)
# a number between 0-100, for pastel you can use (sat = 60) and (light = 80)
sat = 60
light = 80

s = sat / 100
l = light / 100

if choice == 1:
  # HTML
  start = "<span style=\"color:#"
  between = ";\">"
  end = "</span>"
else:
  # Kiwifarms' BBCode
  start = "[color=#"
  between = "]"
  end = "[/color]"

user_input = input("Enter your word/message:\n")
user_input_length = len(user_input)
user_input_no_space = ""

for x in user_input:
  is_space = bool(re.search(r"[\s]", x))
  if is_space:
    continue
  user_input_no_space += x

user_input_no_space_length = len(user_input_no_space)

count = 0
user_input_index = 0

adjust = 360 / user_input_no_space_length
hue = 1
hue_track = hue

while count < user_input_length:

  space_char = bool(re.search(r"[\s]", user_input[user_input_index]))
  if space_char:
    print(" ", end="")
    user_input_index += 1
    count += 1
    continue

  c_hue = hue / 360.0
  r, g, b = colorsys.hls_to_rgb(c_hue, l, s)

  r = hex(int(r * 15))[2:]
  g = hex(int(g * 15))[2:]
  b = hex(int(b * 15))[2:]

  print(f"{start}{r}{g}{b}{between}{user_input[user_input_index]}{end}", end="")
  user_input_index += 1

  hue_track += adjust
  hue_add = round(hue_track)
  hue = hue_add

  count += 1
 
Now that I think about it, instead of reinventing the wheel, there's already a basic module that can change HSL to RGB:
That's very nice indeed just like HSL. I'm not going to ask for a LAB implementation, instead I'm going to require that it is changing pastel colors for every word that is five/six characters or less. Make words into crayons.
 
That's very nice indeed just like HSL. I'm not going to ask for a LAB implementation, instead I'm going to require that it is changing pastel colors for every word that is five/six characters or less. Make words into crayons.
That probably requires a bit more of complexity if you want to keep the rainbow for longer words, but making words into random crayons seems easy to do.

Like this, now there's no rainbow, it's just random Hue values for a hard-coded saturation/lighness values (to make it pastel), so kind of works.

Since I'm not very acquainted with these modules, the code is very simple, but at least is random. I think for now that's all I'll do, once I get more comfortable with this stuff, maybe I'll be able to write better and more efficient code.
Python:
import re
import colorsys
import random

#############[EDIT]############# which type of string you want----------------------------------------------(Edit as wanted)
# 1 >>> for HTML
# 2 >>> for Kiwifarms' BBCode
choice = 2

#############[EDIT]############# enter saturation and lightness---------------------------------------------(Edit as wanted)
# a number between 0-100, for pastel you can use (sat = 60) and (light = 80)
sat = 60
light = 80

s = sat / 100
l = light / 100

if choice == 1:
  # HTML
  start = "<span style=\"color:#"
  between = ";\">"
  end = "</span>"
else:
  # Kiwifarms' BBCode
  start = "[color=#"
  between = "]"
  end = "[/color]"

user_input = input("Enter your word/message:\n")

words = re.compile(r"(\s+)").split(user_input)

for w in words:
    h = random.randint(0, 100) / 100
    
    r, g, b = colorsys.hls_to_rgb(h, l, s)

    r = hex(int(r * 15))[2:]
    g = hex(int(g * 15))[2:]
    b = hex(int(b * 15))[2:]
    
    print(f"{start}{r}{g}{b}{between}{w}{end}", end="")
Random crayons!
Random crayons!
Random crayons!
 
Unlimited colors
Python:
import matplotlib
import numpy
user_input = "Lorem ipsum dolor sit amet, consectetur adipiscing elit"
bb_code = ""
terminal_code = ""
color_list = ['#5BCEFA', '#F5A9B8', '#FFFFFF', '#F5A9B8'] * 5
cmap = matplotlib.colors.LinearSegmentedColormap.from_list('cmap_name', color_list, len(user_input), 1.0)
color_segments = [cmap(i) for i in numpy.linspace(0, 1, len(user_input))]

for char, color in zip(user_input, color_segments):
    if str.isspace(char):
        bb_code += char
        terminal_code += char
    else:
        bb_hex = ''.join("{:1x}".format(int(v*15)) for v in color[:3])
        bb_code += f'[color=#{bb_hex}]{char}[/color]'

        terminal_hex = ';'.join(str(int(v*255)) for v in color[:3])
        terminal_code += f'\033[38;2;{terminal_hex}m{char}\033[0m'

print(bb_code)
print(terminal_code)
 
  • Horrifying
Reactions: Battlefield42
Back