Skip to content

Instantly share code, notes, and snippets.

@dreamingblackcat
Last active March 8, 2018 09:15
Show Gist options
  • Save dreamingblackcat/5ccfb7d853a967a67ca4 to your computer and use it in GitHub Desktop.
Save dreamingblackcat/5ccfb7d853a967a67ca4 to your computer and use it in GitHub Desktop.
A simple ruby script for displaying fancy terminal screen
#!/usr/local/bin/ruby
# matrix test with ruby
# Used Two Gems 'curses' for terminal cursor moving and 'rainbow' for coloring
# first run "gem install curses rainbow"
# then run this file
# Note: you can tweak parameters when initializing the object
# Enjoy :)
require "curses"
require 'rainbow/ext/string'
include Curses
class MatrixTerminal
def initialize(options)
params = {
data: ("a".."z").to_a ,
colors: %w(white green blue yellow cyan magenta),
timer: 0.005,
rows: 20,
columns: 80,
space_index: 30
}
@params = params.merge!(options)
puts @params
end
def run
#added a number of spaces for clarity in printing
@params[:space_index].times { @params[:data].push(" ") }
while(true) do
rd_color = @params[:colors].sample
char = @params[:data].sample
rdx = rand(1..@params[:rows])
rdy = rand(1..@params[:columns])
setpos(rdx,rdy)
printf("\b")
printf(char.color(rd_color.to_sym).send([:bright,:to_s].sample).to_s)
sleep @params[:timer]
refresh
end
end
end
#Prepare Screen and Hide Cursor
noecho
init_screen
curs_set(0)
##ossible colors for Rainbow gem
# black
# red
# green
# yellow
# blue
# magenta
# cyan
# white
chars = %w(က ခ ဂ ဃ င စ ဆ ဇ စ် ည ဋ ဌ ဍ ဎ ဏ တ ထ ဒ ဓ န ပ ဖ ဗ ဘ မ ယ ရ လ ဝ သ ဟ ႒ အ ေ ၁ ၂ ၃ ၄ ၅ ၆ ၇ ၈ ၉ ၀ က ခ ဂ ဃ င စ ဆ ဇ စ် ည ဋ ဌ ဍ ဎ ဏ တ ထ ဒ ဓ န ပ ဖ ဗ ဘ မ ယ ရ လ ဝ သ ဟ ႒ အ ေ ၁ ၂ ၃ ၄ ၅ ၆ ၇ ၈ ၉ )
my_colors = %w(green blue cyan magenta white red)
terminal = MatrixTerminal.new({
data: chars,# array of characters you want to apply
colors: my_colors, # array of colors you want to apply
timer: 0.0004, # sleep timer between each cursor movement, the smaller the faster (in sec value)
space_index: 300, #the higher the index the more spaces included
rows: lines, # Curses.cols provided by 'curses' gem ,same as `tput lines`
columns: cols # Curses.cols provided by 'curses' gem ,same as `tput cols`
})
terminal.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment