stitchify 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e5895de25d1f7278da3b3f19429bc973bdc25d7b
4
- data.tar.gz: ffbae7c51bff3f8313bbc37e5b39604d5d796c75
3
+ metadata.gz: 163c7b301bb8c593d7776451c1b6301d779431b9
4
+ data.tar.gz: 10c75dc399cad95003d8410e17b600dcb3d3a3bb
5
5
  SHA512:
6
- metadata.gz: 87b63def2fbc5aa49d24af785ecf1886c46a0728f27cd2f86d72760b5e09d6bb3da8b411b53c50a0e7d360f6c66e093c5ccab173d6be27725c137b7e7a57ebac
7
- data.tar.gz: 3538d477176f23a093161495db5abfef06bd7bc86f1ac635e68ee9add3ee4a3e16ceb58a250918037f09001cebc25fb4984821fddd3e771886567fd625a7be44
6
+ metadata.gz: 1265812071e71ab6a4c4a91fb0b7276985114b62d79dd7e20e3e4c0a0760d0f5d6a945dcf8ba086e9842fc941e11ae12811bc8ce0c31ae2aee42216aa8092bf6
7
+ data.tar.gz: 9d8431825fa940807b0b48bff170701cec914885369a858edfdc4a85546260a422bc644d06230cba02ee3001548093c073cd74dcdc0fa62a746d8f315482eaa8
@@ -27,6 +27,7 @@ class Stitchifier
27
27
  ]
28
28
 
29
29
  attr_accessor :base_pixel_arr,
30
+ :color_set,
30
31
  :dominant_colors,
31
32
  :img,
32
33
  :img_path,
@@ -48,23 +49,27 @@ class Stitchifier
48
49
  self.dominant_colors = []
49
50
  self.stitch_map = []
50
51
  self.px = px
52
+ self.color_set = nil
51
53
 
52
54
  unless img_path.empty?
53
55
  make_img
54
- set_dominant_colors
56
+ build_color_set
55
57
  build_pixel_array
56
58
 
57
- d = DrawRasem.new(self.stitch_map, self.width, self.px)
58
- d.stitch
59
+ stitch
59
60
  end
60
61
  end
61
62
 
63
+ def stitch
64
+ d = DrawRasem.new(self.stitch_map, self.width, self.px, self.color_set)
65
+ d.stitch
66
+ end
67
+
62
68
  def make_img
63
69
  self.img = ImageList.new(img_path).resize_to_fit(width)
64
70
  end
65
71
 
66
72
  def set_dominant_colors
67
- color_pos = 0
68
73
  colors = black_and_white
69
74
  set_num_colors
70
75
  if self.num_of_colors > 3 && !img_path.empty?
@@ -74,13 +79,32 @@ class Stitchifier
74
79
  off_colors = build_off_color_arr(main_color)
75
80
  colors = miro_px + off_colors + colors
76
81
  end
82
+ set_px_shapes(colors)
83
+ self.dominant_colors = colors.uniq
84
+ end
85
+
86
+ def set_px_shapes(colors)
87
+ color_pos = 0
77
88
  colors.each do |px|
78
89
  if px.shape.nil?
79
90
  px.shape = FILLABLE_SHAPES[color_pos]
80
91
  color_pos = (color_pos + 1) % FILLABLE_SHAPES.length
81
92
  end
82
93
  end
83
- self.dominant_colors = colors.uniq
94
+ end
95
+
96
+ def build_color_set(req_colors = [])
97
+ if req_colors.length == 0
98
+ set_dominant_colors
99
+ self.color_set = self.dominant_colors
100
+ else
101
+ set_dominant_colors
102
+ colors = self.dominant_colors
103
+ colors.slice!(0, req_colors.length)
104
+ color_map = colors + req_colors.map{ |x| Pixelfy.from_hex(x) }
105
+ self.color_set = set_px_shapes(color_map)
106
+ end
107
+ build_pixel_array
84
108
  end
85
109
 
86
110
  def black_and_white
@@ -105,7 +129,8 @@ class Stitchifier
105
129
  end
106
130
 
107
131
  def colorize_pixels
108
- self.base_pixel_arr.each {|px| self.stitch_map << px.colorize(self.dominant_colors) }
132
+ self.stitch_map = []
133
+ self.base_pixel_arr.each {|px| self.stitch_map << px.colorize(self.color_set) }
109
134
  end
110
135
 
111
136
  def set_num_colors
@@ -1,11 +1,12 @@
1
1
  class DrawRasem
2
2
 
3
- attr_accessor :px_arr, :width, :px, :pos_x, :pos_y, :height
3
+ attr_accessor :px_arr, :width, :px, :pos_x, :pos_y, :height, :color_set
4
4
 
5
- def initialize(px_arr, width=50, px=10)
5
+ def initialize(px_arr, width=50, px=10, color_set=[])
6
6
  self.px_arr = px_arr
7
7
  self.width = width
8
8
  self.px = px
9
+ self.color_set = color_set
9
10
  clear_vars
10
11
  end
11
12
 
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.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ellen Wondra