Skip to content

Instantly share code, notes, and snippets.

@framallo
Created December 21, 2015 21:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save framallo/d2ec57e159d7588a4e50 to your computer and use it in GitHub Desktop.
Save framallo/d2ec57e159d7588a4e50 to your computer and use it in GitHub Desktop.
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