| 1 |
|
| 2 |
"""demonstrate pycairo and pygame""" |
| 3 |
|
| 4 |
|
| 5 |
import math |
| 6 |
import sys |
| 7 |
|
| 8 |
import cairo |
| 9 |
import pygame |
| 10 |
|
| 11 |
|
| 12 |
def draw(surface): |
| 13 |
x, y, radius = (250, 250, 200) |
| 14 |
ctx = cairo.Context(surface) |
| 15 |
ctx.set_line_width(15) |
| 16 |
ctx.arc(x, y, radius, 0, 2.0 * math.pi) |
| 17 |
ctx.set_source_rgb(0.8, 0.8, 0.8) |
| 18 |
ctx.fill_preserve() |
| 19 |
ctx.set_source_rgb(1, 1, 1) |
| 20 |
ctx.stroke() |
| 21 |
|
| 22 |
|
| 23 |
def input(events): |
| 24 |
for event in events: |
| 25 |
if event.type == pygame.QUIT: |
| 26 |
sys.exit(0) |
| 27 |
else: |
| 28 |
print(event) |
| 29 |
|
| 30 |
|
| 31 |
def main(): |
| 32 |
width, height = 512, 512 |
| 33 |
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height) |
| 34 |
|
| 35 |
pygame.init() |
| 36 |
pygame.display.set_mode((width, height)) |
| 37 |
screen = pygame.display.get_surface() |
| 38 |
|
| 39 |
draw(surface) |
| 40 |
|
| 41 |
|
| 42 |
buf = surface.get_data() |
| 43 |
image = pygame.image.frombuffer(buf, (width, height), "ARGB") |
| 44 |
|
| 45 |
screen.blit(image, (0, 0)) |
| 46 |
pygame.display.flip() |
| 47 |
|
| 48 |
while True: |
| 49 |
input(pygame.event.get()) |
| 50 |
|
| 51 |
|
| 52 |
if __name__ == "__main__": |
| 53 |
main() |