Created
October 14, 2016 23:02
-
-
Save kellylougheed/ec87686d46d85ae0ad7b2d50e58db3af to your computer and use it in GitHub Desktop.
Image Blur #2 solution
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
class Image | |
attr_accessor :data | |
def initialize(data) | |
@data = data | |
end | |
def blur | |
# Empty array to hold x, y coords with values of "1" | |
to_be_changed = Array.new | |
# Loop through array to find x, y coords with values of "1" | |
@arr.each_index do |y| | |
subarray = @arr[y] | |
subarray.each_index do |x| | |
if subarray[x] == 1 | |
to_be_changed.push([x, y]) | |
end | |
end | |
end | |
# Change surrounding 0's to 1's for each x, y coord | |
to_be_changed.each do |coords| | |
x = coords[0] | |
y = coords[1] | |
@arr[y][x-1] = 1 unless x-1 < 0 | |
@arr[y][x+1] = 1 unless x+1 >= @arr[y].length | |
@arr[y-1][x] = 1 unless y-1 < 0 | |
@arr[y+1][x] = 1 unless y+1 >= @arr.length | |
end | |
return @arr | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment