Advertisement
IvoB1n

proj1

Dec 15th, 2020
699
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def fill(fmap, x, y, color, fill_color, map_size):
  2.     if x < 0 or x >= map_size or y < 0 or y >= map_size:
  3.         return
  4.     if fmap[x][y] == color:
  5.             fmap[x][y] = fill_color
  6.             fill(fmap, x+1, y, color, fill_color, map_size)
  7.             fill(fmap, x-1, y, color, fill_color, map_size)
  8.             fill(fmap, x, y+1, color, fill_color, map_size)
  9.             fill(fmap, x, y-1, color, fill_color, map_size)
  10.  
  11.  
  12. f = open("bitmap.in", "r")
  13.  
  14. map_size = int(f.readline())
  15. fill_color = f.readline()
  16.  
  17. in_coords = (f.readline()).split()
  18. x_coord = int(in_coords[0])
  19. y_coord = int(in_coords[1])
  20.  
  21. x_coord-=1
  22. y_coord-=1
  23.  
  24. bitmap = []
  25.  
  26. for x in range(map_size):
  27.     line = []
  28.     for y in range(map_size):
  29.         line.append(f.read(1))
  30.     f.read(1)    
  31.     bitmap.append(line)
  32.  
  33. c = bitmap[x_coord][y_coord]
  34.  
  35. fill(bitmap, x_coord, y_coord, c, fill_color, map_size)
  36.  
  37. for x in range(map_size):
  38.     print()
  39.     for y in range(map_size):
  40.         print(bitmap[x][y][0], end = '')
  41. print() # remove to delete last \n
  42.  
Advertisement
RAW Paste Data Copied
Advertisement