Skip to content

Instantly share code, notes, and snippets.

@bartolsthoorn
Created January 28, 2011 19:43
Show Gist options
  • Save bartolsthoorn/800818 to your computer and use it in GitHub Desktop.
Save bartolsthoorn/800818 to your computer and use it in GitHub Desktop.
def check_pixel(x, y)
set_checked(x, y)
@shape_pixels = @shape_pixels + 1
if (@shape_y_pixels[y] == nil)
@shape_y_pixels[y] = 0
end
if (@shape_x_pixels[x] == nil)
@shape_x_pixels[x] = 0
end
@shape_y_pixels[y] = @shape_y_pixels[y] + 1
@shape_x_pixels[x] = @shape_x_pixels[x] + 1
if (x-1 >= 0)
if (!is_checked?(x-1, y) and (is_pixel_white?(x-1,y)))
check_pixel(x-1, y)
end
end
if (y-1 >= 0)
if (!is_checked?(x, y-1) and (is_pixel_white?(x,y-1)))
check_pixel(x, y-1)
end
end
if (x+1 < @width)
if (!is_checked?(x+1, y) and (is_pixel_white?(x+1,y)))
check_pixel(x+1, y)
end
end
if (y+1 < @height)
if (!is_checked?(x, y+1) and (is_pixel_white?(x,y+1)))
check_pixel(x, y+1)
end
end
end
def set_checked(x, y)
if (@checkedpixels[x] == nil)
@checkedpixels[x] = Array.new
end
@checkedpixels[x][y] = true
end
def is_checked?(x, y)
if (@checkedpixels[x] == nil)
return false
else
return @checkedpixels[x][y]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment