22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/pixelart/pixelator.rb', line 22
def grid( spacing: 10 )
width = @img.width + (@width-1)*spacing
height = @img.height + (@height-1)*spacing
img = ChunkyPNG::Image.new( width, height, ChunkyPNG::Color::WHITE )
@img.width.times do |x|
xpixel = x/@xsize
@img.height.times do |y|
ypixel = y/@ysize
xpixel = @width-1 if xpixel >= @width
ypixel = @height-1 if ypixel >= @height
color = @img[x,y]
img[x + spacing*xpixel,
y + spacing*ypixel] = color
end
end
Image.new( img.width, img.height, img )
end
|