nyan-cat 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/nyan-cat/cat.rb +19 -4
- data/lib/nyan-cat/version.rb +2 -2
- data/spec/cat_integration_spec.rb +15 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32aab5af498cba9827bde14365160515c1aa95b1
|
4
|
+
data.tar.gz: 8b4dfde39831835c96e92463c643c317124bc2a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ccd2ed8c329144a265ce390c831bab0932a319142bb3536d3a58d806d21ac47ace7fe7928c208770b72fc13a663038d13f3d0052b26758f46d6b8a73376ddf6
|
7
|
+
data.tar.gz: 447560bf0c0cf19c0aaea9ec508e9dff3581e3c129bd5eeffdf4644039845c3632f8d818b0fcb4d2704834863ec4543ab061d98c7cf0176d11a8ca4f0d60fcce
|
data/lib/nyan-cat/cat.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'paint'
|
2
|
+
|
1
3
|
module NyanCat
|
2
4
|
FRAME1 = <<'END'
|
3
5
|
_,------,
|
@@ -15,9 +17,10 @@ END
|
|
15
17
|
|
16
18
|
class Cat
|
17
19
|
def initialize(opts = {})
|
18
|
-
@frames
|
19
|
-
@trail_length
|
20
|
-
@
|
20
|
+
@frames = opts.fetch(:frames) { [FRAME1, FRAME2] }
|
21
|
+
@trail_length = opts.fetch(:trail_length) { 9 }
|
22
|
+
@colorize_trail = opts.fetch(:colorize) { true }
|
23
|
+
@frame_count = 0
|
21
24
|
end
|
22
25
|
|
23
26
|
def tick(frame_count = nil)
|
@@ -42,13 +45,25 @@ END
|
|
42
45
|
lines = frame.split(/\r?\n/)
|
43
46
|
frame_with_trails = lines.map.with_index do |line, i|
|
44
47
|
@trail_length.times do |j|
|
45
|
-
|
48
|
+
color_index = j - @frame_count % @trail_length
|
49
|
+
if @colorize_trail
|
50
|
+
line.prepend(Paint[trail_char(index, i, j), rainbow(color_index)])
|
51
|
+
else
|
52
|
+
line.prepend(trail_char(index, i, j))
|
53
|
+
end
|
46
54
|
end
|
47
55
|
line
|
48
56
|
end
|
49
57
|
frame_with_trails.join("\n")
|
50
58
|
end
|
51
59
|
|
60
|
+
def rainbow(freq = 0.3, i)
|
61
|
+
red = Math.sin(freq*i + 0) * 127 + 128
|
62
|
+
green = Math.sin(freq*i + 2*Math::PI/3) * 127 + 128
|
63
|
+
blue = Math.sin(freq*i + 4*Math::PI/3) * 127 + 128
|
64
|
+
"#%02X%02X%02X" % [ red, green, blue ]
|
65
|
+
end
|
66
|
+
|
52
67
|
def trail_char(frame_index, line_index, trail_index)
|
53
68
|
((frame_index + line_index + trail_index) % 2).zero? ? '-' : '_'
|
54
69
|
end
|
data/lib/nyan-cat/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module NyanCat
|
2
|
-
VERSION = "0.0.
|
3
|
-
end
|
2
|
+
VERSION = "0.0.3"
|
3
|
+
end
|
@@ -3,11 +3,11 @@ require 'minitest/spec'
|
|
3
3
|
|
4
4
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
5
5
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
6
|
-
require '
|
6
|
+
require 'nyan-cat'
|
7
7
|
|
8
8
|
describe NyanCat do
|
9
9
|
before do
|
10
|
-
@cat = NyanCat.new_cat
|
10
|
+
@cat = NyanCat.new_cat(:colorize => false)
|
11
11
|
@cat_frame_1 = (<<'END').strip
|
12
12
|
-_-_-_-_-_,------,
|
13
13
|
_-_-_-_-_-| /\_/\
|
@@ -38,5 +38,18 @@ END
|
|
38
38
|
result = @cat.tick(1).strip
|
39
39
|
result.must_equal @cat_frame_2
|
40
40
|
end
|
41
|
+
|
42
|
+
describe "when colorizing the trail" do
|
43
|
+
|
44
|
+
# this is just a punt since matching the whole string with the colors
|
45
|
+
# is a bit of pain. So instead we just use a simple regex to match
|
46
|
+
# against a specific color. We're not really validating that the colors
|
47
|
+
# are correct or anything. Just that they are populated.
|
48
|
+
it "should add colors to the trail" do
|
49
|
+
cat = NyanCat.new_cat(:colorize => true)
|
50
|
+
result = cat.tick.strip
|
51
|
+
result.must_match(/154m-/)
|
52
|
+
end
|
53
|
+
end
|
41
54
|
end
|
42
55
|
end
|