stitchify 0.2.6 → 0.4.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 +7 -4
- data/lib/stitchify/draw_rasem.rb +123 -31
- data/lib/stitchify/pixelfy.rb +14 -16
- metadata +20 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa5166b72a59cb8893eb7316050b81c92d733a48
|
4
|
+
data.tar.gz: 917832facf0f22cbb4a72380c37c017332a84f63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5fce45ca8698ba4abe984858892138fc56c893644eb8a79e9e88396e5835c920c85273b332c0a21b8005c131a73069cda9c09f14be886211cc147979f9d3d893
|
7
|
+
data.tar.gz: b1b935d41c642ea5c5bbe789fc9df630b63d9093305d15487dfa82ce5b846826d33dd369cb6aa2a60b5ad52638108b80ee7276b016441b7918ee9fb323e4c384
|
data/lib/stitchify.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
require 'chroma'
|
2
2
|
require 'color'
|
3
3
|
require 'miro'
|
4
|
-
require 'pry'
|
5
4
|
require 'rasem'
|
6
|
-
require '
|
5
|
+
require 'rmagick'
|
7
6
|
|
8
7
|
require 'stitchify/draw_rasem.rb'
|
9
8
|
require 'stitchify/pixelfy.rb'
|
@@ -21,6 +20,8 @@ class Stitchifier
|
|
21
20
|
'triangle',
|
22
21
|
'circle',
|
23
22
|
'diamond',
|
23
|
+
'heart',
|
24
|
+
'star',
|
24
25
|
'reverse_triangle',
|
25
26
|
'left_triangle',
|
26
27
|
'right_triangle'
|
@@ -31,6 +32,7 @@ class Stitchifier
|
|
31
32
|
:dominant_colors,
|
32
33
|
:img,
|
33
34
|
:img_path,
|
35
|
+
:file_path,
|
34
36
|
:num_of_colors,
|
35
37
|
:num_of_off_colors,
|
36
38
|
:pos_x,
|
@@ -39,7 +41,7 @@ class Stitchifier
|
|
39
41
|
:stitch_map,
|
40
42
|
:width
|
41
43
|
|
42
|
-
def initialize(img_path = '', width = 50, px=10, num_of_colors =
|
44
|
+
def initialize(img_path = '', width = 50, px=10, num_of_colors=8, file_path='stitchify.svg')
|
43
45
|
# sets variables
|
44
46
|
self.num_of_colors = num_of_colors
|
45
47
|
set_num_colors
|
@@ -50,6 +52,7 @@ class Stitchifier
|
|
50
52
|
self.stitch_map = []
|
51
53
|
self.px = px
|
52
54
|
self.color_set = nil
|
55
|
+
self.file_path = file_path
|
53
56
|
|
54
57
|
unless img_path.empty?
|
55
58
|
make_img
|
@@ -61,7 +64,7 @@ class Stitchifier
|
|
61
64
|
end
|
62
65
|
|
63
66
|
def stitch
|
64
|
-
d = DrawRasem.new(self.stitch_map, self.width, self.px, self.color_set)
|
67
|
+
d = DrawRasem.new(self.stitch_map, self.width, self.px, self.color_set, self.file_path)
|
65
68
|
d.stitch
|
66
69
|
end
|
67
70
|
|
data/lib/stitchify/draw_rasem.rb
CHANGED
@@ -1,17 +1,25 @@
|
|
1
1
|
class DrawRasem
|
2
2
|
|
3
|
-
attr_accessor
|
3
|
+
attr_accessor :color_set,
|
4
|
+
:file_path,
|
5
|
+
:height,
|
6
|
+
:pos_x,
|
7
|
+
:pos_y,
|
8
|
+
:px,
|
9
|
+
:px_arr,
|
10
|
+
:width
|
4
11
|
|
5
|
-
def initialize(px_arr, width=50, px=10, color_set=[])
|
12
|
+
def initialize(px_arr, width=50, px=10, color_set=[], file_path='stitchify.svg')
|
6
13
|
self.px_arr = px_arr
|
7
14
|
self.width = width
|
8
15
|
self.px = px
|
9
16
|
self.color_set = color_set
|
17
|
+
self.file_path = file_path
|
10
18
|
clear_vars
|
11
19
|
end
|
12
20
|
|
13
21
|
def stitch
|
14
|
-
write(build_rasem_data,
|
22
|
+
write(build_rasem_data, self.file_path)
|
15
23
|
clear_vars
|
16
24
|
end
|
17
25
|
|
@@ -31,42 +39,126 @@ class DrawRasem
|
|
31
39
|
rasem_obj = self
|
32
40
|
|
33
41
|
Rasem::SVGImage.new(width: 1000000000, height: 100000000) do
|
42
|
+
pos_x = rasem_obj.pos_x
|
43
|
+
pos_y = rasem_obj.pos_y
|
44
|
+
px = rasem_obj.px
|
45
|
+
a = px / 4
|
46
|
+
b = px / 2
|
47
|
+
c = px - a
|
48
|
+
d = a / 2
|
34
49
|
|
35
|
-
|
36
|
-
|
37
|
-
|
50
|
+
defs do
|
51
|
+
group(id: 'rectangle') do
|
52
|
+
rectangle pos_x, pos_y, px, px
|
53
|
+
end
|
38
54
|
|
39
|
-
|
40
|
-
pos_x = rasem_obj.pos_x
|
41
|
-
pos_y = rasem_obj.pos_y
|
42
|
-
px = rasem_obj.px
|
43
|
-
|
44
|
-
case pixel.shape
|
45
|
-
when 'rectangle'
|
46
|
-
rectangle pos_x, pos_y, px, px, fill: pixel.hex
|
47
|
-
when 'x'
|
55
|
+
group(id: 'x') do
|
48
56
|
line pos_x, pos_y, pos_x + px, pos_y + px
|
49
57
|
line pos_x, pos_y + px, pos_x + px, pos_y
|
50
|
-
when 'circle'
|
51
|
-
circle (pos_x + px/2), (pos_y + px/2), px / 2 - 1, fill: pixel.hex
|
52
|
-
when 'sm_rectangle'
|
53
|
-
rectangle pos_x + 1, pos_y + 1, px - 2, px - 2, fill: pixel.hex
|
54
|
-
when 'triangle'
|
55
|
-
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
|
56
|
-
when 'diamond'
|
57
|
-
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
|
58
|
-
when 'reverse_triangle'
|
59
|
-
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
|
60
|
-
when 'left_triangle'
|
61
|
-
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
|
62
|
-
when 'right_triangle'
|
63
|
-
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
|
64
|
-
else
|
65
|
-
rectangle pos_x, pos_y, px, px, fill: pixel.hex
|
66
58
|
end
|
67
59
|
|
60
|
+
group(id: 'circle') do
|
61
|
+
circle (pos_x + b), (pos_y + b), a + d
|
62
|
+
end
|
63
|
+
|
64
|
+
group(id: 'sm_rectangle') do
|
65
|
+
rectangle pos_x + a + 1, pos_y + a + 1, b, b
|
66
|
+
end
|
67
|
+
|
68
|
+
group(id: 'triangle') do
|
69
|
+
polygon [pos_x + b, pos_y + a],
|
70
|
+
[pos_x + c, pos_y + c],
|
71
|
+
[pos_x + a, pos_y + c]
|
72
|
+
end
|
73
|
+
|
74
|
+
group(id: 'diamond') do
|
75
|
+
polygon [pos_x + b, pos_y + 1],
|
76
|
+
[pos_x + 1, pos_y + b],
|
77
|
+
[pos_x + b, pos_y + px - 1],
|
78
|
+
[pos_x + px - 1, pos_y + b]
|
79
|
+
end
|
80
|
+
|
81
|
+
group(id: 'reverse_triangle') do
|
82
|
+
polygon [pos_x + a, pos_y + a],
|
83
|
+
[pos_x + c, pos_y + a],
|
84
|
+
[pos_x + b, pos_y + c]
|
85
|
+
end
|
86
|
+
|
87
|
+
group(id: 'left_triangle') do
|
88
|
+
polygon [pos_x + a, pos_y + b],
|
89
|
+
[pos_x + c, pos_y + a],
|
90
|
+
[pos_x + c, pos_y + c]
|
91
|
+
end
|
92
|
+
|
93
|
+
group(id: 'right_triangle') do
|
94
|
+
polygon [pos_x + a, pos_y + a],
|
95
|
+
[pos_x + c, pos_y + b],
|
96
|
+
[pos_x + a, pos_y + c]
|
97
|
+
end
|
98
|
+
|
99
|
+
group(id: 'star') do
|
100
|
+
polygon [pos_x + a + 1, pos_y + 1],
|
101
|
+
[pos_x + b, pos_y + a + 1],
|
102
|
+
[pos_x + c - 1, pos_y + 1],
|
103
|
+
[pos_x + c - 1, pos_y + a + 1],
|
104
|
+
[pos_x + px - 1, pos_y + a + 1],
|
105
|
+
[pos_x + c - 1, pos_y + b],
|
106
|
+
[pos_x + px - 1, pos_y + c - 1],
|
107
|
+
[pos_x + c - 1, pos_y + c - 1],
|
108
|
+
[pos_x + c - 1, pos_y + px - 1],
|
109
|
+
[pos_x + b, pos_y + c - 1],
|
110
|
+
[pos_x + a + 1, pos_y + px - 1],
|
111
|
+
[pos_x + a + 1, pos_y + c - 1],
|
112
|
+
[pos_x + 1, pos_y + c - 1],
|
113
|
+
[pos_x + a + 1, pos_y + b],
|
114
|
+
[pos_x + 1, pos_y + a + 1],
|
115
|
+
[pos_x + a + 1, pos_y + a + 1],
|
116
|
+
[pos_x + a + 1, pos_y + 1]
|
117
|
+
end
|
118
|
+
|
119
|
+
group(id: 'heart') do
|
120
|
+
polygon [pos_x + a, pos_y + a],
|
121
|
+
[pos_x + b - d, pos_y + a],
|
122
|
+
[pos_x + b, pos_y + b - d],
|
123
|
+
[pos_x + b + d, pos_y + a],
|
124
|
+
[pos_x + c, pos_y + a],
|
125
|
+
[pos_x + c, pos_y + b],
|
126
|
+
[pos_x + b, pos_y + c],
|
127
|
+
[pos_x + a, pos_y + b]
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
# grid
|
132
|
+
group stroke: 'black' do
|
133
|
+
for line_data in rasem_obj.grid
|
134
|
+
line line_data[0], line_data[1], line_data[2], line_data[3], :stroke_width=>line_data[5]
|
135
|
+
end
|
136
|
+
|
137
|
+
blocks = rasem_obj.width / 10
|
138
|
+
blocks.times do |i|
|
139
|
+
text((i + 1) * 10 * px + b, c, stroke_width: 1, 'font-size': '8px', class: 'grid-numbers') { raw (i + 1) * 10 }
|
140
|
+
text(1, (i + 1) * 10 * px + px + a, stroke_width: 1, 'font-size': '8px', class: 'grid-numbers') { raw (i + 1) * 10 }
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
# content
|
145
|
+
for pixel in rasem_obj.px_arr
|
146
|
+
use(pixel.shape, x: rasem_obj.pos_x - px, y: rasem_obj.pos_y - px, fill: pixel.hex)
|
68
147
|
rasem_obj.update_positions
|
69
148
|
end
|
149
|
+
|
150
|
+
# legend
|
151
|
+
group stroke: 'black' do
|
152
|
+
legend_pos_x = (rasem_obj.width + 2) * px
|
153
|
+
legend_pos_y = 2 * px
|
154
|
+
legend_height = px * (rasem_obj.color_set.length * 2)
|
155
|
+
rectangle legend_pos_x, legend_pos_y, 10 * px, legend_height, fill: 'white'
|
156
|
+
rasem_obj.color_set.each_with_index do |pixel, index|
|
157
|
+
use(pixel.shape, x: legend_pos_x - b, y: legend_pos_y - b, fill: pixel.hex)
|
158
|
+
text(legend_pos_x + 2 * px, legend_pos_y + px + b) { raw pixel.hex }
|
159
|
+
legend_pos_y += 2 * px
|
160
|
+
end
|
161
|
+
end
|
70
162
|
end
|
71
163
|
end
|
72
164
|
|
data/lib/stitchify/pixelfy.rb
CHANGED
@@ -39,26 +39,24 @@ class Pixelfy
|
|
39
39
|
"#{HSL_OPEN_CONST} #{self.hue}, #{self.saturation}%, #{self.lightness}%, 1)"
|
40
40
|
end
|
41
41
|
|
42
|
+
def name
|
43
|
+
n = ''
|
44
|
+
c = Chroma::Color.new(hsl).to_name
|
45
|
+
n = c unless c == "<unknown>"
|
46
|
+
|
47
|
+
end
|
48
|
+
|
42
49
|
def colorize(map)
|
43
50
|
deltae = 100000000000
|
44
51
|
closest_px = map[0]
|
45
52
|
|
46
53
|
map.each do |dom_px|
|
47
|
-
|
48
|
-
|
49
|
-
if
|
50
|
-
|
51
|
-
|
52
|
-
|
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
|
54
|
+
dom_px_delta = self.get_delta_e(dom_px)
|
55
|
+
current_px_delta = self.get_delta_e(closest_px)
|
56
|
+
if dom_px_delta < current_px_delta
|
57
|
+
deltae = dom_px_delta
|
58
|
+
closest_px = dom_px
|
59
|
+
end
|
62
60
|
end
|
63
61
|
|
64
62
|
self.hue = closest_px.hue
|
@@ -69,7 +67,7 @@ class Pixelfy
|
|
69
67
|
self
|
70
68
|
end
|
71
69
|
|
72
|
-
def
|
70
|
+
def get_delta_e(px)
|
73
71
|
hue_delta = (px.hue - self.hue).abs
|
74
72
|
sat_delta = (px.saturation - self.saturation).abs
|
75
73
|
lit_delta = (px.lightness - self.lightness).abs
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stitchify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ellen Wondra
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rasem
|
@@ -56,60 +56,60 @@ dependencies:
|
|
56
56
|
name: chroma
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - '='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 0.2.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:
|
68
|
+
version: 0.2.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rmagick
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '2.16'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '2.16'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rake
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - '='
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: 12.3.1
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - '='
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: 12.3.1
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: pry
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - '='
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
103
|
+
version: 0.11.3
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - '='
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
111
|
-
description:
|
112
|
-
|
110
|
+
version: 0.11.3
|
111
|
+
description: takes a .jpg image and converts it to an SVG cross stitching pattern.
|
112
|
+
You can change the colors, the width, and the number of colors used.
|
113
113
|
email: ellenfromillinois@gmail.com
|
114
114
|
executables: []
|
115
115
|
extensions: []
|