Class: Unmagic::Color::Console::Banner

Inherits:
Object
  • Object
show all
Defined in:
lib/unmagic/color/console/banner.rb

Overview

Renders the colorized ASCII art banner for the console.

Examples:

puts Unmagic::Color::Console::Banner.new.render

Constant Summary collapse

LINES =

ASCII art lines for the banner

[
  "                                                              ▄▄",
  "                                  ▀▀                          ██",
  " ██ ██ ████▄ ███▄███▄  ▀▀█▄ ▄████ ██  ▄████       ▄████ ▄███▄ ██ ▄███▄ ████▄",
  " ██ ██ ██ ██ ██ ██ ██ ▄█▀██ ██ ██ ██  ██    ▀▀▀▀▀ ██    ██ ██ ██ ██ ██ ██ ▀▀",
  " ▀██▀█ ██ ██ ██ ██ ██ ▀█▄██ ▀████ ██▄ ▀████       ▀████ ▀███▀ ██ ▀███▀ ██",
  "                               ██",
  "                             ▀▀▀",
].freeze
COLORS =

Gradient colors for the banner (magenta -> cyan -> green -> yellow -> red)

["#ff00ff", "#00ffff", "#00ff00", "#ffff00", "#ff0000"].freeze

Instance Method Summary collapse

Instance Method Details

#renderString

Render the banner with gradient coloring.

Returns:

  • (String)

    The colorized banner



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/unmagic/color/console/banner.rb', line 28

def render
  gradient = Gradient.linear(COLORS, direction: "left to right")

  height = LINES.length
  width = LINES.map(&:length).max

  bitmap = gradient.rasterize(width: width, height: height)

  LINES.each_with_index.map do |line, y|
    line.chars.each_with_index.map do |char, x|
      if char.strip.empty?
        char
      else
        color = bitmap.pixels[y][x]
        "\e[#{color.to_ansi}m#{char}\e[0m"
      end
    end.join
  end.join("\n")
end

#to_sString

Returns The rendered banner.

Returns:

  • (String)

    The rendered banner



49
50
51
# File 'lib/unmagic/color/console/banner.rb', line 49

def to_s
  render
end