Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pygame draw antialiased filled polygon

The documentation says "For aapolygon, use aalines with the ‘closed’ parameter.", but pygame.draw.aalines doesn't let me specify the width (0 = filled), making it not fill the surface. This looks just terrible: enter image description here

These circles look much better:

enter image description here

How can I do this?

I generate the surface using quadratic beziers, whose coordinates get appended to a list. Then I draw it onto the surface like this (In the image above I did this twice, once for the outer circle and once for the inner circle):

pygame.draw.polygon(self.image,fclr,self.points)

And the drawing code (shape.image is the same surface as self.image in the code above):

screen.fill((0,0,0))
screen.blit(shape.image,(100,100))
pygame.display.flip()
like image 702
user2746752 Avatar asked Sep 05 '25 17:09

user2746752


1 Answers

martineau's comment is on point: In order to draw antialiased filled shapes with pygame, use the module gfxdraw and draw one regular filled shape and one antialiased outline. From http://www.pygame.org/docs/ref/gfxdraw.html:

"To draw an anti aliased and filled shape, first use the aa* version of the function, and then use the filled version."

Note that you need to import gfxdraw explicitly, i.e. from pygame import gfxdraw.

like image 54
andreasdr Avatar answered Sep 08 '25 07:09

andreasdr