fazibear/colorize

Rainbow option (Feature Request)

elisaado opened this issue · 7 comments

I'd like an option to rainbow-ize strings

Thanks

oh please do it 👍

I think this would be a great option too. Until then, here are some ways to do it yourself.

Picking a random color for an entire string is relatively easy:

# First get all the possible colors
colors = String.colors
# Remove :default plus any other colors you don't want
colors -= [:default, :black]
# Send a random color to your string
puts "Random Color".send(colors.sample)

Producing a rainbow of different colors in the same string can be done this way:

# First get all the possible colors
colors = String.colors
# Remove :default plus any other colors you don't want
colors -= [:default, :black]
# Break the string into characters, colorize each, and put back together
puts "Rainbow String".split('').map{|char| char.send(colors.sample)}.join('')

I further encourage the more general support for traditional color hue spectrum: ROYGBIV

class String
  def rainbow
    rainbow_colors = %i[red light_red light_yellow green light_green light_blue blue light_magenta]
    r = rainbow_colors.each.cycle
    each_char.map { |c| c.send(r.next) }.join
  end
end

text = 'Colorize me!, color me like a rainbow!'.rainbow
puts text

That's a lot of extra hidden characters in text. Fun idea though!

IMO something like this goes a little bit beyond the intent of what this gem would do: making simple color enhancements and highlights.

I know it's been 2-3 years, but would you be at all interested in submitting a PR, even for a very minimal possible implementation for this? This library isn't all that big.

Alternatively I could see a rainbow as either (a) something you need to explicitly enable, or (b) as a separate gem, something like colorize-rainbow that would follow a similar mechanism as this library (i.e. extending the String class) to add this functionality.

Thoughts @elisaado ?

BTW: I'm not a library maintainer, and even if a PR were submitted for this, I can't say if @fazibear would be open to it, but at least with a proposed solution there's greater ground for possible feedback.

Thanks!

Also, if this is the only feature you're particularly interested in, consider the rainbow or lolize gems.

Here's a blog post that shows some visual differences in their features.

Looks like lolize gem it the best thing for rainbowing text :)