Skip to content

Instantly share code, notes, and snippets.

@kenmazaika
Created August 7, 2015 19:52
Show Gist options
  • Save kenmazaika/e9340f0e5353032aeadc to your computer and use it in GitHub Desktop.
Save kenmazaika/e9340f0e5353032aeadc to your computer and use it in GitHub Desktop.
def blur
@array.each_with_index do |row,x|
row.each_with_index do |cell,y|
last_x_pixel = # TODO: calculate the width of the image here. May need to subtract 1.
if @array[x][y] == 1
@new_array[x][y] ||= 1
@new_array[x-1][y] = 1 if x != 0 # makes sense to go left, unless it's the left-most
@new_array[x][y-1] = 1
@new_array[x][y+1] = 1
@new_array[x+1][y] = 1 if x != last_x_pixel # only go right if it's not the last x_pixel
else
@new_array[x][y] ||= @array[x][y]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment