Last active
February 16, 2016 21:57
-
-
Save isomorpheric/10e7e58dd4c4d37bb9b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\# Image Blur 1 | |
class Image | |
attr_accessor :array , :result_array | |
def initialize(array) | |
@array = array | |
@result_array = array | |
end | |
def output_image | |
@result_array.each do |row| | |
puts row.join(" ") | |
end | |
nil | |
end | |
def blur | |
one_pixels = Array.new | |
@result_array = @array | |
@array.each.with_index do |row, row_index| #could also use 'i' or 'j' for indices | |
row.each.with_index do |pixel, col_index| | |
if pixel == 1 | |
one_pixels << [row_index, col_index] | |
end | |
end | |
end | |
one_pixels.each do |row_index, col_index| | |
@result_array[row_index - 1][col_index] = 1 | |
@result_array[row_index + 1][col_index] = 1 | |
@result_array[row_index][col_index - 1] = 1 | |
@result_array[row_index][col_index + 1] = 1 | |
end | |
end | |
# def transform(row_index, col_index) | |
# @result_array[row_index - 1][col_index] = 1 | |
# @result_array[row_index + 1][col_index] = 1 | |
# @result_array[row_index][col_index - 1] = 1 | |
# @result_array[row_index][col_index + 1] = 1 | |
# end | |
end | |
image = Image.new([ | |
[0, 0, 0, 0], | |
[0, 1, 0, 0], | |
[0, 0, 0, 1], | |
[0, 0, 0, 0] | |
]) | |
image.blur | |
image.output_image |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment