stitchify 0.1.3 → 0.2.4
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 +158 -287
- data/lib/stitchify/draw_rasem.rb +96 -0
- data/lib/stitchify/pixelfy.rb +79 -0
- metadata +35 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7566ac54885d62ccd4d9da595890b392e6d60b9e
|
4
|
+
data.tar.gz: c7036ec503541d34cdef582cb3b72911a072169b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2f411cfa0219988b2187b8cd1b831c2df4748e111457657689acca81ecf5229daf49614aea2e2d4f8256ff91a43da721d4b86bec836d1dda7b951de19dd7efd
|
7
|
+
data.tar.gz: 57ba44e163b9c1f65ef02e9f15fb49eedf4b771c1e5d54c201da10fae01ef6e64e727dc3e17acaa35ce335a89908ef01f4de01dc6667c93669ee96502aead611
|
data/lib/stitchify.rb
CHANGED
@@ -1,287 +1,158 @@
|
|
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
|
-
|
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
|
-
end
|
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
|
-
output << horizontal_line(px / 2, 1.5 * px, 2 * px, hex_str)
|
160
|
-
output << horizontal_line(px / 2, 2.5 * px, 2 * px, hex_str)
|
161
|
-
when 'o'
|
162
|
-
output << pos_slope_one(px / 2, 1.5 * px, px, hex_str)
|
163
|
-
output << neg_slope_one(1.5 * px, px / 2, px, hex_str)
|
164
|
-
output << pos_slope_one(1.5 * px, 2.5 * px, px, hex_str)
|
165
|
-
output << neg_slope_one(px / 2, 1.5 * px, px, hex_str)
|
166
|
-
when '*'
|
167
|
-
output << pos_slope_one(px / 2, 2.5 * px , 2 * px, hex_str)
|
168
|
-
output << neg_slope_one(px / 2, px / 2, 2 * px, hex_str)
|
169
|
-
output << vertical_line(1.5 * px, px / 2, 2 * px, hex_str)
|
170
|
-
when 'x'
|
171
|
-
output << pos_slope_one(px / 2, 2.5 * px , 2 * px, hex_str)
|
172
|
-
output << neg_slope_one(px / 2, px / 2, 2 * px, hex_str)
|
173
|
-
when '^'
|
174
|
-
output << pos_slope_one(px / 2, 1.5 * px, px, hex_str)
|
175
|
-
output << neg_slope_one(1.5 * px, px / 2, px, hex_str)
|
176
|
-
when '%'
|
177
|
-
output << pos_slope_one(px / 2, 1.5 * px, px, hex_str)
|
178
|
-
output << neg_slope_one(px / 2, px / 2, px, hex_str)
|
179
|
-
output << pos_slope_one(px / 2, 2.5 * px, 2 * px, hex_str)
|
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
|
-
when '#'
|
183
|
-
output << pos_slope_two(px / 2, 2.5 * px, px, hex_str)
|
184
|
-
output << pos_slope_two(1.5 * px, 2.5 * px, px, hex_str)
|
185
|
-
output << horizontal_line(px / 2, 1.5 * px, 2 * px, hex_str)
|
186
|
-
output << horizontal_line(px / 2, 2.5 * px, 2 * px, hex_str)
|
187
|
-
when '@'
|
188
|
-
output << pos_slope_one(1.5 * px, 2.5 * px, px, hex_str)
|
189
|
-
output << neg_slope_one(1.5 * px, 1.5 * px, px, hex_str)
|
190
|
-
output << vertical_line(2.5 * px, px / 2, 2 * px, hex_str)
|
191
|
-
output << horizontal_line(1.5 * px, px / 2, px, hex_str)
|
192
|
-
output << pos_slope_one(px / 2, 1.5 * px, px, hex_str)
|
193
|
-
output << neg_slope_one(px / 2, 1.5 * px, px, hex_str)
|
194
|
-
output << horizontal_line(1.5 * px, 2.5 * px, px, hex_str)
|
195
|
-
when '$'
|
196
|
-
output << horizontal_line(px / 2, px / 2, 2 * px, hex_str)
|
197
|
-
output << neg_slope_one(px / 2, px / 2, 2 * px, hex_str)
|
198
|
-
output << horizontal_line(px / 2, 2.5 * px, 2 * px, hex_str)
|
199
|
-
output << vertical_line(1.5 * px, px / 2, 2 * px, hex_str)
|
200
|
-
when 'M'
|
201
|
-
output << vertical_line(px / 2, px / 2, 2 * px, hex_str)
|
202
|
-
output << neg_slope_one(px / 2, px / 2, px, hex_str)
|
203
|
-
output << pos_slope_one(1.5 * px, 1.5 * px, px, hex_str)
|
204
|
-
output << vertical_line(2.5 * px, px / 2, 2 * px, hex_str)
|
205
|
-
when 'W'
|
206
|
-
output << vertical_line(px / 2, px / 2, 2 * px, hex_str)
|
207
|
-
output << pos_slope_one(px / 2, 2.5 * px, px, hex_str)
|
208
|
-
output << neg_slope_one(1.5 * px, 1.5 * px, px, hex_str)
|
209
|
-
output << vertical_line(2.5 * px, px / 2, 2 * px, hex_str)
|
210
|
-
when '|'
|
211
|
-
output << vertical_line(2.5 * px, px / 2, 2 * px, hex_str)
|
212
|
-
when '-'
|
213
|
-
output << horizontal_line(px / 2, 2.5 * px, 2 * px, hex_str)
|
214
|
-
end
|
215
|
-
output
|
216
|
-
end
|
217
|
-
|
218
|
-
def pos_slope_one(startX, startY, length, hex_str)
|
219
|
-
[
|
220
|
-
startX + pos_x,
|
221
|
-
startY + pos_y,
|
222
|
-
startX + pos_x + length,
|
223
|
-
startY + pos_y - length,
|
224
|
-
hex_str
|
225
|
-
]
|
226
|
-
end
|
227
|
-
|
228
|
-
def neg_slope_one(startX, startY, length, hex_str)
|
229
|
-
[
|
230
|
-
startX + pos_x,
|
231
|
-
startY + pos_y,
|
232
|
-
startX + pos_x + length,
|
233
|
-
startY + pos_y + length,
|
234
|
-
hex_str
|
235
|
-
]
|
236
|
-
end
|
237
|
-
|
238
|
-
def vertical_line(startX, startY, length, hex_str)
|
239
|
-
[
|
240
|
-
startX + pos_x,
|
241
|
-
startY + pos_y,
|
242
|
-
startX + pos_x,
|
243
|
-
startY + pos_y + length,
|
244
|
-
hex_str
|
245
|
-
]
|
246
|
-
end
|
247
|
-
|
248
|
-
def horizontal_line(startX, startY, length, hex_str)
|
249
|
-
[
|
250
|
-
startX + pos_x,
|
251
|
-
startY + pos_y,
|
252
|
-
startX + pos_x + length,
|
253
|
-
startY + pos_y,
|
254
|
-
hex_str
|
255
|
-
]
|
256
|
-
end
|
257
|
-
|
258
|
-
def pos_slope_two(startX, startY, width, hex_str)
|
259
|
-
[
|
260
|
-
startX + pos_x,
|
261
|
-
startY + pos_y,
|
262
|
-
startX + pos_x + width,
|
263
|
-
startY + pos_y - (2 * width),
|
264
|
-
hex_str
|
265
|
-
]
|
266
|
-
end
|
267
|
-
|
268
|
-
def neg_slope_half(startX, startY, height, hex_str)
|
269
|
-
[
|
270
|
-
startX + pos_x,
|
271
|
-
startY + pos_y,
|
272
|
-
startX + pos_x + (2 * height),
|
273
|
-
startY + pos_y + height,
|
274
|
-
hex_str
|
275
|
-
]
|
276
|
-
end
|
277
|
-
|
278
|
-
def neg_slope_two(startX, startY, width, hex_str)
|
279
|
-
[
|
280
|
-
startX + pos_x,
|
281
|
-
startY + pos_y,
|
282
|
-
startX + pos_x + width,
|
283
|
-
startY + pos_y + (2 * width),
|
284
|
-
hex_str
|
285
|
-
]
|
286
|
-
end
|
287
|
-
end
|
1
|
+
require 'chroma'
|
2
|
+
require 'color'
|
3
|
+
require 'miro'
|
4
|
+
require 'pry'
|
5
|
+
require 'rasem'
|
6
|
+
require 'RMagick'
|
7
|
+
|
8
|
+
require 'stitchify/draw_rasem.rb'
|
9
|
+
require 'stitchify/pixelfy.rb'
|
10
|
+
|
11
|
+
class Stitchifier
|
12
|
+
include Chroma
|
13
|
+
include Magick
|
14
|
+
include Miro
|
15
|
+
|
16
|
+
HSLA_BLACK = [0, 0, 0, 1]
|
17
|
+
HSLA_WHITE = [0, 0, 100, 1]
|
18
|
+
HSL_OPEN_CONST = "hsl("
|
19
|
+
FILLABLE_SHAPES = [
|
20
|
+
'sm_rectangle',
|
21
|
+
'triangle',
|
22
|
+
'circle',
|
23
|
+
'diamond',
|
24
|
+
'reverse_triangle',
|
25
|
+
'left_triangle',
|
26
|
+
'right_triangle'
|
27
|
+
]
|
28
|
+
|
29
|
+
attr_accessor :base_pixel_arr,
|
30
|
+
:dominant_colors,
|
31
|
+
:img,
|
32
|
+
:img_path,
|
33
|
+
:num_of_colors,
|
34
|
+
:num_of_off_colors,
|
35
|
+
:pos_x,
|
36
|
+
:pos_y,
|
37
|
+
:px,
|
38
|
+
:stitch_map,
|
39
|
+
:width
|
40
|
+
|
41
|
+
def initialize(img_path = '', width = 50, px=10, num_of_colors = 8)
|
42
|
+
# sets variables
|
43
|
+
self.num_of_colors = num_of_colors
|
44
|
+
set_num_colors
|
45
|
+
self.width = width
|
46
|
+
self.num_of_colors = num_of_colors
|
47
|
+
self.img_path = img_path
|
48
|
+
self.dominant_colors = []
|
49
|
+
self.stitch_map = []
|
50
|
+
self.px = px
|
51
|
+
|
52
|
+
unless img_path.empty?
|
53
|
+
make_img
|
54
|
+
set_dominant_colors
|
55
|
+
build_pixel_array
|
56
|
+
|
57
|
+
d = DrawRasem.new(self.stitch_map, self.width, self.px)
|
58
|
+
d.stitch
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def make_img
|
63
|
+
self.img = ImageList.new(img_path).resize_to_fit(width)
|
64
|
+
end
|
65
|
+
|
66
|
+
def set_dominant_colors
|
67
|
+
color_pos = 0
|
68
|
+
colors = black_and_white
|
69
|
+
set_num_colors
|
70
|
+
if self.num_of_colors > 3 && !img_path.empty?
|
71
|
+
miro_data = Miro::DominantColors.new(self.img_path).to_hex unless self.img_path.empty?
|
72
|
+
main_color = miro_data.slice!(0, 1)[0]
|
73
|
+
miro_px = miro_data.map{|x| Pixelfy.from_hex(x)}
|
74
|
+
off_colors = build_off_color_arr(main_color)
|
75
|
+
colors = miro_px + off_colors + colors
|
76
|
+
end
|
77
|
+
colors.each do |px|
|
78
|
+
if px.shape.nil?
|
79
|
+
px.shape = FILLABLE_SHAPES[color_pos]
|
80
|
+
color_pos = (color_pos + 1) % FILLABLE_SHAPES.length
|
81
|
+
end
|
82
|
+
end
|
83
|
+
self.dominant_colors = colors.uniq
|
84
|
+
end
|
85
|
+
|
86
|
+
def black_and_white
|
87
|
+
[Pixelfy.new(0, 0, 0, 'x'), Pixelfy.new(0, 0, 100, 'circle')]
|
88
|
+
end
|
89
|
+
|
90
|
+
def build_pixel_array
|
91
|
+
get_pixels
|
92
|
+
colorize_pixels
|
93
|
+
end
|
94
|
+
|
95
|
+
def get_pixels
|
96
|
+
px = []
|
97
|
+
|
98
|
+
unless self.img.nil?
|
99
|
+
self.img.each_pixel do | pixel, col, row |
|
100
|
+
pixel = pixel.to_hsla
|
101
|
+
px << Pixelfy.new(pixel[0], pixel[1], pixel[2])
|
102
|
+
end
|
103
|
+
end
|
104
|
+
self.base_pixel_arr = px
|
105
|
+
end
|
106
|
+
|
107
|
+
def colorize_pixels
|
108
|
+
self.base_pixel_arr.each {|px| self.stitch_map << px.colorize(self.dominant_colors) }
|
109
|
+
end
|
110
|
+
|
111
|
+
def set_num_colors
|
112
|
+
num = self.num_of_colors - 2
|
113
|
+
case num
|
114
|
+
when 1
|
115
|
+
set_miro(1, 0)
|
116
|
+
when 2
|
117
|
+
set_miro(1, 1)
|
118
|
+
when 3
|
119
|
+
set_miro(2, 1)
|
120
|
+
when 4
|
121
|
+
set_miro(2, 2)
|
122
|
+
when 5
|
123
|
+
set_miro(3, 2)
|
124
|
+
when 6
|
125
|
+
set_miro(3, 3)
|
126
|
+
else
|
127
|
+
set_miro(num - 3, 3)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def set_miro(cc, off_c)
|
132
|
+
Miro.options[:color_count] = cc
|
133
|
+
self.num_of_off_colors = off_c
|
134
|
+
end
|
135
|
+
|
136
|
+
def build_off_color_arr(color)
|
137
|
+
palette = []
|
138
|
+
if !!color
|
139
|
+
c = Chroma::Color.new(color)
|
140
|
+
palette = c.palette
|
141
|
+
case self.num_of_off_colors
|
142
|
+
when 0
|
143
|
+
palette = []
|
144
|
+
when 1
|
145
|
+
palette = palette.complement.map{|x| Pixelfy.from_hex(x.to_s)}
|
146
|
+
when 2
|
147
|
+
palette = palette.triad.map{|x| Pixelfy.from_hex(x.to_s)}
|
148
|
+
when 3
|
149
|
+
palette = palette.tetrad.map{|x| Pixelfy.from_hex(x.to_s)}
|
150
|
+
end
|
151
|
+
end
|
152
|
+
palette
|
153
|
+
end
|
154
|
+
|
155
|
+
def view_miro_opts
|
156
|
+
Miro.options
|
157
|
+
end
|
158
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
class DrawRasem
|
2
|
+
|
3
|
+
attr_accessor :px_arr, :width, :px, :pos_x, :pos_y, :height
|
4
|
+
|
5
|
+
def initialize(px_arr, width=50, px=10)
|
6
|
+
self.px_arr = px_arr
|
7
|
+
self.width = width
|
8
|
+
self.px = px
|
9
|
+
clear_vars
|
10
|
+
end
|
11
|
+
|
12
|
+
def stitch
|
13
|
+
write(build_rasem_data, file='stitchify.svg')
|
14
|
+
clear_vars
|
15
|
+
end
|
16
|
+
|
17
|
+
def clear_vars
|
18
|
+
self.pos_x = self.px
|
19
|
+
self.pos_y = self.px
|
20
|
+
end
|
21
|
+
|
22
|
+
def write(rasem, file)
|
23
|
+
File.open(file, "w") do |f|
|
24
|
+
rasem.write(f)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
def build_rasem_data
|
30
|
+
rasem_obj = self
|
31
|
+
|
32
|
+
Rasem::SVGImage.new(width: 1000000000, height: 100000000) do
|
33
|
+
|
34
|
+
for line_data in rasem_obj.grid
|
35
|
+
line line_data[0], line_data[1], line_data[2], line_data[3], :stroke_width=>line_data[5]
|
36
|
+
end
|
37
|
+
|
38
|
+
for pixel in rasem_obj.px_arr
|
39
|
+
pos_x = rasem_obj.pos_x
|
40
|
+
pos_y = rasem_obj.pos_y
|
41
|
+
px = rasem_obj.px
|
42
|
+
|
43
|
+
case pixel.shape
|
44
|
+
when 'rectangle'
|
45
|
+
rectangle pos_x, pos_y, px, px, fill: pixel.hex
|
46
|
+
when 'x'
|
47
|
+
line pos_x, pos_y, pos_x + px, pos_y + px
|
48
|
+
line pos_x, pos_y + px, pos_x + px, pos_y
|
49
|
+
when 'circle'
|
50
|
+
circle (pos_x + px/2), (pos_y + px/2), px / 2 - 1, fill: pixel.hex
|
51
|
+
when 'sm_rectangle'
|
52
|
+
rectangle pos_x + 1, pos_y + 1, px - 2, px - 2, fill: pixel.hex
|
53
|
+
when 'triangle'
|
54
|
+
polygon [pos_x + px/2, pos_y + 1], [pos_x + 1, pos_y + px - 1], [pos_x + px - 1, pos_y + px - 1], fill: pixel.hex
|
55
|
+
when 'diamond'
|
56
|
+
polygon [pos_x + px/2, pos_y + 1], [pos_x + 1, pos_y + px/2], [pos_x + px/2, pos_y + px - 1], [pos_x + px - 1, pos_y + px/2], fill: pixel.hex
|
57
|
+
when 'reverse_triangle'
|
58
|
+
polygon [pos_x + px/2, pos_y + px - 1], [pos_x + 1, pos_y + 1], [pos_x + px - 1, pos_y + 1], fill: pixel.hex
|
59
|
+
when 'left_triangle'
|
60
|
+
polygon [pos_x + 1, pos_y + px/2], [pos_x + px - 1, pos_y + 1], [pos_x + px - 1, pos_y + px - 1], fill: pixel.hex
|
61
|
+
when 'right_triangle'
|
62
|
+
polygon [pos_x + px - 1, pos_y + px/2], [pos_x + 1, pos_y + 1], [pos_x + 1, pos_y + px - 1], fill: pixel.hex
|
63
|
+
else
|
64
|
+
rectangle pos_x, pos_y, px, px, fill: pixel.hex
|
65
|
+
end
|
66
|
+
|
67
|
+
rasem_obj.update_positions
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def grid
|
73
|
+
n = 10
|
74
|
+
output = []
|
75
|
+
(self.width + 1).times do |i|
|
76
|
+
x = 1
|
77
|
+
x = 2 if (i % 10 == 0)
|
78
|
+
output << [(i + 1) * self.px, self.px, (i + 1) * self.px, (self.width + 1) * self.px, 'black', x]
|
79
|
+
end
|
80
|
+
(self.width + 1).times do |i|
|
81
|
+
x = 1
|
82
|
+
x = 2 if i % 10 == 0
|
83
|
+
output << [self.px, (i + 1) * self.px, (self.width + 1) * self.px, (i + 1) * self.px, 'black', x]
|
84
|
+
end
|
85
|
+
output
|
86
|
+
end
|
87
|
+
|
88
|
+
def update_positions
|
89
|
+
if (self.pos_x / self.px) < self.width
|
90
|
+
self.pos_x = self.pos_x + self.px
|
91
|
+
else
|
92
|
+
self.pos_x = self.px
|
93
|
+
self.pos_y = self.pos_y + self.px
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
class Pixelfy
|
2
|
+
require 'chroma'
|
3
|
+
include Chroma
|
4
|
+
|
5
|
+
attr_accessor :hue, :saturation, :lightness, :shape
|
6
|
+
|
7
|
+
HSL_OPEN_CONST = "hsl("
|
8
|
+
|
9
|
+
def initialize(hue, saturation, lightness, shape=nil)
|
10
|
+
self.hue = hue
|
11
|
+
self.saturation = saturation
|
12
|
+
self.lightness = lightness
|
13
|
+
self.shape = shape
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.from_hex(hex_str)
|
17
|
+
px = ''
|
18
|
+
if hex_str
|
19
|
+
color_str = Chroma::Color.new(hex_str).to_hsl
|
20
|
+
color_str.slice!(HSL_OPEN_CONST)
|
21
|
+
color_str.slice!("%)")
|
22
|
+
color_str.slice!('%')
|
23
|
+
color_arr = color_str.split(', ')
|
24
|
+
|
25
|
+
px = self.new(color_arr[0].to_i, color_arr[1].to_i, color_arr[2].to_i)
|
26
|
+
end
|
27
|
+
px
|
28
|
+
end
|
29
|
+
|
30
|
+
def hex
|
31
|
+
Chroma::Color.new(hsl).to_hex
|
32
|
+
end
|
33
|
+
|
34
|
+
def hsl
|
35
|
+
"#{HSL_OPEN_CONST} #{self.hue}, #{self.saturation}%, #{self.lightness}%)"
|
36
|
+
end
|
37
|
+
|
38
|
+
def hsla
|
39
|
+
"#{HSL_OPEN_CONST} #{self.hue}, #{self.saturation}%, #{self.lightness}%, 1)"
|
40
|
+
end
|
41
|
+
|
42
|
+
def colorize(map)
|
43
|
+
deltae = 100000000000
|
44
|
+
closest_px = map[0]
|
45
|
+
|
46
|
+
map.each do |dom_px|
|
47
|
+
hue_delta = (dom_px.hue - self.hue).abs
|
48
|
+
|
49
|
+
if hue_delta < deltae
|
50
|
+
|
51
|
+
deltae = hue_delta
|
52
|
+
closest_px = dom_px
|
53
|
+
|
54
|
+
elsif hue_delta == deltae
|
55
|
+
dom_px_delta = self.get_full_delta(dom_px)
|
56
|
+
current_px_delta = self.get_full_delta(closest_px)
|
57
|
+
if dom_px_delta < current_px_delta
|
58
|
+
deltae = hue_delta
|
59
|
+
closest_px = dom_px
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
self.hue = closest_px.hue
|
65
|
+
self.saturation = closest_px.saturation
|
66
|
+
self.lightness = closest_px.lightness
|
67
|
+
self.shape = closest_px.shape
|
68
|
+
|
69
|
+
self
|
70
|
+
end
|
71
|
+
|
72
|
+
def get_full_delta(px)
|
73
|
+
hue_delta = (px.hue - self.hue).abs
|
74
|
+
sat_delta = (px.saturation - self.saturation).abs
|
75
|
+
lit_delta = (px.lightness - self.lightness).abs
|
76
|
+
|
77
|
+
hue_delta + sat_delta + lit_delta
|
78
|
+
end
|
79
|
+
end
|
metadata
CHANGED
@@ -1,71 +1,85 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stitchify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ellen Wondra
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: rasem
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.7.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 0.7.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: miro
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - '='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
33
|
+
version: 0.4.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.
|
40
|
+
version: 0.4.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: color
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - '='
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: '1.8'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - '='
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: '1.8'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: chroma
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0
|
61
|
+
version: '0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rmagick
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rake
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,13 +108,16 @@ dependencies:
|
|
94
108
|
- - ">="
|
95
109
|
- !ruby/object:Gem::Version
|
96
110
|
version: '0'
|
97
|
-
description: input an HTML document and output an SVG cross stitching
|
111
|
+
description: ultimate goal is to input an HTML document and output an SVG cross stitching
|
112
|
+
pattern
|
98
113
|
email: ellenfromillinois@gmail.com
|
99
114
|
executables: []
|
100
115
|
extensions: []
|
101
116
|
extra_rdoc_files: []
|
102
117
|
files:
|
103
118
|
- lib/stitchify.rb
|
119
|
+
- lib/stitchify/draw_rasem.rb
|
120
|
+
- lib/stitchify/pixelfy.rb
|
104
121
|
homepage: http://rubygems.org/gems/stitchify
|
105
122
|
licenses:
|
106
123
|
- MIT
|
@@ -124,5 +141,5 @@ rubyforge_project:
|
|
124
141
|
rubygems_version: 2.6.14
|
125
142
|
signing_key:
|
126
143
|
specification_version: 4
|
127
|
-
summary: converts an
|
144
|
+
summary: converts an image into a cross stitching pattern
|
128
145
|
test_files: []
|