33 lines
682 B
Python
33 lines
682 B
Python
from PIL import Image
|
|
|
|
image = Image.open("stables.png")
|
|
|
|
width, height = image.size
|
|
|
|
def fill(x, y):
|
|
global image
|
|
global width
|
|
global height
|
|
image.putpixel((x,y), 127)
|
|
if x < width-1 and image.getpixel((x+1,y)) == 255:
|
|
fill(x+1, y)
|
|
if x > 0 and image.getpixel((x-1,y)) == 255:
|
|
fill(x-1, y)
|
|
if y < height-1 and image.getpixel((x,y+1)) == 255:
|
|
fill(x, y+1)
|
|
if y > 0 and image.getpixel((x,y-1)) == 255:
|
|
fill(x, y-1)
|
|
|
|
zones = 0
|
|
for x in range(width):
|
|
for y in range(height):
|
|
if image.getpixel((x,y)) == 255:
|
|
fill(x,y)
|
|
# image.show()
|
|
zones += 1
|
|
|
|
print(zones)
|
|
image.show()
|
|
|
|
|