pygame-ce
pygame-ce copied to clipboard
Add draw.aaellipse
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()