module ThemeDoodleMatrix
ThemeDoodleMatrix — Matrix movie ASCII art with bullet-dodge panels (classic 16 colours). Public: CLASSIC_COLOURS, matrix_decorate, matrix_line, bullet_dodge_panels, matrix_header, matrix_between_separators, matrix_footer Depends: IrcFormat Tests: test/lib/theme_doodle_matrix_test.rb
Constants
- BASE_WIDTH
- CLASSIC_COLOURS
- MATRIX_CYCLE
Public Instance Methods
Source
# File lib/theme_doodle_matrix.rb, line 126 def binary_rain_line(width:, seed:) bits = %w[0 1] line = +"" width.times { |index| line << bits[(seed + index) % 2] } line end
Source
# File lib/theme_doodle_matrix.rb, line 36 def bullet_dodge_panels(seed:, width: BASE_WIDTH) panels = [ bullet_time_panel(width: width), matrix_rain_panel(width: width), dodge_left_panel(width: width), dodge_right_panel(width: width) ] panels[seed.to_i.abs % panels.length] end
Source
# File lib/theme_doodle_matrix.rb, line 83 def bullet_time_panel(width:) art = [ " o * o * ", " * \\ | / o * ", " * --- NEO --- o ", " / | \\ * o * ", " o * o * " ] fit_art(art, width: width) end
Source
# File lib/theme_doodle_matrix.rb, line 18 def colour_at(index) CLASSIC_COLOURS[index % CLASSIC_COLOURS.length] end
Source
# File lib/theme_doodle_matrix.rb, line 104 def dodge_left_panel(width:) art = [ " * o * o * o ", " o \\ | / * o ", " * o --- NEO --- * o * ", " / | \\ o * ", " o * o * o " ] fit_art(art, width: width) end
Source
# File lib/theme_doodle_matrix.rb, line 115 def dodge_right_panel(width:) art = [ " * o * o * o * o ", " o * \\ | / * o ", " * --- NEO DODGE --- o * ", " / | \\ * o * ", " o * o * o * o " ] fit_art(art, width: width) end
Source
# File lib/theme_doodle_matrix.rb, line 133 def fit_art(lines, width:) lines.map do |line| text = line.to_s if text.length >= width text[0, width] else text.center(width)[0, width] end end end
Source
# File lib/theme_doodle_matrix.rb, line 60 def matrix_between_separators(width: BASE_WIDTH, count: 3, seed: 0) lines = [] count.times do |index| panel_seed = seed + (index * 17) lines.concat(bullet_dodge_panels(seed: panel_seed, width: width)) char = %w[* o | 0 1][panel_seed % 5] lines << char * width inner = width - 2 lines << "|" + binary_rain_line(width: inner, seed: panel_seed + 3).center(inner) + "|" end lines end
Source
# File lib/theme_doodle_matrix.rb, line 22 def matrix_decorate(text, offset: 0) text.to_s.chars.map.with_index do |ch, index| next ch if ch == " " fg = colour_at(offset + index) "#{IrcFormat.color(fg)}#{ch}#{IrcFormat::RESET}" end.join end
Source
# File lib/theme_doodle_matrix.rb, line 46 def matrix_header(tag: "TAG", width: BASE_WIDTH, seed: 0) inner = width - 2 label = " #{tag} " rain_top = "|" + binary_rain_line(width: inner, seed: seed) + "|" rain_bot = "|" + binary_rain_line(width: inner, seed: seed + 11) + "|" [ "+" + "=" * inner + "+", rain_top, "|" + label.center(inner) + "|", rain_bot, "+" + "-" * inner + "+" ] + bullet_dodge_panels(seed: seed, width: width) end
Source
# File lib/theme_doodle_matrix.rb, line 31 def matrix_line(text, line_index: 0, seed: 0) offset = (seed.to_s.bytes.sum + (line_index * 7)) % CLASSIC_COLOURS.length matrix_decorate(text, offset: offset) end
Source
# File lib/theme_doodle_matrix.rb, line 94 def matrix_rain_panel(width:) art = [ "|010110101010110101011001010101010|", "|10101100101010101011010101011010|", "|<< THE MATRIX :: BULLET TIME >>|", "|01010110101011010101101010101101|" ] fit_art(art, width: width) end