draw_utils.py
def flood_fill(surf, f_x, f_y, color):
    """ fill surface surf with specified color at f_x, f_y
    """
    pixels = pygame.PixelArray(surf)
    width, height = surf.get_size()

    test_color = pixels[f_x, f_y]

    color = pygame.Color(color)
    color = (color.r, color.g, color.b)
        
    stack = []        
    stack.append((f_x, f_y))
    
    while len(stack):            
        x, y = stack.pop()
            
        if x < 0 or y < 0 or x >= width or y >= height:
            continue

        c_color = pixels[x, y]
        if pygame.Color(c_color)[1:]==color:
            continue

        if test_color==c_color:            
            pixels[x, y] = color
        else:
            continue

        stack.append((x + 1, y))   # right
        stack.append((x - 1, y))  # left
        stack.append((x, y + 1))  # down
        stack.append((x, y - 1))
 fill surface surf with specified color at f_x, f_y
    
fill surface surf with specified color at f_x, f_y
fill surface surf with specified color at f_x f_y
def flood_fill(surf, f_x, f_y, color):
    pixels = pygame.PixelArray(surf)
    width, height = surf.get_size()
    test_color = pixels[f_x, f_y]
    color = pygame.Color(color)
    color = (color.r, color.g, color.b)
    stack = []        
    stack.append((f_x, f_y))
    while len(stack):            
        x, y = stack.pop()
        if x < 0 or y < 0 or x >= width or y >= height:
            continue
        c_color = pixels[x, y]
        if pygame.Color(c_color)[1:]==color:
            continue
        if test_color==c_color:            
            pixels[x, y] = color
        else:
            continue
        stack.append((x + 1, y))   
        stack.append((x - 1, y))  
        stack.append((x, y + 1))  
        stack.append((x, y - 1))
def flood_fill ( surf , f_x , f_y , color ) : pixels = pygame . PixelArray ( surf ) width , height = surf . get_size ( ) test_color = pixels [ f_x , f_y ] color = pygame . Color ( color ) color = ( color . r , color . g , color . b ) stack = [ ] stack . append ( ( f_x , f_y ) ) while len ( stack ) : x , y = stack . pop ( ) if x < 0 or y < 0 or x >= width or y >= height : continue c_color = pixels [ x , y ] if pygame . Color ( c_color ) [ 1 : ] == color : continue if test_color == c_color : pixels [ x , y ] = color else : continue stack . append ( ( x + 1 , y ) ) stack . append ( ( x - 1 , y ) ) stack . append ( ( x , y + 1 ) ) stack . append ( ( x , y - 1 ) )
fill surface surf with specified color at f_x, f_y
fill surface surf with specified color at f_x f_y
""" fill surface surf with specified color at f_x, f_y
    """ # right
 # left
 # down

surf
f_x
f_y
color