Skip to content

Commit dd11ffc

Browse files
authored
Merge pull request #2800 from mzivic7/draw.aacircle
draw.aacircle()
2 parents 582b639 + 1162639 commit dd11ffc

File tree

7 files changed

+1120
-0
lines changed

7 files changed

+1120
-0
lines changed

buildconfig/stubs/pygame/draw.pyi

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from pygame.rect import Rect
22
from pygame.surface import Surface
3+
from typing import overload
34

45
from ._common import ColorValue, Coordinate, RectValue, Sequence
56

@@ -31,6 +32,26 @@ def circle(
3132
draw_bottom_left: bool = False,
3233
draw_bottom_right: bool = False,
3334
) -> Rect: ...
35+
@overload
36+
def aacircle(
37+
surface: Surface,
38+
color: ColorValue,
39+
center: Coordinate,
40+
radius: float,
41+
width: int = 0,
42+
) -> Rect: ...
43+
@overload
44+
def aacircle(
45+
surface: Surface,
46+
color: ColorValue,
47+
center: Coordinate,
48+
radius: float,
49+
width: int = 0,
50+
draw_top_right: bool = False,
51+
draw_top_left: bool = False,
52+
draw_bottom_left: bool = False,
53+
draw_bottom_right: bool = False,
54+
) -> Rect: ...
3455
def ellipse(
3556
surface: Surface, color: ColorValue, rect: RectValue, width: int = 0
3657
) -> Rect: ...
2.12 KB
Loading

docs/reST/ref/code_examples/draw_module_example.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@
7777

7878
# Draw a circle
7979
pygame.draw.circle(screen, "blue", [60, 250], 40)
80+
81+
# Draw an antialiased circle with 3 pixels wide line
82+
pygame.draw.aacircle(screen, "green", [340, 250], 40, 3)
83+
84+
# Draw an antialiased top right circle quadrant with 4 pixels wide line
85+
pygame.draw.aacircle(screen, "red", [340, 250], 20, 4, draw_top_right=True)
86+
87+
# Draw an antialiased bottom left filled circle quadrant
88+
pygame.draw.aacircle(screen, "blue", [340, 250], 20, draw_bottom_left=True)
8089

8190
# Draw only one circle quadrant
8291
pygame.draw.circle(screen, "blue", [250, 250], 40, 0, draw_top_right=True)

docs/reST/ref/draw.rst

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,62 @@ object around the draw calls (see :func:`pygame.Surface.lock` and
206206

207207
.. ## pygame.draw.circle ##
208208
209+
.. function:: aacircle
210+
211+
| :sl:`draw an antialiased circle`
212+
| :sg:`aacircle(surface, color, center, radius) -> Rect`
213+
| :sg:`aacircle(surface, color, center, radius, width=0, draw_top_right=None, draw_top_left=None, draw_bottom_left=None, draw_bottom_right=None) -> Rect`
214+
215+
Draws an antialiased circle on the given surface.
216+
Uses Xaolin Wu Circle Algorithm.
217+
adapted from: https://cgg.mff.cuni.cz/~pepca/ref/WU.pdf
218+
219+
:param Surface surface: surface to draw on
220+
:param color: color to draw with, the alpha value is optional if using a
221+
tuple ``(RGB[A])``
222+
:type color: Color or string (for :doc:`color_list`) or int or tuple(int, int, int, [int])
223+
:param center: center point of the circle as a sequence of 2 ints/floats,
224+
e.g. ``(x, y)``
225+
:type center: tuple(int or float, int or float) or
226+
list(int or float, int or float) or Vector2(int or float, int or float)
227+
:param radius: radius of the circle, measured from the ``center`` parameter,
228+
nothing will be drawn if the ``radius`` is less than 1
229+
:type radius: int or float
230+
:param int width: (optional) used for line thickness or to indicate that
231+
the circle is to be filled
232+
233+
| if ``width == 0``, (default) fill the circle
234+
| if ``width > 0``, used for line thickness
235+
| if ``width < 0``, nothing will be drawn
236+
|
237+
238+
.. note::
239+
When using ``width`` values ``> 1``, the edge lines will only grow
240+
inward.
241+
:param bool draw_top_right: (optional) if this is set to True then the top right corner
242+
of the circle will be drawn
243+
:param bool draw_top_left: (optional) if this is set to True then the top left corner
244+
of the circle will be drawn
245+
:param bool draw_bottom_left: (optional) if this is set to True then the bottom left corner
246+
of the circle will be drawn
247+
:param bool draw_bottom_right: (optional) if this is set to True then the bottom right corner
248+
of the circle will be drawn
249+
250+
| if any of the draw_circle_part is True then it will draw all circle parts that have the True
251+
| value, otherwise it will draw the entire circle.
252+
253+
:returns: a rect bounding the changed pixels, if nothing is drawn the
254+
bounding rect's position will be the ``center`` parameter value (float
255+
values will be truncated) and its width and height will be 0
256+
:rtype: Rect
257+
258+
:raises TypeError: if ``center`` is not a sequence of two numbers
259+
:raises TypeError: if ``radius`` is not a number
260+
261+
.. versionadded:: 2.5.0
262+
263+
.. ## pygame.draw.aacircle ##
264+
209265
.. function:: ellipse
210266

211267
| :sl:`draw an ellipse`

src_c/doc/draw_doc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#define DOC_DRAW_RECT "rect(surface, color, rect) -> Rect\nrect(surface, color, rect, width=0, border_radius=0, border_top_left_radius=-1, border_top_right_radius=-1, border_bottom_left_radius=-1, border_bottom_right_radius=-1) -> Rect\ndraw a rectangle"
44
#define DOC_DRAW_POLYGON "polygon(surface, color, points) -> Rect\npolygon(surface, color, points, width=0) -> Rect\ndraw a polygon"
55
#define DOC_DRAW_CIRCLE "circle(surface, color, center, radius) -> Rect\ncircle(surface, color, center, radius, width=0, draw_top_right=None, draw_top_left=None, draw_bottom_left=None, draw_bottom_right=None) -> Rect\ndraw a circle"
6+
#define DOC_DRAW_AACIRCLE "aacircle(surface, color, center, radius) -> Rect\naacircle(surface, color, center, radius, width=0, draw_top_right=None, draw_top_left=None, draw_bottom_left=None, draw_bottom_right=None) -> Rect\ndraw an antialiased circle"
67
#define DOC_DRAW_ELLIPSE "ellipse(surface, color, rect) -> Rect\nellipse(surface, color, rect, width=0) -> Rect\ndraw an ellipse"
78
#define DOC_DRAW_ARC "arc(surface, color, rect, start_angle, stop_angle) -> Rect\narc(surface, color, rect, start_angle, stop_angle, width=1) -> Rect\ndraw an elliptical arc"
89
#define DOC_DRAW_LINE "line(surface, color, start_pos, end_pos) -> Rect\nline(surface, color, start_pos, end_pos, width=1) -> Rect\ndraw a straight line"

0 commit comments

Comments
 (0)