cellular_automata 0.1.4 → 0.1.5
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/.gitignore +1 -0
- data/README.md +17 -5
- data/bin/cell +16 -11
- data/bin/cell_console +43 -12
- data/lib/cellular_automata.rb +0 -1
- data/lib/cellular_automata/version.rb +1 -1
- metadata +2 -7
- data/bin/cell_gif +0 -52
- data/bin/cell_gui +0 -53
- data/lib/cellular_automata/gif_writer.rb +0 -56
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc753c35c9c45bb5df74f2678d37c0d2ba9af371
|
4
|
+
data.tar.gz: ff0800f910754856743abc46f147f4bb0ae19225
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30f23c199406a34c53c29a0887d0317cfb1cf78d4ba3deb1b69c949b6e446e6f8f847a077fae2e4459730fd9179b496a35f891b8a9a8f0cfeeea55377adb4e26
|
7
|
+
data.tar.gz: 3f27c51e0a612acd9921e20cf87e738d199ad5b2dc5767c1904adf29fdfe729e4f8bcfe6ea55386a2be6c6e90f0d675ef798cd2adb6736e002c9e4cb48f3560f
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -21,7 +21,23 @@ Or install it yourself as:
|
|
21
21
|
|
22
22
|
## Usage
|
23
23
|
|
24
|
-
|
24
|
+
```
|
25
|
+
cell [options] RULE
|
26
|
+
-w, --width WIDTH Set width
|
27
|
+
-h, --height HEIGHT Set height
|
28
|
+
-s, --scale SCALE Factor by which to scale game board
|
29
|
+
-c, --cell-width WIDTH Factor by which to scale cells
|
30
|
+
Use 1 for an 'LED' look
|
31
|
+
Use 2 for no borders around cells
|
32
|
+
or choose anything in between
|
33
|
+
-f, --full-screen Full screen
|
34
|
+
-v, --version Print version information
|
35
|
+
--help Display this screen
|
36
|
+
```
|
37
|
+
|
38
|
+
RULE is a [standard Life Rule](http://www.conwaylife.com/wiki/Cellular_automaton) in the format `S.../B...` The `/` is optional, and it doesn't matter which comes first.
|
39
|
+
|
40
|
+
`cell_console` (a console version with simple ASCII output) also exists, but isn't near as interesting!
|
25
41
|
|
26
42
|
## Development
|
27
43
|
|
@@ -30,10 +46,6 @@ Install gosu dependencies:
|
|
30
46
|
% brew install sdl2 libogg libvorbis
|
31
47
|
```
|
32
48
|
|
33
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
34
|
-
|
35
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
36
|
-
|
37
49
|
## Contributing
|
38
50
|
|
39
51
|
1. Fork it ( https://github.com/ffleming/cellular_automata/fork )
|
data/bin/cell
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'cellular_automata'
|
4
4
|
require 'optparse'
|
5
|
+
require 'gosu'
|
5
6
|
|
6
7
|
def opts_from_cli
|
7
8
|
options = {}
|
@@ -10,7 +11,10 @@ def opts_from_cli
|
|
10
11
|
opts.banner = "#{opts.program_name} [options] RULE"
|
11
12
|
opts.on('-w WIDTH', '--width WIDTH', 'Set width') { |w| options[:width] = w.to_i }
|
12
13
|
opts.on('-h HEIGHT', '--height HEIGHT', 'Set height') { |h| options[:height] = h.to_i }
|
13
|
-
opts.on('-
|
14
|
+
opts.on('-s SCALE', '--scale SCALE', 'Factor by which to scale game board') { |s| options[:scale] = s.to_i }
|
15
|
+
opts.on('-c WIDTH', '--cell-width WIDTH', 'Factor by which to scale cells', 'Use 1 for an \'LED\' look',
|
16
|
+
'Use 2 for no borders around cells', 'or choose anything in between') {|w| options[:cell_scale] = w.to_f }
|
17
|
+
opts.on('-f', '--full-screen', 'Full screen') { options[:fullscreen] = true }
|
14
18
|
opts.on('-v', '--version', 'Print version information') do
|
15
19
|
puts "#{File.basename(__FILE__)} #{CellularAutomata::VERSION}"
|
16
20
|
exit true
|
@@ -30,19 +34,20 @@ def opts_from_cli
|
|
30
34
|
end
|
31
35
|
|
32
36
|
opts = opts_from_cli
|
33
|
-
opts[:width] ||=
|
34
|
-
opts[:height] ||=
|
35
|
-
opts[:
|
37
|
+
opts[:width] ||= 160
|
38
|
+
opts[:height] ||= 120
|
39
|
+
opts[:scale] ||= 2
|
40
|
+
opts[:cell_scale] ||= 2.0
|
41
|
+
opts[:cell_scale] = 2.0 if opts[:cell_scale] > 2.0
|
42
|
+
opts[:cell_scale] = 1.0 if opts[:cell_scale] < 1.0
|
43
|
+
opts[:fullscreen] ||= false
|
36
44
|
rule = ARGV[0] || 'B3S2'
|
37
|
-
|
45
|
+
opts[:rule] = rule
|
38
46
|
|
39
47
|
trap 'SIGINT' do
|
40
48
|
exit
|
41
49
|
end
|
42
50
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
puts board.to_s
|
47
|
-
sleep opts[:refresh]
|
48
|
-
end
|
51
|
+
window = CellWindow.new(opts)
|
52
|
+
window.show
|
53
|
+
exit
|
data/bin/cell_console
CHANGED
@@ -2,16 +2,47 @@
|
|
2
2
|
|
3
3
|
require 'cellular_automata'
|
4
4
|
require 'optparse'
|
5
|
-
require 'byebug'
|
6
|
-
require 'pry'
|
7
5
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
6
|
+
def opts_from_cli
|
7
|
+
options = {}
|
8
|
+
opt_parser = OptionParser.new do |opts|
|
9
|
+
opts.program_name = File.basename(__FILE__)
|
10
|
+
opts.banner = "#{opts.program_name} [options] RULE"
|
11
|
+
opts.on('-w WIDTH', '--width WIDTH', 'Set width') { |w| options[:width] = w.to_i }
|
12
|
+
opts.on('-h HEIGHT', '--height HEIGHT', 'Set height') { |h| options[:height] = h.to_i }
|
13
|
+
opts.on('-r REFRESH', '--refresh REFRESH', 'Set refresh rate in seconds') { |r| options[:refresh] = r.to_f }
|
14
|
+
opts.on('-v', '--version', 'Print version information') do
|
15
|
+
puts "#{File.basename(__FILE__)} #{CellularAutomata::VERSION}"
|
16
|
+
exit true
|
17
|
+
end
|
18
|
+
opts.on('--help', 'Display this screen') do
|
19
|
+
puts opts
|
20
|
+
exit true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
begin
|
24
|
+
opt_parser.parse!
|
25
|
+
rescue OptionParser::InvalidOption => e
|
26
|
+
puts e.message
|
27
|
+
exit false
|
28
|
+
end
|
29
|
+
options
|
30
|
+
end
|
31
|
+
|
32
|
+
opts = opts_from_cli
|
33
|
+
opts[:width] ||= 120
|
34
|
+
opts[:height] ||= 30
|
35
|
+
opts[:refresh] ||= 0.1
|
36
|
+
rule = ARGV[0] || 'B3S2'
|
37
|
+
board = CellularAutomata::Board.new(width: opts[:width], height: opts[:height], rule: rule)
|
38
|
+
|
39
|
+
trap 'SIGINT' do
|
40
|
+
exit
|
41
|
+
end
|
42
|
+
|
43
|
+
while true do
|
44
|
+
puts "\e[H\e[2J"
|
45
|
+
board.tick!
|
46
|
+
puts board.to_s
|
47
|
+
sleep opts[:refresh]
|
48
|
+
end
|
data/lib/cellular_automata.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cellular_automata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Forrest Fleming
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gosu
|
@@ -152,8 +152,6 @@ email:
|
|
152
152
|
executables:
|
153
153
|
- cell
|
154
154
|
- cell_console
|
155
|
-
- cell_gif
|
156
|
-
- cell_gui
|
157
155
|
extensions:
|
158
156
|
- ext/cellular_c/extconf.rb
|
159
157
|
extra_rdoc_files: []
|
@@ -166,15 +164,12 @@ files:
|
|
166
164
|
- Rakefile
|
167
165
|
- bin/cell
|
168
166
|
- bin/cell_console
|
169
|
-
- bin/cell_gif
|
170
|
-
- bin/cell_gui
|
171
167
|
- cellular_automata.gemspec
|
172
168
|
- ext/cellular_c/cellular_c.c
|
173
169
|
- ext/cellular_c/extconf.rb
|
174
170
|
- lib/cellular_automata.rb
|
175
171
|
- lib/cellular_automata/board.rb
|
176
172
|
- lib/cellular_automata/cell.rb
|
177
|
-
- lib/cellular_automata/gif_writer.rb
|
178
173
|
- lib/cellular_automata/gui_window.rb
|
179
174
|
- lib/cellular_automata/rule.rb
|
180
175
|
- lib/cellular_automata/version.rb
|
data/bin/cell_gif
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'cellular_automata'
|
4
|
-
require 'optparse'
|
5
|
-
require 'gosu'
|
6
|
-
|
7
|
-
def opts_from_cli
|
8
|
-
options = {}
|
9
|
-
opt_parser = OptionParser.new do |opts|
|
10
|
-
opts.program_name = File.basename(__FILE__)
|
11
|
-
opts.banner = "#{opts.program_name} [options] RULE"
|
12
|
-
opts.on('-w WIDTH', '--width WIDTH', 'Set width') { |w| options[:width] = w.to_i }
|
13
|
-
opts.on('-h HEIGHT', '--height HEIGHT', 'Set height') { |h| options[:height] = h.to_i }
|
14
|
-
opts.on('-s SCALE', '--scale SCALE', 'Factor by which to scale game board') { |s| options[:scale] = s.to_i }
|
15
|
-
opts.on('-c WIDTH', '--cell-width WIDTH', 'Factor by which to scale cells', 'Use 1 for an \'LED\' look',
|
16
|
-
'Use 2 for no borders around cells', 'or choose anything in between') {|w| options[:cell_scale] = w.to_f }
|
17
|
-
opts.on('-f FRAMES', '--frames FRAMES', 'Number of frames to write') { |f| options[:frames] = f.to_i }
|
18
|
-
opts.on('-v', '--version', 'Print version information') do
|
19
|
-
puts "#{File.basename(__FILE__)} #{CellularAutomata::VERSION}"
|
20
|
-
exit true
|
21
|
-
end
|
22
|
-
opts.on('--help', 'Display this screen') do
|
23
|
-
puts opts
|
24
|
-
exit true
|
25
|
-
end
|
26
|
-
end
|
27
|
-
begin
|
28
|
-
opt_parser.parse!
|
29
|
-
rescue OptionParser::InvalidOption => e
|
30
|
-
puts e.message
|
31
|
-
exit false
|
32
|
-
end
|
33
|
-
options
|
34
|
-
end
|
35
|
-
|
36
|
-
opts = opts_from_cli
|
37
|
-
opts[:width] ||= 160
|
38
|
-
opts[:height] ||= 120
|
39
|
-
opts[:scale] ||= 1
|
40
|
-
opts[:cell_scale] ||= 2.0
|
41
|
-
opts[:cell_scale] = 2.0 if opts[:cell_scale] > 2.0
|
42
|
-
opts[:cell_scale] = 1.0 if opts[:cell_scale] < 1.0
|
43
|
-
opts[:frames] ||= 100
|
44
|
-
rule = ARGV[0] || 'B3S2'
|
45
|
-
opts[:rule] = rule
|
46
|
-
|
47
|
-
trap 'SIGINT' do
|
48
|
-
exit
|
49
|
-
end
|
50
|
-
|
51
|
-
CellularAutomata::GifWriter.write(opts)
|
52
|
-
exit
|
data/bin/cell_gui
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'cellular_automata'
|
4
|
-
require 'optparse'
|
5
|
-
require 'gosu'
|
6
|
-
|
7
|
-
def opts_from_cli
|
8
|
-
options = {}
|
9
|
-
opt_parser = OptionParser.new do |opts|
|
10
|
-
opts.program_name = File.basename(__FILE__)
|
11
|
-
opts.banner = "#{opts.program_name} [options] RULE"
|
12
|
-
opts.on('-w WIDTH', '--width WIDTH', 'Set width') { |w| options[:width] = w.to_i }
|
13
|
-
opts.on('-h HEIGHT', '--height HEIGHT', 'Set height') { |h| options[:height] = h.to_i }
|
14
|
-
opts.on('-s SCALE', '--scale SCALE', 'Factor by which to scale game board') { |s| options[:scale] = s.to_i }
|
15
|
-
opts.on('-c WIDTH', '--cell-width WIDTH', 'Factor by which to scale cells', 'Use 1 for an \'LED\' look',
|
16
|
-
'Use 2 for no borders around cells', 'or choose anything in between') {|w| options[:cell_scale] = w.to_f }
|
17
|
-
opts.on('-f', '--full-screen', 'Full screen') { options[:fullscreen] = true }
|
18
|
-
opts.on('-v', '--version', 'Print version information') do
|
19
|
-
puts "#{File.basename(__FILE__)} #{CellularAutomata::VERSION}"
|
20
|
-
exit true
|
21
|
-
end
|
22
|
-
opts.on('--help', 'Display this screen') do
|
23
|
-
puts opts
|
24
|
-
exit true
|
25
|
-
end
|
26
|
-
end
|
27
|
-
begin
|
28
|
-
opt_parser.parse!
|
29
|
-
rescue OptionParser::InvalidOption => e
|
30
|
-
puts e.message
|
31
|
-
exit false
|
32
|
-
end
|
33
|
-
options
|
34
|
-
end
|
35
|
-
|
36
|
-
opts = opts_from_cli
|
37
|
-
opts[:width] ||= 160
|
38
|
-
opts[:height] ||= 120
|
39
|
-
opts[:scale] ||= 2
|
40
|
-
opts[:cell_scale] ||= 2.0
|
41
|
-
opts[:cell_scale] = 2.0 if opts[:cell_scale] > 2.0
|
42
|
-
opts[:cell_scale] = 1.0 if opts[:cell_scale] < 1.0
|
43
|
-
opts[:fullscreen] ||= false
|
44
|
-
rule = ARGV[0] || 'B3S2'
|
45
|
-
opts[:rule] = rule
|
46
|
-
|
47
|
-
trap 'SIGINT' do
|
48
|
-
exit
|
49
|
-
end
|
50
|
-
|
51
|
-
window = CellWindow.new(opts)
|
52
|
-
window.show
|
53
|
-
exit
|
@@ -1,56 +0,0 @@
|
|
1
|
-
module CellularAutomata::GifWriter
|
2
|
-
class << self
|
3
|
-
def write(opts={})
|
4
|
-
@scale = opts[:scale]
|
5
|
-
@cell_width = scale**opts[:cell_scale]
|
6
|
-
@board = CellularAutomata::Board.new(width: opts[:width]/scale, height: opts[:height]/scale, rule: opts[:rule])
|
7
|
-
@gif = Magick::ImageList.new
|
8
|
-
@width = opts[:width]
|
9
|
-
@height = opts[:height]
|
10
|
-
@frames = opts[:frames]
|
11
|
-
write_gif('test.gif')
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
attr_reader :board, :scale, :cell_width, :frames, :writer, :height, :width
|
17
|
-
|
18
|
-
def write_gif(outfile)
|
19
|
-
frames.times do |i|
|
20
|
-
draw_frame
|
21
|
-
board.tick!
|
22
|
-
end
|
23
|
-
@gif.write(outfile)
|
24
|
-
end
|
25
|
-
|
26
|
-
def draw_frame
|
27
|
-
writer = Magick::Draw.new
|
28
|
-
frame = Magick::Image.new(width, height) do
|
29
|
-
self.background_color = '#000000'
|
30
|
-
end
|
31
|
-
board.each_cell do |cell|
|
32
|
-
prev_1 = board.history[0][cell.y][cell.x]
|
33
|
-
prev_2 = board.history[1][cell.y][cell.x]
|
34
|
-
color = '#000000'
|
35
|
-
if cell.alive?
|
36
|
-
color = '#FFFF00'
|
37
|
-
elsif prev_1.alive?
|
38
|
-
color = '#AAAA00'
|
39
|
-
elsif prev_2.alive?
|
40
|
-
color = '#444400'
|
41
|
-
end
|
42
|
-
writer.stroke color
|
43
|
-
writer.fill color
|
44
|
-
x1 = cell.x * scale**2
|
45
|
-
y1 = cell.y * scale**2
|
46
|
-
x2 = x1 + cell_width
|
47
|
-
y2 = y1 + cell_width
|
48
|
-
writer.rectangle(x1, y1, x2, y2)
|
49
|
-
end
|
50
|
-
writer.draw(frame)
|
51
|
-
@gif << frame
|
52
|
-
print '.'
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|