Add function and documentation to draw circle

This commit is contained in:
void4 2024-05-27 00:23:16 +02:00
parent 8b14ed741a
commit 2c4a6e1179
2 changed files with 22 additions and 0 deletions

View File

@ -240,6 +240,19 @@ Methods
.. versionadded:: 5.3.0
.. py:method:: ImageDraw.circle(xy, radius, fill=None, outline=None, width=1)
Draws a circle given the center coordinates and a radius.
:param xy: One point to define the circle center. Sequence:
``[x, y]``
:param radius: Radius of the circle
:param outline: Color to use for the outline.
:param fill: Color to use for the fill.
:param width: The line width, in pixels.
.. versionadded:: ?.?.?
.. py:method:: ImageDraw.line(xy, fill=None, width=0, joint=None)
Draws a line between the coordinates in the ``xy`` list.

View File

@ -181,6 +181,15 @@ class ImageDraw:
if ink is not None and ink != fill and width != 0:
self.draw.draw_ellipse(xy, ink, 0, width)
def circle(self, xy: Coords, radius, fill=None, outline=None, width=1) -> None:
"""Draw a circle given center coordinates and a radius."""
ink, fill = self._getink(outline, fill)
ellipse_xy = (xy[0]-radius, xy[1]-radius, xy[0]+radius, xy[1]+radius)
if fill is not None:
self.draw.draw_ellipse(ellipse_xy, fill, 1)
if ink is not None and ink != fill and width != 0:
self.draw.draw_ellipse(ellipse_xy, ink, 0, width)
def line(self, xy: Coords, fill=None, width=0, joint=None) -> None:
"""Draw a line, or a connected sequence of line segments."""
ink = self._getink(fill)[0]