Makes interesting shapes on the screen.  Too bad PyGame's draw-polygon
routine is non-antialiased, but it's maybe more interesting in that it
uses the even-odd rule.

#!/usr/bin/python
import pygame, math, random

def main():
    pygame.init()
    (w, h) = (1024, 768)
    screen = pygame.display.set_mode((w, h), pygame.FULLSCREEN)
    color = (255, 64, 64)
    center = (w/2, h/2)
    r = h/2
    d_d_theta = math.pi / 70
    d_theta = 0
    npoints = 3
    while 1:
        ev = pygame.event.poll()
        if ev.type == pygame.NOEVENT:
            screen.fill((0, 0, 0))
            d_theta += d_d_theta / npoints
            if d_theta > 2 * math.pi:
                d_theta %= 2 * math.pi
                npoints += 1
            pointslist = [(w/2 + r * math.sin(ii * d_theta),
                           h/2 + r * -math.cos(ii * d_theta))
                          for ii in range(npoints)]
            pygame.draw.polygon(screen, color, pointslist)
            pygame.display.flip()
        if ev.type == pygame.MOUSEBUTTONDOWN: break
        elif ev.type == pygame.QUIT: break

if __name__ == '__main__': main()

Reply via email to