stitchify 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/stitchify.rb +238 -5
  3. metadata +75 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd5cd513fea21877b22b4e7fbd75a85ac9037a98
4
- data.tar.gz: e661188624d3977124ea6ca5ee02c748aae78a81
3
+ metadata.gz: c1ae236a6ab9fa858d781b1a3dd11be1346f7b38
4
+ data.tar.gz: 7030f2b85807ff84c8bbf7439f2eb8de6e25d58a
5
5
  SHA512:
6
- metadata.gz: b0a792aaf6e2e8de81281f7a81304676746d50f58eb3b64019f60c8aac4ce34362bb8fbe811758e09c195baa55f8249c8d4f9574832630d235935af835621ebc
7
- data.tar.gz: e4093cec0a808d294304d429b01d3ae9fce084e9071c23beaa8f91cbe95df9dcb640829a88c6f0dd2900d24bcc637fe15b887297c59cefb8f246fc5263d786e5
6
+ metadata.gz: 9f2c9384433e03f5269f76a5a03f765e19bf3ba47d39f2847e1c61e32822d11d42e62cf14fc014e3e47ade599c9cfb7a8792da393e883700baec71ab3274c2fc
7
+ data.tar.gz: 987943c1456f54ac0c1753fdde31e4af09bd6558bed9ef940bce7aadef33596a0c8806a61f0ef503a1632a261cbd5dc94e7cdaf30a8dbd9eb2fcfcc66720ba81
data/lib/stitchify.rb CHANGED
@@ -1,5 +1,238 @@
1
- class Stitchify
2
- def self.hi
3
- puts "Hello world"
4
- end
5
- end
1
+ class Stitchifier
2
+ require 'nokogiri'
3
+ require 'open-uri'
4
+ require 'pry'
5
+ require 'rasem'
6
+ require 'asciiart'
7
+
8
+ attr_accessor :px, :pos_x, :pos_y, :width, :height, :ascii_width
9
+
10
+ def initialize(px = 10, ascii_width = 45)
11
+ self.px = px
12
+ self.pos_x = 0
13
+ self.pos_y = 0
14
+ self.width = 4 * px
15
+ self.height = 4 * px
16
+ self.ascii_width = ascii_width
17
+ end
18
+
19
+ def stitch(img, file = 'stitchify.svg')
20
+ ascii = img_processor(img)
21
+ arrs = paragraph_builder(ascii)
22
+ arrs = arrs + grid
23
+ rasem = arrs_to_rasem(arrs)
24
+ write(rasem, file)
25
+ clear_vars
26
+ end
27
+
28
+ def clear_vars
29
+ pos_x = 0
30
+ pos_y = 0
31
+ width = 0
32
+ height = 0
33
+ end
34
+
35
+ def img_processor(img)
36
+ AsciiArt.new(img).to_ascii_art(width: ascii_width)
37
+ end
38
+
39
+ def arrs_to_rasem(arrs)
40
+ Rasem::SVGImage.new(width: self.width, height: self.height) do
41
+ for line_data in arrs
42
+ line line_data[0], line_data[1], line_data[2], line_data[3]
43
+ end
44
+ end
45
+ end
46
+
47
+ def write(rasem, file)
48
+ File.open(file, "w") do |f|
49
+ rasem.write(f)
50
+ end
51
+ end
52
+
53
+ def grid
54
+ n = 10
55
+ output = []
56
+ (width / n).times do |i|
57
+ output << [i * n, 0, i * n, height]
58
+ end
59
+ (height / n).times do |i|
60
+ output << [0, i * n, width, i * n]
61
+ end
62
+ output
63
+ end
64
+
65
+ def paragraph_builder(str)
66
+ self.height = 0
67
+ arr = str.split("\n")
68
+ output = []
69
+ arr.each do |line|
70
+ output = output + line_builder(line)
71
+ self.pos_y = self.pos_y + (4 * px)
72
+ self.pos_x = 0
73
+ self.height = self.height + (4 * px)
74
+ end
75
+ output
76
+ end
77
+
78
+ def line_builder(line)
79
+ self.width = 0
80
+ line_output = []
81
+ line.split('').each do |char|
82
+ line_output = line_output + char_builder(char)
83
+ self.pos_x = self.pos_x + (4 * px)
84
+ self.width = self.width + (4 * px)
85
+ end
86
+ line_output
87
+ end
88
+
89
+ def char_builder(char)
90
+ output = []
91
+ case char
92
+ when '.'
93
+ output << pos_slope_one(1.5 * px, 3.5 * px, px)
94
+ output << neg_slope_one(1.5 * px, 2.5 * px, px)
95
+ when '~'
96
+ output << pos_slope_one(px / 2, 2.5 * px, px)
97
+ output << neg_slope_one(1.5 * px, 1.5 * px, px)
98
+ output << pos_slope_one(2.5 * px, 2.5 * px, px)
99
+ when ':'
100
+ output << pos_slope_one(1.5 * px, 3.5 * px, px)
101
+ output << neg_slope_one(1.5 * px, 2.5 * px, px)
102
+ output << pos_slope_one(1.5 * px, 1.5 * px, px)
103
+ output << neg_slope_one(1.5 * px, px / 2, px)
104
+ when '+'
105
+ output << vertical_line(2.5 * px, px / 2, 3 * px)
106
+ output << horizontal_line(px / 2, 1.5 * px, 3 * px)
107
+ when '='
108
+ output << horizontal_line(px / 2, 1.5 * px, 3 * px)
109
+ output << horizontal_line(px / 2, 2.5 * px, 3 * px)
110
+ when 'o'
111
+ output << pos_slope_one( px / 2, 1.5 * px, px)
112
+ output << horizontal_line(1.5 * px, px / 2, px)
113
+ output << neg_slope_one( 2.5 * px, px / 2, px)
114
+ output << vertical_line( 3.5 * px, 1.5 * px, px)
115
+ output << pos_slope_one( 2.5 * px, 3.5 * px, px)
116
+ output << horizontal_line(1.5 * px, 3.5 * px, px)
117
+ output << neg_slope_one( px / 2, 2.5 * px, px)
118
+ output << vertical_line( px / 2, 1.5 * px, px)
119
+ when '*'
120
+ output << pos_slope_one(px / 2, 3.5 * px , 3 * px)
121
+ output << neg_slope_one(px / 2, px / 2, 3 * px)
122
+ output << vertical_line(2.5 * px, px / 2, 3 * px)
123
+ when 'x'
124
+ output << pos_slope_one(px / 2, 3.5 * px, 3 * px)
125
+ output << neg_slope_one(px / 2, px / 2, 3 * px)
126
+ when '^'
127
+ output << pos_slope_one(1.5 * px, 1.5 * px, px)
128
+ output << neg_slope_one(2.5 * px, px / 2, px)
129
+ when '%'
130
+ output << pos_slope_one(px / 2, 1.5 * px, px)
131
+ output << neg_slope_one(px / 2, px / 2, px)
132
+ output << pos_slope_one(px / 2, 3.5 * px, 3 * px)
133
+ output << pos_slope_one(2.5 * px, 3.5 * px, px)
134
+ output << neg_slope_one(2.5 * px, 2.5 * px, px)
135
+ when '#'
136
+ output << vertical_line(1.5 * px, px / 2, 3 * px)
137
+ output << vertical_line(2.5 * px, px / 2, 3 * px)
138
+ output << horizontal_line(px / 2, 1.5 * px, 3 * px)
139
+ output << horizontal_line(px / 2, 2.5 * px, 3 * px)
140
+ when '@'
141
+ output << pos_slope_one(2.5 * px, 2.5 * px, px)
142
+ output << neg_slope_one(2.5 * px, 1.5 * px, px)
143
+ output << vertical_line(3.5 * px, px / 2, 2 * px)
144
+ output << horizontal_line(1.5 * px, px / 2, 2 * px)
145
+ output << pos_slope_two(px / 2, 2.5 * px, px)
146
+ output << neg_slope_one(px / 2, 2.5 * px, px)
147
+ output << horizontal_line(1.5 * px, 3.5 * px, 2 * px)
148
+ when '$'
149
+ output << pos_slope_one(1.5 * px, 1.5 * px, px)
150
+ output << neg_slope_one(2.5 * px, px / 2, px)
151
+ output << neg_slope_half(1.5 * px, 1.5 * px, px)
152
+ output << pos_slope_one(2.5 * px, 3.5 * px, px)
153
+ output << neg_slope_one(1.5 * px, 2.5 * px, px)
154
+ output << vertical_line(2.5 * px, px / 2, 3 * px)
155
+ when 'M'
156
+ output << vertical_line(1.5 * px, px / 2, 3 * px)
157
+ output << neg_slope_two(1.5 * px, px / 2, px)
158
+ output << pos_slope_two(2.5 * px, 2.5 * px, px)
159
+ output << vertical_line(3.5 * px, px / 2, 3 * px)
160
+ when 'W'
161
+ output << vertical_line(1.5 * px, px / 2, 3 * px)
162
+ output << pos_slope_two(1.5 * px, 3.5 * px, px)
163
+ output << neg_slope_two(2.5 * px, 1.5 * px, px)
164
+ output << vertical_line(3.5 * px, px / 2, 3 * px)
165
+ when '|'
166
+ output << vertical_line(2.5 * px, px / 2, 3 * px)
167
+ when '-'
168
+ output << horizontal_line(px / 2, 2.5 * px, 3 * px)
169
+ end
170
+ output
171
+ end
172
+
173
+ def pos_slope_one(startX, startY, length)
174
+ [
175
+ startX + pos_x,
176
+ startY + pos_y,
177
+ startX + pos_x + length,
178
+ startY + pos_y - length
179
+ ]
180
+ end
181
+
182
+ def neg_slope_one(startX, startY, length)
183
+ [
184
+ startX + pos_x,
185
+ startY + pos_y,
186
+ startX + pos_x + length,
187
+ startY + pos_y + length
188
+ ]
189
+ end
190
+
191
+ def vertical_line(startX, startY, length)
192
+ [
193
+ startX + pos_x,
194
+ startY + pos_y,
195
+ startX + pos_x,
196
+ startY + pos_y + length
197
+ ]
198
+ end
199
+
200
+ def horizontal_line(startX, startY, length)
201
+ [
202
+ startX + pos_x,
203
+ startY + pos_y,
204
+ startX + pos_x + length,
205
+ startY + pos_y
206
+ ]
207
+ end
208
+
209
+ def pos_slope_two(startX, startY, width)
210
+ [
211
+ startX + pos_x,
212
+ startY + pos_y,
213
+ startX + pos_x + width,
214
+ startY + pos_y - (2 * width)
215
+ ]
216
+ end
217
+
218
+ def neg_slope_half(startX, startY, height)
219
+ [
220
+ startX + pos_x,
221
+ startY + pos_y,
222
+ startX + pos_x + (2 * height),
223
+ startY + pos_y + height
224
+ ]
225
+ end
226
+
227
+ def neg_slope_two(startX, startY, width)
228
+ [
229
+ startX + pos_x,
230
+ startY + pos_y,
231
+ startX + pos_x + width,
232
+ startY + pos_y + (2 * width)
233
+ ]
234
+ end
235
+ end
236
+
237
+ s = Stitchifier.new
238
+ s.stitch('../../../Downloads/MYFACE.jpg')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stitchify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ellen Wondra
@@ -9,7 +9,77 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2018-03-05 00:00:00.000000000 Z
12
- dependencies: []
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.8.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.8.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: rasem
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.7.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.7.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: asciiart
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.0.9
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.0.9
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
13
83
  description: input an HTML document and output an SVG cross stitching pattern
14
84
  email: ellenfromillinois@gmail.com
15
85
  executables: []
@@ -27,17 +97,17 @@ require_paths:
27
97
  - lib
28
98
  required_ruby_version: !ruby/object:Gem::Requirement
29
99
  requirements:
30
- - - '>='
100
+ - - ">="
31
101
  - !ruby/object:Gem::Version
32
102
  version: '0'
33
103
  required_rubygems_version: !ruby/object:Gem::Requirement
34
104
  requirements:
35
- - - '>='
105
+ - - ">="
36
106
  - !ruby/object:Gem::Version
37
107
  version: '0'
38
108
  requirements: []
39
109
  rubyforge_project:
40
- rubygems_version: 2.0.14.1
110
+ rubygems_version: 2.6.14
41
111
  signing_key:
42
112
  specification_version: 4
43
113
  summary: converts an HTML document into a cross stitching pattern