Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add draw.aaellipse #3016

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions buildconfig/stubs/pygame/draw.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ def aacircle(
def ellipse(
surface: Surface, color: ColorLike, rect: RectLike, width: int = 0
) -> Rect: ...
def aaellipse(
surface: Surface, color: ColorLike, rect: RectLike, width: int = 0
) -> Rect: ...
def arc(
surface: Surface,
color: ColorLike,
Expand Down
Binary file modified docs/reST/ref/code_examples/draw_module_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 7 additions & 2 deletions docs/reST/ref/code_examples/draw_module_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,15 @@
)

# Draw an ellipse outline, using a rectangle as the outside boundaries
pygame.draw.ellipse(screen, "red", [225, 10, 50, 20], 2)
pygame.draw.ellipse(screen, "red", [235, 10, 50, 20], 2)

# Draw an solid ellipse, using a rectangle as the outside boundaries
pygame.draw.ellipse(screen, "red", [300, 10, 50, 20])
pygame.draw.ellipse(screen, "red", [310, 10, 50, 20])

# Draw an antialiased ellipse, using a rectangle as the outside boundaries
pygame.draw.aaellipse(screen, "red", [235, 40, 50, 20], 3)
# Draw an antialiased filled ellipse, using a rectangle as the outside boundaries
pygame.draw.aaellipse(screen, "red", [310, 40, 50, 20])

# This draws a triangle using the polygon command
pygame.draw.polygon(screen, "black", [[100, 100], [0, 200], [200, 200]], 5)
Expand Down
39 changes: 39 additions & 0 deletions docs/reST/ref/draw.rst
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,45 @@ object around the draw calls (see :func:`pygame.Surface.lock` and

.. ## pygame.draw.ellipse ##

.. function:: aaellipse

| :sl:`draw an antialiased ellipse`
| :sg:`aaellipse(surface, color, rect) -> Rect`
| :sg:`aaellipse(surface, color, rect, width=0) -> Rect`

Draws an antialiased ellipse on the given surface.
Uses Xiaolin Wu Circle Algorithm.
adapted from: https://cgg.mff.cuni.cz/~pepca/ref/WU.pdf

:param Surface surface: surface to draw on
:param color: color to draw with, the alpha value is optional if using a
tuple ``(RGB[A])``
:type color: Color or string (for :doc:`color_list`) or int or tuple(int, int, int, [int])
:param Rect rect: rectangle to indicate the position and dimensions of the
ellipse, the ellipse will be centered inside the rectangle and bounded
by it
:param int width: (optional) used for line thickness or to indicate that
the ellipse is to be filled (not to be confused with the width value
of the ``rect`` parameter)

| if ``width == 0``, (default) fill the ellipse
| if ``width > 0``, used for line thickness
| if ``width < 0``, nothing will be drawn
|

.. note::
When using ``width`` values ``> 1``, the edge lines will only grow
inward from the original boundary of the ``rect`` parameter.

:returns: a rect bounding the changed pixels, if nothing is drawn the
bounding rect's position will be the position of the given ``rect``
parameter and its width and height will be 0
:rtype: Rect

.. versionadded:: 2.5.3

.. ## pygame.draw.aaellipse ##

.. function:: arc

| :sl:`draw an elliptical arc`
Expand Down
1 change: 1 addition & 0 deletions src_c/doc/draw_doc.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#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"
#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"
#define DOC_DRAW_ELLIPSE "ellipse(surface, color, rect) -> Rect\nellipse(surface, color, rect, width=0) -> Rect\ndraw an ellipse"
#define DOC_DRAW_AAELLIPSE "aaellipse(surface, color, rect) -> Rect\naaellipse(surface, color, rect, width=0) -> Rect\ndraw an antialiased ellipse"
#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"
#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"
#define DOC_DRAW_LINES "lines(surface, color, closed, points) -> Rect\nlines(surface, color, closed, points, width=1) -> Rect\ndraw multiple contiguous straight line segments"
Expand Down
Loading
Loading