public
Rubygem
Description: a ruby library for generating identicon
Clone URL: git://github.com/swdyh/quilt.git
 * fixed draw algorithm.
swdyh (author)
Fri Sep 19 05:15:44 -0700 2008
commit  0c285859bae065278ef21fd5afa8559de28c9f97
tree    f59ca9287a28b906d628f204ce2dce03d9d90d17
parent  6bf117b73c874aa2f89f6f8cc283fa423a436952
...
128
129
130
131
 
132
133
134
135
136
137
 
138
139
140
...
194
195
196
197
 
198
199
200
201
202
203
204
 
 
 
205
206
207
208
 
209
210
 
211
212
 
213
214
215
...
128
129
130
 
131
132
133
134
135
136
 
137
138
139
140
...
194
195
196
 
197
198
199
200
201
202
 
 
203
204
205
206
207
208
 
209
210
 
211
212
 
213
214
215
216
0
@@ -128,13 +128,13 @@ module Quilt
0
       @decode = decode @code
0
 
0
       if opt[:size]
0
- @scale = (((opt[:size] / 3) - 1) / (PATCH_SIZE - 1)) + 1
0
+ @scale = (opt[:size].to_f / (PATCH_SIZE * 3)).ceil
0
         @resize_to = opt[:size]
0
       else
0
         @scale = opt[:scale] || 1
0
       end
0
 
0
- @patch_width = (PATCH_SIZE - 1) * @scale + 1
0
+ @patch_width = PATCH_SIZE * @scale
0
       @image = @@image_lib.new @patch_width * 3, @patch_width * 3
0
       @back_color = @image.color 255, 255, 255
0
       @fore_color = @image.color @decode[:red], @decode[:green], @decode[:blue]
0
@@ -194,22 +194,23 @@ module Quilt
0
       else
0
         fore, back = @fore_color, @back_color
0
       end
0
- @image.fill_rect(x, y, x + @patch_width, y + @patch_width, back)
0
+ @image.fill_rect(x, y, x + @patch_width - 1, y + @patch_width - 1, back)
0
 
0
       points = []
0
       PATCHES[patch].each do |pt|
0
         dx = pt % PATCH_SIZE
0
         dy = pt / PATCH_SIZE
0
- px = dx.to_f / (PATCH_SIZE - 1) * @patch_width
0
- py = dy.to_f / (PATCH_SIZE - 1) * @patch_width
0
+ len = @patch_width - 1
0
+ px = dx.to_f / (PATCH_SIZE - 1) * len
0
+ py = dy.to_f / (PATCH_SIZE - 1) * len
0
 
0
         case turn
0
         when 1
0
- px, py = @patch_width - py, px
0
+ px, py = len - py, px
0
         when 2
0
- px, py = @patch_width - px, @patch_width - py
0
+ px, py = len - px, len - py
0
         when 3
0
- px, py = py, @patch_width - px
0
+ px, py = py, len - px
0
         end
0
         points << [x + px, y + py]
0
       end

Comments

    No one has commented yet.