summaryrefslogtreecommitdiff
path: root/test/pygame-test2.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/pygame-test2.py')
-rwxr-xr-xtest/pygame-test2.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/test/pygame-test2.py b/test/pygame-test2.py
new file mode 100755
index 0000000..9ebc1ae
--- /dev/null
+++ b/test/pygame-test2.py
@@ -0,0 +1,49 @@
+#!/usr/bin/env python
+"""demonstrate pycairo and pygame
+method1: use an intermediate Python array object
+"""
+
+import array
+import math
+import sys
+
+import cairo
+import pygame
+
+def draw(surface):
+ x,y, radius = (250,250, 200)
+ ctx = cairo.Context(surface)
+ ctx.set_line_width(15)
+ ctx.arc(x, y, radius, 0, 2.0 * math.pi)
+ ctx.set_source_rgb(0.8, 0.8, 0.8)
+ ctx.fill_preserve()
+ ctx.set_source_rgb(1, 1, 1)
+ ctx.stroke()
+
+def input(events):
+ for event in events:
+ if event.type == pygame.QUIT:
+ sys.exit(0)
+ else:
+ print event
+
+
+Width, Height = 512, 512
+data = array.array('c', chr(0) * Width * Height * 4)
+stride = Width * 4
+surface = cairo.ImageSurface.create_for_data(data, cairo.FORMAT_ARGB32,Width, Height, stride)
+
+pygame.init()
+window = pygame.display.set_mode( (Width,Height) )
+screen = pygame.display.get_surface()
+
+draw(surface)
+
+#Create PyGame surface from Cairo Surface
+image = pygame.image.frombuffer(data.tostring(),(Width,Height),"ARGB",)
+#Tranfer to Screen
+screen.blit(image, (0,0))
+pygame.display.flip()
+
+while True:
+ input(pygame.event.get())