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

Add draw.aapolygon

Open mzivic7 opened this issue 4 months ago • 19 comments

This PR adds draw.aapolygon function, with filled option. It was not possible to overlap draw.poylgon and draw.aalines without issues: function draw_fillpoly sometimes draws polygon slightly larger, and those fully opaque pixels are hiding antialiased pixels from aalines So I made separate, modified, draw_fillpoly_for_aapolygon that makes borders slightly thinner at those problematic places. I didn't want to change original draw_fillpoly: to not add extra arguments and if-s inside loops, which would make it slower. draw.aapolygon is added to docs, examples and tests.

Screenshot_From_2024-09-28_12-44-51 Left: draw.polygon+draw.aalines Right: draw.aapolygon

Sample code
import pygame

points = [[100, 100],
        [200, 160],
        [120, 255],
        [70, 121]]
points2 = [[220, 100],
         [320, 160],
         [240, 255],
         [190, 121]]
pygame.init()
screen = pygame.display.set_mode((400, 400))
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.aalines(screen, "white", True, points)
  pygame.draw.polygon(screen, "white", points)
  pygame.draw.aapolygon(screen, "white", points2)
  pygame.display.flip()
  clock.tick(60)
pygame.quit()

mzivic7 avatar Sep 28 '24 13:09 mzivic7