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

Re: [pygame] blending edges



On Fri, Jan 11, 2002 at 03:38:30PM -0800, Robert Flemming wrote:
> On Fri, Jan 11, 2002 at 03:04:17PM -0800, Robert Flemming wrote:
> > On a purely cosmetic note I was thinking about a way to try and blend the
> > edges of an image with the background.  After the recent discussion on
> 
> I guess to sort of answer my own question, yes I know I can do several blits
> on top of each other each time changing the alpha value and decreasing the
> size of the rectangle, but I was hoping to avoid doing a large number of
> blits, especially since there will be many images on the screen at the same
> time that would get this kind of treatment.

I assume you want surfarray.
It's the fastest way to change per-pixel alpha values known to me. And it also
gives you the choice of circular fading out edges as well.
Here's a small sample app. It's not optimized at all and just fades out
rectangular areas in the edges:


import pygame
import pygame.surfarray as surfarray
from pygame.locals import *

def createEdges(surface):
    alpha = surfarray.pixels_alpha(surface)
    r = range(1,20)
    r.reverse()
    for i in r:
        alpha[0:5*i,0:5*i] = i*12
        alpha[0:5*i,-5*i:] = i*12
        alpha[-5*i:,0:5*i] = i*12
        alpha[-5*i:,-5*i:] = i*12

def main():
    pygame.init()
    screen = pygame.display.set_mode((640,480),0,32)
    screen.fill((0,0,128))

    surface = pygame.Surface((640,480),0,32).convert_alpha()
    surface.fill((0,255,0))
    createEdges(surface)
    screen.blit(surface,(0,0))

    pygame.display.update()
    while 1:
        for event in pygame.event.get():
            if event.type == QUIT or (event.type == KEYDOWN and
             event.key == K_ESCAPE):
                pygame.quit()
                raise SystemExit
        pygame.time.delay(50)
        
if __name__ == '__main__': main()


-- 
Raiser, Frank aka CrashChaos
IRC: irc.openprojects.net #pygame

Windows is the one true OS. MS invented the GUI. MS invented
the 32 bit OS. MS is open and standard. MS loves you. We have
always been at war with Oceana.
____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org