nyancat 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
data/bin/nyancat
CHANGED
@@ -32,16 +32,20 @@
|
|
32
32
|
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
33
33
|
# WITH THE SOFTWARE.
|
34
34
|
|
35
|
-
|
35
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
36
36
|
require 'nyancat'
|
37
|
+
require 'optparse'
|
37
38
|
|
38
|
-
|
39
|
+
options = {}
|
40
|
+
OptionParser.new do |opts|
|
41
|
+
opts.banner = "Usage: nyancat [options]"
|
39
42
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
end
|
43
|
+
opts.on("-s", "--silent", "Don't play audio") do |s|
|
44
|
+
options[:mute] = s
|
45
|
+
end
|
46
|
+
opts.on("-f", "--flavour FLAVOUR", "Available flavours: #{NyanCat.flavours.join(', ')}") do |f|
|
47
|
+
options[:flavour] = f
|
48
|
+
end
|
49
|
+
end.parse!
|
46
50
|
|
47
|
-
NyanCat.nyancat(
|
51
|
+
NyanCat.nyancat(options)
|
data/lib/nyancat.rb
CHANGED
@@ -30,30 +30,41 @@
|
|
30
30
|
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
31
31
|
# WITH THE SOFTWARE.
|
32
32
|
|
33
|
-
|
33
|
+
require 'yaml'
|
34
34
|
|
35
|
+
module NyanCat
|
35
36
|
OUTPUT_CHAR = " "
|
36
37
|
|
37
|
-
def self.
|
38
|
-
|
38
|
+
def self.flavours
|
39
|
+
return Dir.entries(File.expand_path("../nyancat/", __FILE__)).select { |entry| !(entry =='.' || entry == '..') }
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.nyancat(options = {})
|
43
|
+
flavour = options[:flavour] || 'original'
|
44
|
+
mute = options[:mute] || false
|
45
|
+
|
46
|
+
frames = YAML.load_file(File.expand_path("../nyancat/#{flavour}/frames.yml", __FILE__))
|
47
|
+
palette = YAML.load_file(File.expand_path("../nyancat/#{flavour}/palette.yml", __FILE__))
|
48
|
+
audio = File.expand_path("../nyancat/#{flavour}/audio.mp3", __FILE__)
|
49
|
+
|
39
50
|
# Get TTY size
|
40
51
|
term_width, term_height = `stty size`.split.map { |x| x.to_i }.reverse
|
41
52
|
|
42
53
|
# Calculate the width in terms of the output char
|
43
54
|
term_width = term_width / OUTPUT_CHAR.length
|
44
|
-
|
55
|
+
|
45
56
|
min_row = 0
|
46
57
|
max_row = frames[0].length
|
47
|
-
|
58
|
+
|
48
59
|
min_col = 0
|
49
60
|
max_col = frames[0][0].length
|
50
|
-
|
61
|
+
|
51
62
|
min_row = (max_row - term_height) / 2 if max_row > term_height
|
52
63
|
max_row = min_row + term_height if max_row > term_height
|
53
|
-
|
64
|
+
|
54
65
|
min_col = (max_col - term_width) / 2 if max_col > term_width
|
55
66
|
max_col = min_col + term_width if max_col > term_width
|
56
|
-
|
67
|
+
|
57
68
|
frames = frames.map do |frame|
|
58
69
|
frame[min_row...max_row].map do |line|
|
59
70
|
line.chars.to_a[min_col...max_col].map do |c|
|
@@ -62,6 +73,8 @@ module NyanCat
|
|
62
73
|
end.join + "\033[H"
|
63
74
|
end
|
64
75
|
|
76
|
+
audio_thread = Thread.new { IO.popen("mpg123 -loop 0 -q #{audio} > /dev/null 2>&1") } unless mute
|
77
|
+
|
65
78
|
start_time = Time.now
|
66
79
|
printf("\033[H\033[2J\033[?25l")
|
67
80
|
begin
|
@@ -80,4 +93,4 @@ module NyanCat
|
|
80
93
|
raise e
|
81
94
|
end
|
82
95
|
end
|
83
|
-
end
|
96
|
+
end
|
Binary file
|
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,70 +1,50 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: nyancat
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 3
|
10
|
-
version: 0.0.3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.0
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Ben Arblaster
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
date: 2011-12-06 00:00:00 +00:00
|
19
|
-
default_executable:
|
12
|
+
date: 2013-01-01 00:00:00.000000000 Z
|
20
13
|
dependencies: []
|
21
|
-
|
22
14
|
description: A Ruby port of Kevin Lange's nyancat
|
23
15
|
email: ben@andatche.com
|
24
|
-
executables:
|
16
|
+
executables:
|
25
17
|
- nyancat
|
26
18
|
extensions: []
|
27
|
-
|
28
19
|
extra_rdoc_files: []
|
29
|
-
|
30
|
-
files:
|
20
|
+
files:
|
31
21
|
- lib/nyancat.rb
|
32
|
-
- lib/nyancat/
|
33
|
-
- lib/nyancat/
|
22
|
+
- lib/nyancat/original/audio.mp3
|
23
|
+
- lib/nyancat/original/frames.yml
|
24
|
+
- lib/nyancat/original/palette.yml
|
34
25
|
- bin/nyancat
|
35
|
-
has_rdoc: true
|
36
26
|
homepage: https://github.com/andatche/ruby_nyancat/
|
37
27
|
licenses: []
|
38
|
-
|
39
28
|
post_install_message:
|
40
29
|
rdoc_options: []
|
41
|
-
|
42
|
-
require_paths:
|
30
|
+
require_paths:
|
43
31
|
- lib
|
44
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ! '>='
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
45
37
|
none: false
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
- 0
|
52
|
-
version: "0"
|
53
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ! '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
54
43
|
none: false
|
55
|
-
requirements:
|
56
|
-
- - ">="
|
57
|
-
- !ruby/object:Gem::Version
|
58
|
-
hash: 3
|
59
|
-
segments:
|
60
|
-
- 0
|
61
|
-
version: "0"
|
62
44
|
requirements: []
|
63
|
-
|
64
45
|
rubyforge_project:
|
65
|
-
rubygems_version: 1.
|
46
|
+
rubygems_version: 1.8.23
|
66
47
|
signing_key:
|
67
48
|
specification_version: 3
|
68
49
|
summary: nyancat on your terminal
|
69
50
|
test_files: []
|
70
|
-
|