Skip to content

Instantly share code, notes, and snippets.

@pshushereba
Created February 10, 2016 22:54
Show Gist options
  • Save pshushereba/eb1454c20d27f16c50a2 to your computer and use it in GitHub Desktop.
Save pshushereba/eb1454c20d27f16c50a2 to your computer and use it in GitHub Desktop.
class Image
def initialize(image)
@image = image
end
def output_image
@image.each { |row| puts row.join }
end
def blur(row_index,col_index)
@image[row_index-1][col_index] = 1
@image[row_index][col_index-1] = 1
image[row_index][col_index+1] = 1
image[row_index+1][col_index] = 1
end
end
def transform
one_index = []
@image.each_with_index do |row, row_index|
row.each_with_index do |pixel, col_index|
if pixel == 1
one_index.push([row_index, col_index])
end
one_index.each do |row_index, col_index|
blur(row_index,col_index)
end
end
end
return Image.new(@image)
end
end
image = Image.new([
[0, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 0, 1],
[0, 0, 0, 0]
])
#image.output_image
afterImage = image.transform
afterImage.output_image
# afterImage = Image.new([
# [0, 1, 0, 0],
# [1, 1, 1, 1],
# [0, 1, 1, 1],
# [0, 0, 0, 1]
# ])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment