Created
December 21, 2015 21:52
-
-
Save framallo/d2ec57e159d7588a4e50 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
require 'pp' | |
class Image | |
attr_accessor :array | |
def initialize(array) | |
@array = array | |
end | |
def output_image | |
array.each { |a,b,c,d| puts "#{a} #{b} #{c} #{d}" } | |
end | |
def detect_ones | |
arr = [] | |
array.each_with_index do |row, y| | |
row.each_with_index do |e, x| | |
arr << [x, y] if e == 1 | |
end | |
end | |
arr | |
end | |
def blur | |
detect_ones.each do |x,y| | |
write x, y+1, 1 | |
write x, y-1, 1 | |
write x+1, y, 1 | |
write x-1, y, 1 | |
end | |
end | |
def write(x, y, value) | |
raise 'error' unless array.size >= y && array[y] && array[y].size >= x | |
array[y][x] = value | |
end | |
end | |
image = Image.new( | |
[ [0, 0, 0, 0], | |
[0, 1, 0, 0], | |
[0, 0, 0, 1], | |
[0, 0, 0, 0] | |
]) | |
image.output_image | |
image.blur | |
image.output_image |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment