nyan-cat 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3454be47a1c20632a06a1aa0bf629475cc5e92f0
4
- data.tar.gz: ce93ec93e9399ed34f9caf3c9538780b860c4501
3
+ metadata.gz: 32aab5af498cba9827bde14365160515c1aa95b1
4
+ data.tar.gz: 8b4dfde39831835c96e92463c643c317124bc2a5
5
5
  SHA512:
6
- metadata.gz: c7560d926414ed22073a285b49179789b23cea56ec8353359a79e024865dee92f77cc9abde7a3d1a89d49c370eddef029ada7cdf233c3357b064b59df13c56ab
7
- data.tar.gz: 1d248ebcda3ebe848bed8013966b88736568e89a68557b1b493f85bce2fc7211dfef3f6b7aa3ff69390d0d657252979c2aecd49719f3abffe6f775534928dd14
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 = opts.fetch(:frames) { [FRAME1, FRAME2] }
19
- @trail_length = opts.fetch(:trail_length) { 9 }
20
- @frame_count = 0
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
- line.prepend(trail_char(index, i, j))
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
@@ -1,3 +1,3 @@
1
1
  module NyanCat
2
- VERSION = "0.0.2"
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 'nyan_cat'
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nyan-cat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Keathley