harlem_bits 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
File without changes
@@ -8,7 +8,7 @@ require 'harlem_bits/version'
8
8
  module HarlemBits
9
9
  DURATION = 30
10
10
  FRAME_RATE = 30.0
11
- AUDIO_FILE = 'resources/HarlemShake.mp3'
11
+ AUDIO_FILE = 'bin/HarlemShake.mp3'
12
12
 
13
13
  def self.shake(width, height)
14
14
  if OS.osx?
@@ -1,3 +1,3 @@
1
1
  module HarlemBits
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: harlem_bits
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-18 00:00:00.000000000 Z
12
+ date: 2013-02-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: colored
@@ -47,6 +47,7 @@ description: It's the Harlem Shake. In Ruby. In the terminal.
47
47
  email:
48
48
  - diego@greyrobot.com
49
49
  executables:
50
+ - HarlemShake.mp3
50
51
  - harlem_bits
51
52
  extensions: []
52
53
  extra_rdoc_files: []
@@ -56,16 +57,15 @@ files:
56
57
  - LICENSE.txt
57
58
  - README.md
58
59
  - Rakefile
60
+ - bin/HarlemShake.mp3
59
61
  - bin/harlem_bits
60
62
  - harlem_bits.gemspec
61
- - harlem_bits.rb
62
63
  - lib/harlem_bits.rb
63
64
  - lib/harlem_bits/arena.rb
64
65
  - lib/harlem_bits/bit.rb
65
66
  - lib/harlem_bits/cli_rendering.rb
66
67
  - lib/harlem_bits/harlem.rb
67
68
  - lib/harlem_bits/version.rb
68
- - resources/HarlemShake.mp3
69
69
  homepage: https://github.com/DiegoSalazar/BinaryHarlemShake
70
70
  licenses: []
71
71
  post_install_message:
@@ -1,144 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "os"
4
-
5
- class Bit
6
- def initialize(color, on = false)
7
- @color, @on = color, on
8
- end
9
-
10
- def switch
11
- @on = !@on
12
- end
13
-
14
- def off
15
- @on = false
16
- end
17
-
18
- def to_s
19
- @on ? '1'.send(@color) : '0'
20
- end
21
- alias_method :inspect, :to_s
22
- end
23
-
24
- module CliRendering
25
- require 'colored'
26
- COLORS = Colored.methods - [:extra, :colors, :colorize, :color] - Object.methods
27
-
28
- def draw
29
- puts with_enough_breaks_to_page_down
30
- end
31
-
32
- private
33
-
34
- def rand_color
35
- COLORS[rand(COLORS.size-1)]
36
- end
37
-
38
- def with_enough_breaks_to_page_down
39
- "#{"\n" * 50}#{with_space_below}"
40
- end
41
-
42
- def with_space_below
43
- "#{rows_with_newlines}#{"\n" * 5}"
44
- end
45
-
46
- def rows_with_newlines
47
- @arena.map { |row| with_leading_space row }.join("\n")
48
- end
49
-
50
- def with_leading_space(row)
51
- "#{' '*10}#{row.join(' ')}"
52
- end
53
- end
54
-
55
- class Arena
56
- include CliRendering
57
-
58
- def initialize(width, height)
59
- @width, @height, @arena = width.to_i, height.to_i, []
60
- @height.times do |h|
61
- @arena << (1..@width).map do |i|
62
- Bit.new rand_color
63
- end
64
- end
65
- end
66
-
67
- def center
68
- @arena[@height/2][@width/2]
69
- end
70
-
71
- def clear
72
- @arena.each { |row| row.each { |bit| bit.off } }
73
- end
74
-
75
- def random!
76
- random.map { |bit| bit.switch }
77
- end
78
-
79
- def random
80
- found = []
81
- @arena.each do |row|
82
- row.each do |bit|
83
- found << bit if rand(@width) < @width/3
84
- end
85
- end
86
- found
87
- end
88
- end
89
-
90
- class Harlem
91
- DURATION = 30
92
- FRAME_RATE = 30.0
93
- AUDIO_FILE = 'HarlemShake.mp3'
94
-
95
- def self.shake(width, height)
96
- if OS.osx?
97
- t = Thread.new { system "afplay #{AUDIO_FILE}" }
98
- elsif OS.linux?
99
- t = Thread.new { system "mpg123 #{AUDIO_FILE}" }
100
- else
101
- #Playing songs from windows command line? Can it be done? Has science gone too far?
102
- t = Thread.new { puts "Pretend that there's music, pal." }
103
- end
104
- s = new width || 50, height || 25
105
- s.start
106
- rescue Interrupt
107
- s.kill
108
- t.kill
109
- ensure
110
- puts 'fin'
111
- exit 0
112
- end
113
-
114
- def initialize(width, height)
115
- @arena = Arena.new width, height
116
- @alive = true
117
- end
118
-
119
- def kill
120
- @alive = false
121
- end
122
-
123
- def start
124
- start_t = Time.now.to_f
125
- last_t = Time.now.to_i
126
- frame = 0
127
- switched = false
128
-
129
- while @alive
130
- cur_t = Time.now.to_f
131
- delta = cur_t - start_t
132
-
133
- @arena.clear
134
- @arena.center.switch if delta % 2.0 == 0 || (delta % 2.0) / 2.0 > 0.3
135
- @arena.random! if delta >= (DURATION / 2) + 1
136
- @arena.draw
137
-
138
- break if delta > DURATION
139
- sleep 1/FRAME_RATE
140
- end
141
- end
142
- end
143
-
144
- Harlem.shake ARGV[0], ARGV[1] if $0 == __FILE__