Skip to content

Instantly share code, notes, and snippets.

@filiperocha
Created January 5, 2025 19:17
Show Gist options
  • Select an option

  • Save filiperocha/a584d6f72d5102b05ea786413c0c8e93 to your computer and use it in GitHub Desktop.

Select an option

Save filiperocha/a584d6f72d5102b05ea786413c0c8e93 to your computer and use it in GitHub Desktop.

Revisions

  1. filiperocha created this gist Jan 5, 2025.
    28 changes: 28 additions & 0 deletions the_matrix.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    clear_screen = -> { puts "\033[2J" }

    trap("SIGINT") do
    clear_screen.call

    puts "Morpheus: 'Follow me.'"
    exit!
    end

    total_width = `stty size`.scan(/\d+/)[1].to_i # terminal width

    chars = {}
    eligible_chars = ('a'..'z').to_a + ('1'..'9').to_a

    clear_screen.call

    loop do
    chars[rand(total_width)] = 0

    chars.each do |column, row|
    chars[column] += 1 # increment row value

    print "\033[#{row + 1};#{column}H" # move cursor down (row + 1)
    print "#{eligible_chars.sample} " # print random character
    print "\033[0;0H" # move cursor to top/left position
    end
    sleep 0.1
    end