Sha256: aea97f915a6db596b55d76f29ecf40fe9b809a1b79540453b02f429688b3a572
Contents?: true
Size: 1.21 KB
Versions: 3
Compression:
Stored size: 1.21 KB
Contents
require 'pastel' require 'tty-cursor' require 'tty-screen' require_relative '../lib/tty-font' @pastel = Pastel.new @cursor = TTY::Cursor @font = TTY::Font.new(:starwars) @reg_font = TTY::Font.new(:straight) def lines_at(lines, x, y) lines.each_with_index.reduce([]) do |acc, (line, i)| acc << @cursor.move_to(x - line.size/2, y - lines.size/2 + i) + line acc end end def paint_logo @size = TTY::Screen.size print @cursor.save print @cursor.clear_screen print @cursor.hide # ["2606".to_i(16)].pack("U*") stars = ['.', '*'] (@size[1] + @size[0]).times do |i| print @cursor.move_to(rand(@size[1]), rand(@size[0])) + stars[rand(2)] end center_x = @size[1]/2 center_y = @size[0]/2 lines = @font.write('STAR').split("\n") print @pastel.red(lines_at(lines, center_x, center_y - 5).join) lines = @reg_font.write("THE LAST JEDI", letter_spacing: 1).split("\n") print lines_at(lines, center_x, center_y).join lines = @font.write('WARS').split("\n") print @pastel.red(lines_at(lines, center_x, center_y + 4).join) end begin Signal.trap('SIGWINCH') { paint_logo } paint_logo $stdin.getc ensure print @cursor.show print @cursor.clear_screen print @cursor.restore end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
tty-font-0.4.0 | examples/star_wars_logo.rb |
tty-font-0.3.0 | examples/star_wars_logo.rb |
tty-font-0.2.0 | examples/star_wars_logo.rb |