stitchify 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/stitchify.rb +279 -238
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c73c9993fb08707c070876e610733903a80fc6e
|
4
|
+
data.tar.gz: b09b9fcca355a156c0ba60425767faac7da06489
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d810c0bec150c1525dddc6c140026adfa04ad2c6851d6fecf8356f8e11f2d61ad5fe2056b80aa28b0846f938e10fa2ba052a44c118f89153ba6fac9e94f12dd
|
7
|
+
data.tar.gz: 05056621ccac0f50e750ff4b473a8aed14bec07f7acef7ea41715751c4fa8260cbb622b24b09ecbb223b5f527753a610c74592c0cedc551be314eae812d3c81f
|
data/lib/stitchify.rb
CHANGED
@@ -1,238 +1,279 @@
|
|
1
|
-
class Stitchifier
|
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
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
startX
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
startY
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
1
|
+
class Stitchifier
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'open-uri'
|
4
|
+
require 'pry'
|
5
|
+
require 'rasem'
|
6
|
+
require 'asciiart'
|
7
|
+
require 'hex256'
|
8
|
+
|
9
|
+
OPEN_BRACKET = "\e[38;5;"
|
10
|
+
CLOSE_BRACKET = "\e[0m"
|
11
|
+
|
12
|
+
attr_accessor :px, :pos_x, :pos_y, :width, :height, :ascii_width
|
13
|
+
|
14
|
+
def initialize(px = 10, ascii_width = nil)
|
15
|
+
self.px = px
|
16
|
+
self.pos_x = 0
|
17
|
+
self.pos_y = 0
|
18
|
+
self.width = 4 * px
|
19
|
+
self.height = 4 * px
|
20
|
+
self.ascii_width = ascii_width
|
21
|
+
end
|
22
|
+
|
23
|
+
def stitch(img, file = 'stitchify.svg')
|
24
|
+
ascii = img_processor(img)
|
25
|
+
arrs = paragraph_builder(ascii)
|
26
|
+
rasem = arrs_to_rasem(arrs, grid)
|
27
|
+
write(rasem, file)
|
28
|
+
clear_vars
|
29
|
+
end
|
30
|
+
|
31
|
+
# ".~:+=o*x^%#@$MW\n .~:+=o*x^%#@$M\nW.~:+=o*x^% #@$MW"
|
32
|
+
|
33
|
+
def stitch_string(str, file = 'stitchify.svg')
|
34
|
+
arrs = paragraph_builder(str)
|
35
|
+
rasem = arrs_to_rasem(arrs, grid)
|
36
|
+
write(rasem, file)
|
37
|
+
clear_vars
|
38
|
+
end
|
39
|
+
|
40
|
+
def clear_vars
|
41
|
+
self.pos_x = 0
|
42
|
+
self.pos_y = 0
|
43
|
+
self.width = 0
|
44
|
+
self.height = 0
|
45
|
+
end
|
46
|
+
|
47
|
+
def ascii_conditions
|
48
|
+
ret = {}
|
49
|
+
ret[:color] = false
|
50
|
+
ret[:width] = self.ascii_width unless self.ascii_width.nil?
|
51
|
+
ret
|
52
|
+
end
|
53
|
+
|
54
|
+
def img_processor(img)
|
55
|
+
AsciiArt.new(img).to_ascii_art(ascii_conditions)
|
56
|
+
end
|
57
|
+
|
58
|
+
def arrs_to_rasem(arrs, grid)
|
59
|
+
Rasem::SVGImage.new(width: self.width, height: self.height) do
|
60
|
+
for line_data in arrs
|
61
|
+
line line_data[0], line_data[1], line_data[2], line_data[3], :stroke_width=>2, :fill=>line_data[4], :stroke=>line_data[4]
|
62
|
+
end
|
63
|
+
for line_data in grid
|
64
|
+
line line_data[0], line_data[1], line_data[2], line_data[3], :stroke_width=>line_data[5]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def write(rasem, file)
|
70
|
+
File.open(file, "w") do |f|
|
71
|
+
rasem.write(f)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def grid
|
76
|
+
n = 10
|
77
|
+
output = []
|
78
|
+
(width / n).times do |i|
|
79
|
+
x = 1
|
80
|
+
x = 2 if (i % 10 == 0)
|
81
|
+
output << [i * n, 0, i * n, height, 'black', x]
|
82
|
+
end
|
83
|
+
(height / n).times do |i|
|
84
|
+
x = 1
|
85
|
+
x = 2 if i % 10 == 0
|
86
|
+
output << [0, i * n, width, i * n, 'black', x]
|
87
|
+
end
|
88
|
+
output
|
89
|
+
end
|
90
|
+
|
91
|
+
def paragraph_builder(str)
|
92
|
+
self.height = 0
|
93
|
+
arr = str.split("\n")
|
94
|
+
output = []
|
95
|
+
arr.each do |line|
|
96
|
+
output = output + line_builder(line)
|
97
|
+
self.pos_y = self.pos_y + (3 * px)
|
98
|
+
self.pos_x = 0
|
99
|
+
self.height = self.height + (3 * px)
|
100
|
+
end
|
101
|
+
output
|
102
|
+
end
|
103
|
+
|
104
|
+
def line_builder(line)
|
105
|
+
self.width = 0
|
106
|
+
line_output = []
|
107
|
+
|
108
|
+
l = line.split(OPEN_BRACKET)
|
109
|
+
|
110
|
+
l.each do |segment|
|
111
|
+
|
112
|
+
char_data = segment.split("m")
|
113
|
+
|
114
|
+
# if the midpoint doesn't exist
|
115
|
+
if char_data.length == 1
|
116
|
+
char_data[0].chars.each do |char|
|
117
|
+
line_output = line_output + char_builder(char, '#000000')
|
118
|
+
self.pos_x = self.pos_x + (2 * px)
|
119
|
+
self.width = self.width + (2 * px)
|
120
|
+
end
|
121
|
+
else
|
122
|
+
char = char_data[1].delete(CLOSE_BRACKET)
|
123
|
+
line_output = line_output + char_builder(char, HexConverter.ansi_to_hex(char_data[0]))
|
124
|
+
self.pos_x = self.pos_x + (2 * px)
|
125
|
+
self.width = self.width + (2 * px)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
line_output
|
130
|
+
end
|
131
|
+
|
132
|
+
def char_builder(char, hex_str)
|
133
|
+
output = []
|
134
|
+
case char
|
135
|
+
when '.'
|
136
|
+
output << pos_slope_one(1.5 * px, 2.5 * px, px, hex_str)
|
137
|
+
output << neg_slope_one(1.5 * px, 1.5 * px, px, hex_str)
|
138
|
+
when '~'
|
139
|
+
output << pos_slope_one((0 - px / 2), 2.5 * px, px, hex_str)
|
140
|
+
output << neg_slope_one(px / 2, 1.5 * px, px, hex_str)
|
141
|
+
output << pos_slope_one(1.5 * px, 2.5 * px, px, hex_str)
|
142
|
+
when ':'
|
143
|
+
output << pos_slope_one(1.5 * px, 2.5 * px, px, hex_str)
|
144
|
+
output << neg_slope_one(1.5 * px, 1.5 * px, px, hex_str)
|
145
|
+
output << pos_slope_one(1.5 * px, 1.5 * px, px, hex_str)
|
146
|
+
output << neg_slope_one(1.5 * px, px / 2, px, hex_str)
|
147
|
+
when '+'
|
148
|
+
output << vertical_line(1.5 * px, px / 2, 2 * px, hex_str)
|
149
|
+
output << horizontal_line(px / 2, 1.5 * px, 2 * px, hex_str)
|
150
|
+
when '='
|
151
|
+
output << horizontal_line(px / 2, 1.5 * px, 2 * px, hex_str)
|
152
|
+
output << horizontal_line(px / 2, 2.5 * px, 2 * px, hex_str)
|
153
|
+
when 'o'
|
154
|
+
output << pos_slope_one(px / 2, 1.5 * px, px, hex_str)
|
155
|
+
output << neg_slope_one(1.5 * px, px / 2, px, hex_str)
|
156
|
+
output << pos_slope_one(1.5 * px, 2.5 * px, px, hex_str)
|
157
|
+
output << neg_slope_one(px / 2, 1.5 * px, px, hex_str)
|
158
|
+
when '*'
|
159
|
+
output << pos_slope_one(px / 2, 2.5 * px , 2 * px, hex_str)
|
160
|
+
output << neg_slope_one(px / 2, px / 2, 2 * px, hex_str)
|
161
|
+
output << vertical_line(1.5 * px, px / 2, 2 * px, hex_str)
|
162
|
+
when 'x'
|
163
|
+
output << pos_slope_one(px / 2, 2.5 * px , 2 * px, hex_str)
|
164
|
+
output << neg_slope_one(px / 2, px / 2, 2 * px, hex_str)
|
165
|
+
when '^'
|
166
|
+
output << pos_slope_one(px / 2, 1.5 * px, px, hex_str)
|
167
|
+
output << neg_slope_one(1.5 * px, px / 2, px, hex_str)
|
168
|
+
when '%'
|
169
|
+
output << pos_slope_one(px / 2, 1.5 * px, px, hex_str)
|
170
|
+
output << neg_slope_one(px / 2, px / 2, px, hex_str)
|
171
|
+
output << pos_slope_one(px / 2, 2.5 * px, 2 * px, hex_str)
|
172
|
+
output << pos_slope_one(1.5 * px, 2.5 * px, px, hex_str)
|
173
|
+
output << neg_slope_one(1.5 * px, 1.5 * px, px, hex_str)
|
174
|
+
when '#'
|
175
|
+
output << pos_slope_two(px / 2, 2.5 * px, px, hex_str)
|
176
|
+
output << pos_slope_two(1.5 * px, 2.5 * px, px, hex_str)
|
177
|
+
output << horizontal_line(px / 2, 1.5 * px, 2 * px, hex_str)
|
178
|
+
output << horizontal_line(px / 2, 2.5 * px, 2 * px, hex_str)
|
179
|
+
when '@'
|
180
|
+
output << pos_slope_one(1.5 * px, 2.5 * px, px, hex_str)
|
181
|
+
output << neg_slope_one(1.5 * px, 1.5 * px, px, hex_str)
|
182
|
+
output << vertical_line(2.5 * px, px / 2, 2 * px, hex_str)
|
183
|
+
output << horizontal_line(1.5 * px, px / 2, px, hex_str)
|
184
|
+
output << pos_slope_one(px / 2, 1.5 * px, px, hex_str)
|
185
|
+
output << neg_slope_one(px / 2, 1.5 * px, px, hex_str)
|
186
|
+
output << horizontal_line(1.5 * px, 2.5 * px, px, hex_str)
|
187
|
+
when '$'
|
188
|
+
output << horizontal_line(px / 2, px / 2, 2 * px, hex_str)
|
189
|
+
output << neg_slope_one(px / 2, px / 2, 2 * px, hex_str)
|
190
|
+
output << horizontal_line(px / 2, 2.5 * px, 2 * px, hex_str)
|
191
|
+
output << vertical_line(1.5 * px, px / 2, 2 * px, hex_str)
|
192
|
+
when 'M'
|
193
|
+
output << vertical_line(px / 2, px / 2, 2 * px, hex_str)
|
194
|
+
output << neg_slope_one(px / 2, px / 2, px, hex_str)
|
195
|
+
output << pos_slope_one(1.5 * px, 1.5 * px, px, hex_str)
|
196
|
+
output << vertical_line(2.5 * px, px / 2, 2 * px, hex_str)
|
197
|
+
when 'W'
|
198
|
+
output << vertical_line(px / 2, px / 2, 2 * px, hex_str)
|
199
|
+
output << pos_slope_one(px / 2, 2.5 * px, px, hex_str)
|
200
|
+
output << neg_slope_one(1.5 * px, 1.5 * px, px, hex_str)
|
201
|
+
output << vertical_line(2.5 * px, px / 2, 2 * px, hex_str)
|
202
|
+
when '|'
|
203
|
+
output << vertical_line(2.5 * px, px / 2, 2 * px, hex_str)
|
204
|
+
when '-'
|
205
|
+
output << horizontal_line(px / 2, 2.5 * px, 2 * px, hex_str)
|
206
|
+
end
|
207
|
+
output
|
208
|
+
end
|
209
|
+
|
210
|
+
def pos_slope_one(startX, startY, length, hex_str)
|
211
|
+
[
|
212
|
+
startX + pos_x,
|
213
|
+
startY + pos_y,
|
214
|
+
startX + pos_x + length,
|
215
|
+
startY + pos_y - length,
|
216
|
+
hex_str
|
217
|
+
]
|
218
|
+
end
|
219
|
+
|
220
|
+
def neg_slope_one(startX, startY, length, hex_str)
|
221
|
+
[
|
222
|
+
startX + pos_x,
|
223
|
+
startY + pos_y,
|
224
|
+
startX + pos_x + length,
|
225
|
+
startY + pos_y + length,
|
226
|
+
hex_str
|
227
|
+
]
|
228
|
+
end
|
229
|
+
|
230
|
+
def vertical_line(startX, startY, length, hex_str)
|
231
|
+
[
|
232
|
+
startX + pos_x,
|
233
|
+
startY + pos_y,
|
234
|
+
startX + pos_x,
|
235
|
+
startY + pos_y + length,
|
236
|
+
hex_str
|
237
|
+
]
|
238
|
+
end
|
239
|
+
|
240
|
+
def horizontal_line(startX, startY, length, hex_str)
|
241
|
+
[
|
242
|
+
startX + pos_x,
|
243
|
+
startY + pos_y,
|
244
|
+
startX + pos_x + length,
|
245
|
+
startY + pos_y,
|
246
|
+
hex_str
|
247
|
+
]
|
248
|
+
end
|
249
|
+
|
250
|
+
def pos_slope_two(startX, startY, width, hex_str)
|
251
|
+
[
|
252
|
+
startX + pos_x,
|
253
|
+
startY + pos_y,
|
254
|
+
startX + pos_x + width,
|
255
|
+
startY + pos_y - (2 * width),
|
256
|
+
hex_str
|
257
|
+
]
|
258
|
+
end
|
259
|
+
|
260
|
+
def neg_slope_half(startX, startY, height, hex_str)
|
261
|
+
[
|
262
|
+
startX + pos_x,
|
263
|
+
startY + pos_y,
|
264
|
+
startX + pos_x + (2 * height),
|
265
|
+
startY + pos_y + height,
|
266
|
+
hex_str
|
267
|
+
]
|
268
|
+
end
|
269
|
+
|
270
|
+
def neg_slope_two(startX, startY, width, hex_str)
|
271
|
+
[
|
272
|
+
startX + pos_x,
|
273
|
+
startY + pos_y,
|
274
|
+
startX + pos_x + width,
|
275
|
+
startY + pos_y + (2 * width),
|
276
|
+
hex_str
|
277
|
+
]
|
278
|
+
end
|
279
|
+
end
|
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.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ellen Wondra
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - '='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 0.0.9
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: hex256
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.0.1
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.0.1
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rake
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|