### Title: Fast Circle Drawing Using Surfarray

Author: Pete Shinners (pete at shinners.org)
Submission date: May 19, 2001

Description: Pete says, "I put together a quick demonstration on how to make your own circles using Numeric python and the surfarray modules. Note that this code only does circles. Changing it to handle ellipses shouldn't be too difficult, but you'll need to be a little up on your math. Remember you'll need Numeric python installed ( www.pfdubois.com ), but other than that you should be able to pick and learn at my little circle drawing example."

pygame version required: Any with SurfArray
SDL version required: Any
Python version required: Any with Numeric

Comments: Pete gives us a circle drawing routine, and a small script to test it. The math is pretty straightforward, but the syntax may be a little unfamiliar to those not used to working with Numpy.

As this script draws its circles, you may note that many look a little oblong. This is most noticable with the smallest , brightest circles, but all look a little squared off. This occurs not because of any particular weakness in the code, but rather because of the lack of anti-aliasing. Also note that this code doesn't run as fast as it could - Pete has added an artificial delay loop at the end of his script. Comment out the last line (pygame.time.delay(100)) to see how fast it can go.

```
"""Draw a circle with Numeric"""

#quick and dirty imports
import pygame
from pygame.locals import *
import pygame.surfarray as surfarray
from Numeric import *
squareroot = sqrt

"make a surface with a circle in it, color is RGB"

#make a simple 8bit surface and colormap
surf.set_palette(((0, 0, 0), color))

surf.set_colorkey(0, RLEACCEL)      #make transparent

return surf

if __name__ == '__main__':
#lets do a little testing
from random import *
pygame.init()
screen = pygame.display.set_mode((200, 200))
while not pygame.event.peek([QUIT,KEYDOWN]):
pos = randint(0, 160), randint(0, 160)
color = randint(20, 200), randint(20, 200), randint(20, 200)