Pygame SVG(last modified: 10 August, '06)
A Python module for rendering an SVG image to a Pygame surface.
A module that allows you to load and display SVG images using Pygame and cairo/libsvg.
The module basically sends the SVG to cairo and receives RGBA data in return, which it then maps an SDL_Surface and then to a Pygame surface.
Usage is simple - a short example follows that will load an SVG image named 'test.svg' and display it (there are two more examples available inside the archive).
| 1 | import pygamesvg, pygame |
| 2 | from pygame.locals import * |
| 3 | |
| 4 | svg = file("test.svg") |
| 5 | # initiate pygame |
| 6 | pygame.init() |
| 7 | # create the pygame screen we will be drawing to |
| 8 | screen = pygame.display.set_mode([500, 400]) |
| 9 | screen.fill((255, 255, 255)) |
| 10 | # render the SVG directly to the screen at the co-ordinates (0, 0), and with scale ratio (1.0, 1.0) |
| 11 | pygamesvg.renderSVGFile(screen, svg, (0, 0), (0, 0), (1.0, 1.0)) |
| 12 | svg.close() |
| 13 | # display loop |
| 14 | while pygame.event.poll().type != QUIT: |
| 15 | pygame.time.delay(10) |
| 16 | pygame.display.update() |