Skip to content

Commit 8d13367

Browse files
authored
Merge pull request #2840 from pygame-community/flood_fill
flood fill
2 parents 0940fb6 + d440ba8 commit 8d13367

File tree

4 files changed

+441
-1
lines changed

4 files changed

+441
-1
lines changed

buildconfig/stubs/pygame/draw.pyi

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ object around the draw calls (see :func:`pygame.Surface.lock` and
2828
See the :mod:`pygame.gfxdraw` module for alternative draw methods.
2929
"""
3030

31-
from typing import overload
31+
from typing import Union, overload
3232

3333
from pygame.rect import Rect
3434
from pygame.surface import Surface
@@ -568,3 +568,28 @@ def aalines(
568568
.. versionchanged:: 2.5.0 ``blend`` argument re-added for backcompat, but will
569569
always raise a deprecation exception when used
570570
"""
571+
572+
def flood_fill(
573+
surface: Surface, color: Union[ColorLike, Surface], start_pos: Point
574+
) -> Rect:
575+
"""Fill an enclosed, same color area, on a surface.
576+
577+
Replace the color of a cluster of connected same-color pixels, beginning
578+
from the starting position, with a repeating pattern or solid single color.
579+
580+
:param Surface surface: surface to draw on
581+
:param color: color, or surface pattern, to draw with. The alpha value is optional if using a
582+
tuple ``(RGB[A])``
583+
:type color: :data:`pygame.typing.ColorLike` or a pattern to fill with, as a Surface
584+
:param start_pos: starting position as a sequence of 2 ints/floats,
585+
e.g. ``(x, y)``
586+
:type start_pos: tuple(int or float, int or float) or
587+
list(int or float, int or float) or Vector2(int or float, int or float)
588+
589+
:returns: a rect bounding the changed pixels, if nothing is drawn the
590+
bounding rect's position will be the position of the starting point
591+
and its width and height will be 0
592+
:rtype: Rect
593+
594+
.. versionadded:: 2.5.6
595+
"""

src_c/doc/draw_doc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
#define DOC_DRAW_LINES "lines(surface, color, closed, points, width=1) -> Rect\nDraw multiple contiguous straight line segments."
1111
#define DOC_DRAW_AALINE "aaline(surface, color, start_pos, end_pos, width=1) -> Rect\nDraw a straight antialiased line."
1212
#define DOC_DRAW_AALINES "aalines(surface, color, closed, points) -> Rect\nDraw multiple contiguous straight antialiased line segments."
13+
#define DOC_DRAW_FLOODFILL "flood_fill(surface, color, start_pos) -> Rect\nFill an enclosed, same color area, on a surface."

0 commit comments

Comments
 (0)