Class: Unmagic::Color::Console::Banner
- Inherits:
-
Object
- Object
- Unmagic::Color::Console::Banner
- Defined in:
- lib/unmagic/color/console/banner.rb
Overview
Renders the colorized ASCII art banner for the console.
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
-
#render ⇒ String
Render the banner with gradient coloring.
-
#to_s ⇒ String
The rendered banner.
Instance Method Details
#render ⇒ String
Render the banner with gradient coloring.
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_s ⇒ String
Returns The rendered banner.
49 50 51 |
# File 'lib/unmagic/color/console/banner.rb', line 49 def to_s render end |