[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pygame] image & sprite module



azazel wrote:
> However, I want to ask you a final question, how can I know whether a surface 
> is totally fill with the same color without quering all the pixels?

this will have to be a numeric operation. still it's going to require
checking all pixel values, so hopefully you do this before the game
actually starts.

import pygame, Numeric

def all_pixels_same(surf):
    pixels = pygame.surfarray.pixels2d(surf)
    return Numeric.alltrue(pixels == pixels[0])

that should be as fast as you can get it. using the pixels2d means we are
checking directly the pixels in the surface, not making a copy first. hmm,
you could speed up false cases by breaking the image up, perhaps doing it
by row.

____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org