Code Monkey home page Code Monkey logo

Comments (7)

MarchandMD avatar MarchandMD commented on June 14, 2024 1

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

from colorize.

GitHubUserCDC avatar GitHubUserCDC commented on June 14, 2024

oh please do it 👍

from colorize.

joshdaloewen avatar joshdaloewen commented on June 14, 2024

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('')

from colorize.

jknight1725 avatar jknight1725 commented on June 14, 2024
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

from colorize.

jefflunt avatar jefflunt commented on June 14, 2024

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!

from colorize.

jefflunt avatar jefflunt commented on June 14, 2024

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.

from colorize.

fazibear avatar fazibear commented on June 14, 2024

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

from colorize.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.