let_it_fall 0.0.5 → 0.1.0

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: 9e733c0fb50b19af4d4ff0b6a79fe773c98ec2b6
4
- data.tar.gz: ce2471ce46af7fa66a99b1ea2e1407c3cdbebd93
3
+ metadata.gz: a4f963c78fba302d24ef508e16cc7cf582f879ef
4
+ data.tar.gz: 747799f998285ac6ce9217f0c91000839e361459
5
5
  SHA512:
6
- metadata.gz: 32af8adadce123eee8a18d0d7edc693f18c332d97bceb3a61658cbef75248a75f6ef71a1ddb1d790e458545b4d6ad7258ace6317a77b6e30a182a0d3e5b303a4
7
- data.tar.gz: be0f5d44fadfacaabb315e724e695af932e5b16db7e92fedb0a15200b584dbffd1ab7aa6a94da800d30f34d848981333e67c35729cc8def0d9ed13c96c68f289
6
+ metadata.gz: e2c6d763a21adaec119190811f80a86090f5f0927e897a65893a2999889ae7affecf73e4b5a67710be08a04baf95240583fc392dded0c3f0aed087b9242eef69
7
+ data.tar.gz: a5e1792a63bbbaaf994ae314ee725d0fc2edfc8d81c3c15dde24ce7283a60d202caf30266a4a69e725173558b6f711bbe28f118c7cc3982696f232e621321283
@@ -6,11 +6,10 @@ module LetItFall
6
6
  LetItFall::CODESET.keys.each do |command|
7
7
  desc "#{command}", "Let #{command} fall"
8
8
  option :speed, aliases:'-s', default:1, type: :numeric
9
- if [:snow, :kanji].include?(command)
10
- option :color, aliases:'-c', default:true, type: :boolean
11
- end
9
+ option :color, aliases:'-c', default:nil, type: :numeric
10
+ option :matrix, aliases:'-m', default:false, type: :boolean
12
11
  define_method(command) do
13
- run(command, options[:speed], options[:color])
12
+ run(command, options[:speed], options[:color], options[:matrix])
14
13
  end
15
14
  end
16
15
 
@@ -18,21 +17,28 @@ module LetItFall
18
17
  option :speed, aliases:'-s', default:1, type: :numeric
19
18
  def rand
20
19
  code = LetItFall::CODESET.keys.sample
21
- run(code, options[:speed], options[:color])
22
-
20
+ run(code, options[:speed], options[:color], false)
21
+ end
22
+
23
+ desc "matrix [MARK]", "Let it matrix"
24
+ option :speed, aliases:'-s', default:1, type: :numeric
25
+ option :color, aliases:'-c', default:32, type: :numeric
26
+ def matrix(mark=:latin)
27
+ run(mark, options[:speed], options[:color], true)
23
28
  end
24
29
 
25
30
  desc "code [CODE]", "Let specific character fall"
26
31
  option :speed, aliases:'-s', default:1, type: :numeric
27
- option :color, aliases:'-c', default:true, type: :boolean
32
+ option :color, aliases:'-c', default:nil, type: :numeric
28
33
  option :range, aliases:'-r', default:false, type: :boolean
34
+ option :matrix, aliases:'-m', default:false, type: :boolean
29
35
  def code(*code)
30
36
  if options[:range]
31
37
  st, ed = code.minmax
32
38
  code = Range.new(st.to_i(16), ed.to_i(16))
33
39
  .to_a.map { |i| i.to_s(16) }
34
40
  end
35
- run(code, options[:speed], options[:color])
41
+ run(code, options[:speed], options[:color], options[:matrix])
36
42
  end
37
43
 
38
44
  desc "version", "Show LetItFall version"
@@ -42,10 +48,10 @@ module LetItFall
42
48
  map "-v" => :version
43
49
 
44
50
  no_tasks do
45
- def run(name, speed, color)
51
+ def run(name, speed, color, matrix)
46
52
  speed = 0.1 if speed < 0.1
47
53
  interval = 0.05 / speed
48
- Render.run(name, IO.console.winsize, interval:interval, colorize:color)
54
+ Render.run(name, IO.console.winsize, interval:interval, color:color, matrix:matrix)
49
55
  end
50
56
  end
51
57
  end
@@ -1,23 +1,23 @@
1
1
  module LetItFall
2
2
  CODESET = {
3
- face: [*0x1F600..0x1F64F] - [*0x1F641..0x1F644],
4
- kanji: (0x4E00..0x4F00),
5
- snow: 0x2736,
6
- time: (0x1F550..0x1f567),
7
- animal: (0x1F40C..0x1F43C),
3
+ face: [*0x1F600..0x1F64F] - [*0x1F641..0x1F644],
4
+ kanji: (0x4E00..0x4F00),
5
+ snow: 0x2736,
6
+ time: (0x1F550..0x1f567),
7
+ animal: (0x1F40C..0x1F43C),
8
8
  oreilly: (0x1F40C..0x1F43C),
9
- food: (0x1F344..0x1F373),
10
- love: (0x1F493..0x1F49F),
11
- moon: (0x1F311..0x1F315),
12
- gem: 0x1F48E,
13
- python: 0x1F40D,
9
+ food: (0x1F344..0x1F373),
10
+ love: (0x1F493..0x1F49F),
11
+ moon: (0x1F311..0x1F315),
12
+ gem: 0x1F48E,
13
+ python: 0x1F40D,
14
14
  perl: 0x1F42A,
15
- wine: 0x1F377,
15
+ wine: 0x1F377,
16
16
  cocktail: 0x1F378,
17
17
  juice: 0x1F379,
18
- beer: 0x1F37A,
19
- beers: 0x1F37B,
20
- cake: 0x1F382,
18
+ beer: 0x1F37A,
19
+ beers: 0x1F37B,
20
+ cake: 0x1F382,
21
21
  sparkle: 0x2728,
22
22
  cyclone: 0x1F300,
23
23
  octopus: 0x1F419,
@@ -47,6 +47,8 @@ module LetItFall
47
47
  angel: 0x1F47C,
48
48
  alien: 0x1F47D,
49
49
  kiss: 0x1F48B,
50
+ alphabet: [*0x0041..0x005A, *0x0061..0x007A],
51
+ latin: [*0x0021..0x007E, *0x00A1..0x00FF, *0x0100..0x017F, *0x0250..0x02AF],
50
52
 
51
53
  }
52
54
  end
@@ -1,3 +1,3 @@
1
1
  module LetItFall
2
- VERSION = "0.0.5"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/let_it_fall.rb CHANGED
@@ -4,25 +4,33 @@ require "let_it_fall/version"
4
4
 
5
5
  module LetItFall
6
6
  class Render
7
- def self.run(mark, screen, colorize:false, interval:0.1)
8
- new(mark, screen, colorize:colorize, interval:interval).run
7
+ def self.run(mark, screen, color:nil, interval:0.1, matrix:false)
8
+ new(mark, screen, color:color, interval:interval, matrix:matrix).run
9
9
  end
10
10
 
11
- def initialize(mark, screen, colorize:false, interval:0.1)
11
+ def initialize(mark, screen, color:nil, interval:0.1, matrix:false)
12
12
  @y, @x = screen
13
- @colorize = colorize
14
- marks =
15
- if Array===mark
16
- mark.map { |m| m.to_i(16) }
17
- else
18
- CODESET[mark.intern] || CODESET[:snow]
19
- end
20
- @marks = Array(marks).map { |code| code.chr("UTF-8") }.cycle
13
+ if [nil, *31..37].include?(color)
14
+ @color = color
15
+ else
16
+ raise ArgumentError, "color should be 31-37 or nil"
17
+ end
18
+ @marks = build_marks(mark)
21
19
  @interval = interval
22
20
  @screen = {}
21
+ @matrix = matrix
23
22
  $stdout.sync = true
24
23
  end
25
24
 
25
+ def build_marks(mark)
26
+ marks =
27
+ case mark
28
+ when Array then mark.map { |m| m.to_i(16) }
29
+ else CODESET[mark.intern] || CODESET[:snow]
30
+ end
31
+ Array(marks).map { |code| code.chr("UTF-8") }.cycle
32
+ end
33
+
26
34
  def run
27
35
  clear_screen
28
36
  loop do
@@ -30,7 +38,7 @@ module LetItFall
30
38
  print "\e[?25h\e[0;0H" # show cursor and set 0,0 pos
31
39
  exit(0)
32
40
  end
33
- print_marks
41
+ print_marks(rand(@x), 0, @marks)
34
42
  sleep @interval
35
43
  end
36
44
  end
@@ -40,21 +48,23 @@ module LetItFall
40
48
  print "\e[?25l\e[2J"
41
49
  end
42
50
 
43
- def print_marks
44
- @screen[rand @x] = [0, @marks.dup]
45
- @screen.each do |x, (y,mark)|
46
- @screen[x][0] += 1 if @screen[x][0] <= @y*0.9
47
- clear_prev_mark(x, y)
48
- color = @colorize ? [*31..37].sample : 37
49
- draw_mark(x, @screen[x][0], mark.next, color)
51
+ def print_marks(pos_x, pos_y, marks)
52
+ @screen[pos_x] = pos_y
53
+ @screen.each do |x, y|
54
+ if @screen[x] <= @y*0.95
55
+ @screen[x] += 1
56
+ clear_prev_mark(x, y) unless @matrix && [true, true, false][rand 3]
57
+ color = @color || [*31..37].sample
58
+ draw_mark(x, @screen[x], marks.next, color)
59
+ end
50
60
  end
51
61
  end
52
62
 
53
63
  def clear_prev_mark(x, y)
54
- draw_mark(x, y, " ")
64
+ draw_mark(x, y, " ", 37)
55
65
  end
56
66
 
57
- def draw_mark(x, y, mark, color=37)
67
+ def draw_mark(x, y, mark, color)
58
68
  print "\e[%dm \e[%d;%dH%s \e[0;0H \e[0m" % [color, y, x, mark]
59
69
  end
60
70
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: let_it_fall
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kyoendo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-04 00:00:00.000000000 Z
11
+ date: 2014-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor