pygame-ce icon indicating copy to clipboard operation
pygame-ce copied to clipboard

Add draw.aaellipse

Open mzivic7 opened this issue 7 months ago • 1 comments

This PR adds draw.aaellipse function, with width and thickness options. It is completely interchangeable with draw.ellipse in terms of arguments. Algorithm used is adapted from Xiaolin Wu's general fast antialiasing algorithm, and is very similar to draw.aacircle. Only notable difference: in aacircle, 8 pixels are drawn at once, but here, only 4, because ellipse has 2 symmetries. Because of that aaelipse has additional vertical drawing (aacircle has only horizontal but because of extra symmetries it is vertical at the same time). It is added to docs too.

Sample code
import pygame

pygame.init()
screen = pygame.display.set_mode((512, 512))
clock = pygame.time.Clock()

run = True
while run:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False
    screen.fill("black")
    pygame.draw.aaellipse(screen, "red", [100, 100, 100, 50], 1)
    pygame.draw.aaellipse(screen, "red", [100, 160, 100, 50])
    pygame.draw.aaellipse(screen, "red", [100, 220, 100, 50], 4)
    pygame.display.flip()
    clock.tick(60)
pygame.quit()

mzivic7 avatar Jul 22 '24 18:07 mzivic7