![]() |
|
[Ruby] Loading animation plugin - Printable Version +- Sinisterly (https://sinister.li) +-- Forum: Coding (https://sinister.li/Forum-Coding) +--- Forum: Coding (https://sinister.li/Forum-Coding--71) +--- Thread: [Ruby] Loading animation plugin (/Thread-Ruby-Loading-animation-plugin) |
[Ruby] Loading animation plugin - Inori - 05-15-2015 I had a supply in French so I decided to make a loading animations plugin for Ruby. Currently, it has 2 styles (0 and 1). You can add more by editing the if/elsif/else statement in the initialize method. To install, all you need to do is paste the code into a .rb file (I named it ani.rb) in your lib folder. To use it in a program, you just need to make the first line of your program require 'ani'. And yes, it is multi-platform! Usage: Code: <variable> = Ani.new(<style>) - creates a new animation with the specified style under the specified name
<variable>.play(<loops>) - plays the already created Ani the number of times specifiedCode: Code: class Ani
def initialize(style)
$frames = Array.new
if style == 0
$frames[0] = "o "
$frames[1] = " o "
$frames[2] = " o "
$frames[3] = " o "
$frames[4] = " o "
$frames[5] = " o"
$frames[6] = " o "
$frames[7] = " o "
$frames[8] = " o "
$frames[9] = " o "
$frames[10] = "o "
@@n_frames = 11
elsif style == 1
$frames[0] = "▓"
$frames[1] = "▒▓"
$frames[2] = "░▒▓"
$frames[3] = " ░▒▓"
$frames[4] = " ░▒"
$frames[5] = " ░"
$frames[6] = " ▓"
$frames[7] = " ▓▒"
$frames[8] = " ▓▒░"
$frames[9] = "▓▒░"
$frames[10] = "▒░"
$frames[11] = "░"
@@n_frames = 12
end
end
def play(loops)
loops.times do
i = 0
@@n_frames.times do
system "cls" or system "clear"
puts $frames[i]
i += 1
sleep(0.04)
end
end
end
end |