rsirts 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1807f23a6d12b88ff1fe4f7a6059903e435745b8
4
+ data.tar.gz: 3cdd73218bd798da08264b3cfb1d9d550d204354
5
+ SHA512:
6
+ metadata.gz: feb5710ba2f19ea4633782b2d1046dc7de0c314f2c78c2c5df0ebdabc1da4e57e48d33f60f1c645509441e0cb2fc4d1f9c72227a6a20ca8c5eb428261dba9743
7
+ data.tar.gz: f69df94f69aff50f274c035e9faac8983e91e858467d7bfe46aafdbba5e5d57b84a2783b4280a5bbcb6c2e14f4a89121f522c8ed50aebf9c7c2ebfcc9191501b
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rsirts.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Sankaranarayanan Viswanathan
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # Rsirts
2
+
3
+ Generate SIRTS (Single Image Random Text Stereograms)
4
+
5
+ ## Installation
6
+
7
+ $ gem install rsirts
8
+
9
+ ## Usage
10
+
11
+ $ rsirts samples/sirts01.txt
12
+
13
+ ## Contributing
14
+
15
+ 1. Fork it ( http://github.com/rationalrevolt/rsirts/fork )
16
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
17
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
18
+ 4. Push to the branch (`git push origin my-new-feature`)
19
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/rsirts ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rsirts'
4
+
5
+ usage = <<END
6
+ Usage: #{$0} depth_map_file
7
+ END
8
+
9
+ args_present = ARGV[0]
10
+
11
+ unless args_present
12
+ puts usage
13
+ exit
14
+ end
15
+
16
+ inp_file_path = ARGV[0]
17
+
18
+ puts; puts; puts; puts
19
+ Rsirts.generate(inp_file_path).each do |line|
20
+ puts line
21
+ end
22
+ puts; puts; puts; puts
data/lib/rsirts.rb ADDED
@@ -0,0 +1,11 @@
1
+ require "rsirts/version"
2
+ require "rsirts/parser"
3
+ require "rsirts/renderer"
4
+
5
+ module Rsirts
6
+
7
+ def self.generate path
8
+ Renderer.new(Parser.parse path).generate
9
+ end
10
+
11
+ end
@@ -0,0 +1,43 @@
1
+ module Rsirts
2
+
3
+ class ParseError < StandardError; end
4
+
5
+ class Parser
6
+
7
+ ZMAP_VALUES = Hash[ "12345689-".each_char.to_a.map { |v| [v, v == '-' ? 0 : v.to_i] } ]
8
+
9
+ def self.parse path
10
+ new.parse path
11
+ end
12
+
13
+ def parse path
14
+ map_depth(
15
+ File.new(path)
16
+ .readlines
17
+ .map { |line| line.chomp }
18
+ .tap { |lines| check_format lines }
19
+ )
20
+ end
21
+
22
+ private
23
+
24
+ def check_format lines
25
+ lines.each_with_index do |line,i|
26
+ line_length ||= line.length
27
+ raise ParseError, "Length of line #{i+1} does not match previous lines" if line.length != line_length
28
+ raise ParseError, "Invalid character at line #{i+1} position #{$~.offset(0)[0]}" if line[/[^-0-9]/]
29
+ end
30
+ end
31
+
32
+ def map_depth lines
33
+ lines.map do |line|
34
+ line.each_char.to_a.map do |c|
35
+ ZMAP_VALUES[c]
36
+ end
37
+ end
38
+ end
39
+
40
+ end
41
+
42
+ end
43
+
@@ -0,0 +1,122 @@
1
+ module Rsirts
2
+
3
+ class Ring
4
+
5
+ def initialize elements
6
+ @elements = elements.dup
7
+ @indx = 0
8
+ end
9
+
10
+ def add new_elements
11
+ left = elements.take(indx)
12
+ right = elements.drop(indx)
13
+ self.elements = left + new_elements + right
14
+ end
15
+
16
+ def remove count
17
+ from_indx = size - indx
18
+ from_beg = count - from_indx
19
+ if count >= from_indx
20
+ elements.pop(from_indx)
21
+ elements.slice!(0,from_beg) unless from_beg == 0
22
+ self.indx = 0
23
+ else
24
+ elements.slice!(indx,count)
25
+ end
26
+ end
27
+
28
+ def next
29
+ result = elements[indx]
30
+ increment_indx
31
+ result
32
+ end
33
+
34
+ def size
35
+ elements.size
36
+ end
37
+
38
+ private
39
+
40
+ attr_accessor :indx, :elements
41
+
42
+ def increment_indx
43
+ self.indx = indx == (size - 1) ? 0 : indx + 1
44
+ end
45
+
46
+ end
47
+
48
+ class Renderer
49
+
50
+ PATTERN_CHARS = ('!'..'~').to_a
51
+ DEFAULT_PATTERN_LENGTH = 12
52
+
53
+ def initialize zmap_lines
54
+ @zmap_lines = zmap_lines
55
+ @width = zmap_lines[0].size
56
+ end
57
+
58
+ def generate
59
+ zmap_lines.map do |line|
60
+ translate_line line
61
+ end
62
+ end
63
+
64
+ private
65
+
66
+ attr_reader :zmap_lines, :width
67
+ attr_accessor :current_line, :pattern
68
+
69
+ def translate_line line
70
+ initialize_for_new_line
71
+
72
+ append_pattern
73
+
74
+ old_z = nil
75
+ line.each do |z; z_diff|
76
+ z_diff = z - old_z if old_z
77
+ begin
78
+ shorten_pattern(z_diff) if z_diff > 0
79
+ lengthen_pattern(-z_diff) if z_diff < 0
80
+ end if z_diff
81
+ append_pattern_char
82
+ old_z = z
83
+ end
84
+
85
+ current_line
86
+ end
87
+
88
+ def initialize_for_new_line
89
+ @current_line = nil.to_s
90
+ @pattern = Ring.new(random_pattern DEFAULT_PATTERN_LENGTH)
91
+ end
92
+
93
+ def append_pattern
94
+ pattern.size.times { current_line << pattern.next }
95
+ end
96
+
97
+ def append_pattern_char
98
+ current_line << pattern.next
99
+ end
100
+
101
+ def shorten_pattern n
102
+ pattern.remove(n)
103
+ end
104
+
105
+ def lengthen_pattern n
106
+ pattern.add random_pattern(n)
107
+ end
108
+
109
+ def random_pattern n
110
+ chars = PATTERN_CHARS.dup
111
+ [].tap do |pat|
112
+ n.times do
113
+ item = chars.sample
114
+ pat << item
115
+ chars.delete_at(chars.find_index(item))
116
+ end
117
+ end
118
+ end
119
+
120
+ end
121
+
122
+ end
@@ -0,0 +1,3 @@
1
+ module Rsirts
2
+ VERSION = "0.0.1"
3
+ end
data/rsirts.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rsirts/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rsirts"
8
+ spec.version = Rsirts::VERSION
9
+ spec.authors = ["Sankaranarayanan Viswanathan"]
10
+ spec.email = ["rationalrevolt@gmail.com"]
11
+ spec.summary = %q{Generate SIRTS (Single Image Random Text Stereograms)}
12
+ spec.description = %q{N/A}
13
+ spec.homepage = "https://github.com/rationalrevolt/rsirts"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,35 @@
1
+ ----------------------------------------------------------------------------------------------------
2
+ ----------------------------------------------------------------------------------------------------
3
+ ----------------------------------------------------------------------------------------------------
4
+ ----------------------------------------------------------------------------------------------------
5
+ ----------------------------------------------------------------------------------------------------
6
+ --------------------------------222222---------2222222222-------------------------------------------
7
+ -------------------------------22222222------2222222222222------------------------------------------
8
+ ------------------------------2222222222---22222222222222222----------------------------------------
9
+ ----------------------------2222222222222-2222222222222222222---------------------------------------
10
+ ---------------------------22222222222222222222222222222222222--------------------------------------
11
+ ----------------------------222222222222222222222222222222222---------------------------------------
12
+ -----------------------------2222222222222222222222222222222----------------------------------------
13
+ ------------------------------22222222222222222222222222222-----------------------------------------
14
+ -------------------------------222222222222222222222222222------------------------------------------
15
+ --------------------------------2222222222222222222222222-------------------------------------------
16
+ ---------------------------------22222222222222222222222--------------------------------------------
17
+ ----------------------------------222222222222222222222---------------------------------------------
18
+ -----------------------------------2222222222222222222----------------------------------------------
19
+ ------------------------------------22222222222222222-----------------------------------------------
20
+ -------------------------------------222222222222222------------------------------------------------
21
+ --------------------------------------2222222222222-------------------------------------------------
22
+ ---------------------------------------22222222222--------------------------------------------------
23
+ ----------------------------------------222222222---------------------------------------------------
24
+ -----------------------------------------2222222----------------------------------------------------
25
+ ------------------------------------------22222-----------------------------------------------------
26
+ -------------------------------------------222------------------------------------------------------
27
+ --------------------------------------------2-------------------------------------------------------
28
+ ----------------------------------------------------------------------------------------------------
29
+ ----------------------------------------------------------------------------------------------------
30
+ ----------------------------------------------------------------------------------------------------
31
+ ----------------------------------------------------------------------------------------------------
32
+ ----------------------------------------------------------------------------------------------------
33
+ ----------------------------------------------------------------------------------------------------
34
+ ----------------------------------------------------------------------------------------------------
35
+ ----------------------------------------------------------------------------------------------------
@@ -0,0 +1,35 @@
1
+ ----------------------------------------------------------------------------------------------------
2
+ ----------------------------------------------------------------------------------------------------
3
+ ----------------------------------------------------------------------------------------------------
4
+ ----------------------------------------------------------------------------------------------------
5
+ ----------------------------------------------------------------------------------------------------
6
+ ----------------------------------------------------------------------------------------------------
7
+ ----------------------------------------------------------------------------------------------------
8
+ ----------------------------------------------------------------------------------------------------
9
+ ----------------------------------------------------------------------------------------------------
10
+ ----------------------------------------------------------------------------------------------------
11
+ ----------------------------------------------------------------------------------------------------
12
+ ----------------------------------------------------------------------------------------------------
13
+ ----------------------------------------------------------------------------------------------------
14
+ ----------------------------------------------------------------------------------------------------
15
+ ----------------------------------------------------------------------------------------------------
16
+ ----------------------------------------------------------------------------------------------------
17
+ ----------------------------------------------------------------------------------------------------
18
+ ----------------------------------------------------------------------------------------------------
19
+ ----------------------------------------------------------------------------------------------------
20
+ ----------------------------------------------------------------------------------------------------
21
+ ----------------------------------------------------------------------------------------------------
22
+ ----------------------------------------------------------------------------------------------------
23
+ ----------------------------------------------------------------------------------------------------
24
+ ----------------------------------------------------------------------------------------------------
25
+ ----------------------------------------------------------------------------------------------------
26
+ ----------------------------------------------------------------------------------------------------
27
+ ----------------------------------------------------------------------------------------------------
28
+ ----------------------------------------------------------------------------------------------------
29
+ ----------------------------------------------------------------------------------------------------
30
+ ----------------------------------------------------------------------------------------------------
31
+ ----------------------------------------------------------------------------------------------------
32
+ ----------------------------------------------------------------------------------------------------
33
+ ----------------------------------------------------------------------------------------------------
34
+ ----------------------------------------------------------------------------------------------------
35
+ ----------------------------------------------------------------------------------------------------
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rsirts
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sankaranarayanan Viswanathan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: N/A
42
+ email:
43
+ - rationalrevolt@gmail.com
44
+ executables:
45
+ - rsirts
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - .gitignore
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bin/rsirts
55
+ - lib/rsirts.rb
56
+ - lib/rsirts/parser.rb
57
+ - lib/rsirts/renderer.rb
58
+ - lib/rsirts/version.rb
59
+ - rsirts.gemspec
60
+ - samples/sirts01.txt
61
+ - samples/template.txt
62
+ homepage: https://github.com/rationalrevolt/rsirts
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.1.11
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Generate SIRTS (Single Image Random Text Stereograms)
86
+ test_files: []