cellular_automata 0.1.1 → 0.1.2
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/README.md +5 -0
- data/bin/cell_gui +53 -0
- data/cellular_automata.gemspec +10 -8
- data/lib/cellular_automata/board.rb +2 -2
- data/lib/cellular_automata/gui_window.rb +35 -0
- data/lib/cellular_automata/rule.rb +1 -1
- data/lib/cellular_automata/version.rb +1 -1
- data/lib/cellular_automata.rb +2 -0
- metadata +39 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 891c6c36e259e19ad44dad69cdfef0336058978a
|
4
|
+
data.tar.gz: 4e5898cdadcdc8031601e70f4da409b8157fdbb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e7ae0a28aecd0030faefaa03fefe2671ed7d0a1e477190d48506c2178d5a5e9a9322e827fa3f52b21bd4024370ffc2b6448bc8741f49b0fdc4f7a705d6d632e
|
7
|
+
data.tar.gz: e59aaed8f24f32467b4c069c3df8a40e458d64cb872703f17c553933ec6a469a2b1f1696598dc7bb48dadf4425abd335f1f96929abb39cdbd9e1e2db7ec6f26a
|
data/README.md
CHANGED
@@ -25,6 +25,11 @@ At present, it can only play Conway's Game of Life. Run `cell` to watch.
|
|
25
25
|
|
26
26
|
## Development
|
27
27
|
|
28
|
+
Install gosu dependencies:
|
29
|
+
```bash
|
30
|
+
% brew install sdl2 libogg libvorbis
|
31
|
+
```
|
32
|
+
|
28
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.
|
29
34
|
|
30
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).
|
data/bin/cell_gui
ADDED
@@ -0,0 +1,53 @@
|
|
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
|
data/cellular_automata.gemspec
CHANGED
@@ -4,24 +4,26 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'cellular_automata/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'cellular_automata'
|
8
8
|
spec.version = CellularAutomata::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['Forrest Fleming']
|
10
|
+
spec.email = ['ffleming@gmail.com']
|
11
11
|
|
12
12
|
spec.summary = %q{A simulation of cellular automata}
|
13
13
|
spec.description = %q{A set of 0-player games, of which Conway's Game of Life is a member.}
|
14
|
-
spec.homepage =
|
14
|
+
spec.homepage = 'https://github.com/ffleming/cellular_automata'
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
-
spec.bindir =
|
17
|
+
spec.bindir = 'bin'
|
18
18
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
-
spec.require_paths = [
|
19
|
+
spec.require_paths = ['lib']
|
20
20
|
|
21
21
|
spec.license = 'MIT'
|
22
22
|
|
23
|
-
spec.
|
24
|
-
spec.add_development_dependency
|
23
|
+
spec.add_runtime_dependency 'gosu', '~> 0.9'
|
24
|
+
spec.add_development_dependency 'releasy', '~> 1', '>= 1.8'
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1', '>= 1.8'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
25
27
|
spec.add_development_dependency 'pry', '~> 0.10'
|
26
28
|
spec.add_development_dependency 'byebug', '~> 4'
|
27
29
|
spec.add_development_dependency 'pry-byebug', '~> 3.1'
|
@@ -29,8 +29,6 @@ class CellularAutomata::Board
|
|
29
29
|
@state = next_state
|
30
30
|
end
|
31
31
|
|
32
|
-
private
|
33
|
-
|
34
32
|
def each_cell
|
35
33
|
(0..height-1).each do |y|
|
36
34
|
(0..width-1).each do |x|
|
@@ -39,6 +37,8 @@ class CellularAutomata::Board
|
|
39
37
|
end
|
40
38
|
end
|
41
39
|
|
40
|
+
private
|
41
|
+
|
42
42
|
def seed!
|
43
43
|
each_cell { |c| c.live! if rand < 0.1 }
|
44
44
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class CellWindow < Gosu::Window
|
2
|
+
attr_reader :board, :scale, :cell_width, :paused
|
3
|
+
alias paused? paused
|
4
|
+
def initialize(opts={})
|
5
|
+
@scale = opts[:scale]
|
6
|
+
@cell_width = scale**opts[:cell_scale]
|
7
|
+
super opts[:width]*scale, opts[:height]*scale, opts[:fullscreen]
|
8
|
+
@board = CellularAutomata::Board.new(width: opts[:width]/scale, height: opts[:height]/scale, rule: opts[:rule])
|
9
|
+
self.caption = "Cellular Automata"
|
10
|
+
end
|
11
|
+
|
12
|
+
def update
|
13
|
+
board.tick! unless paused?
|
14
|
+
end
|
15
|
+
|
16
|
+
def draw
|
17
|
+
board.each_cell do |cell|
|
18
|
+
color = cell.alive? ? Gosu::Color::YELLOW : Gosu::Color::BLACK
|
19
|
+
Gosu.draw_rect(cell.x * scale**2, cell.y * scale**2, cell_width, cell_width, color, 0, :default)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def button_down(id)
|
24
|
+
if id == Gosu::KbSpace
|
25
|
+
toggle_pause
|
26
|
+
else
|
27
|
+
exit
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def toggle_pause
|
32
|
+
@paused = !@paused
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
@@ -15,7 +15,7 @@ class CellularAutomata::Rule
|
|
15
15
|
|
16
16
|
def process_rule!(rule_string)
|
17
17
|
rules = rule_string.scan(/[BS]\d+/)
|
18
|
-
raise ArgumentError.new(
|
18
|
+
raise ArgumentError.new("Invalid rule string #{rule_string}") if rules.length != 2
|
19
19
|
birth_string = rules.select {|s| s.start_with?('B')}.first
|
20
20
|
survive_string = rules.select {|s| s.start_with?('S')}.first
|
21
21
|
(birth, survive) = [birth_string, survive_string].map { |s| s[1..-1].split('').map(&:to_i) }
|
data/lib/cellular_automata.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
require 'pry'
|
2
2
|
require 'byebug'
|
3
3
|
require 'pry-byebug'
|
4
|
+
require 'gosu'
|
4
5
|
require "cellular_automata/version"
|
5
6
|
require "cellular_automata/cell"
|
6
7
|
require "cellular_automata/rule"
|
7
8
|
require "cellular_automata/board"
|
9
|
+
require "cellular_automata/gui_window"
|
8
10
|
|
9
11
|
module CellularAutomata
|
10
12
|
end
|
metadata
CHANGED
@@ -1,15 +1,49 @@
|
|
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.2
|
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-05-
|
11
|
+
date: 2015-05-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: gosu
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.9'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: releasy
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '1.8'
|
37
|
+
type: :development
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '1'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.8'
|
13
47
|
- !ruby/object:Gem::Dependency
|
14
48
|
name: bundler
|
15
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -91,6 +125,7 @@ email:
|
|
91
125
|
- ffleming@gmail.com
|
92
126
|
executables:
|
93
127
|
- cell
|
128
|
+
- cell_gui
|
94
129
|
extensions: []
|
95
130
|
extra_rdoc_files: []
|
96
131
|
files:
|
@@ -101,10 +136,12 @@ files:
|
|
101
136
|
- README.md
|
102
137
|
- Rakefile
|
103
138
|
- bin/cell
|
139
|
+
- bin/cell_gui
|
104
140
|
- cellular_automata.gemspec
|
105
141
|
- lib/cellular_automata.rb
|
106
142
|
- lib/cellular_automata/board.rb
|
107
143
|
- lib/cellular_automata/cell.rb
|
144
|
+
- lib/cellular_automata/gui_window.rb
|
108
145
|
- lib/cellular_automata/rule.rb
|
109
146
|
- lib/cellular_automata/version.rb
|
110
147
|
homepage: https://github.com/ffleming/cellular_automata
|