diff options
author | Walter Bender <walter.bender@gmail.com> | 2011-11-12 16:21:54 (GMT) |
---|---|---|
committer | Walter Bender <walter.bender@gmail.com> | 2011-11-12 16:21:54 (GMT) |
commit | f0f663ea89eff871214ccc4a8348e572603d2a16 (patch) | |
tree | e45c3b22ac937b95edffb896997cb20307bd7ae0 /TurtleArt/sprites.py | |
parent | 30028d772bdcc33bd8ee444e18b769ecca7f880a (diff) |
more robust get_pixel code as per cscott
Diffstat (limited to 'TurtleArt/sprites.py')
-rw-r--r-- | TurtleArt/sprites.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/TurtleArt/sprites.py b/TurtleArt/sprites.py index ace99c9..412e3bd 100644 --- a/TurtleArt/sprites.py +++ b/TurtleArt/sprites.py @@ -440,6 +440,18 @@ class Sprite: y < 0 or y > (self.rect.height - 1): return(-1, -1, -1, -1) + # create a new 1x1 cairo surface + cs = cairo.ImageSurface(cairo.FORMAT_RGB24, 1, 1); + cr = cairo.Context(cs) + cr.set_source_surface(self.cached_surfaces[i], -x, -y) + cr.rectangle(0,0,1,1) + cr.set_operator(cairo.OPERATOR_SOURCE) + cr.fill() + cs.flush() # ensure all writing is done + # Read the pixel + pixels = cs.get_data() + return (ord(pixels[0]), ord(pixels[1]), ord(pixels[2]), 0) + ''' # Map the cairo surface onto a pixmap pixmap = gtk.gdk.Pixmap(None, self.rect.width, self.rect.height, 24) cr = pixmap.cairo_create() @@ -450,3 +462,4 @@ class Sprite: return(int((pixel & 0xFF0000) >> 16), int((pixel & 0x00FF00) >> 8), int((pixel & 0x0000FF) >> 0), 0) + ''' |