[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Bump mapping



On Wed, 30 Jun 2004 02:17:42 -0700 (PDT), Jasper Phillips
<jasper@peak.org> wrote:
> 
> Actually, now that I look at it in isolation there isn't much here beyond
> the get_at()s and set_at()s.  I should just get off my lazy ass and try
> surfarray. ;-)
> 
> -Jasper
> 

I was bored, so here. ;)

def shadeMapSurfArray( surface, shadeSurf, elevation=55.0, compensate=False ):
    array = pygame.surfarray.array3d(surface)
    shade = pygame.surfarray.array3d(shadeSurf).astype(N.Float64)
    if compensate:
        compensation = sin(elevation)
        shade /= compensation
    shade /= 255.0

    # repeat the shade pattern as many times as needed
    # to cover the whole surface
    x,y  = surface.get_size()
    xx,yy = shadeSurf.get_size()
    mx,my = (x+xx)//xx, (y+yy)//yy
    shade = N.concatenate((shade,)*mx,0)
    shade = N.concatenate((shade,)*my,1)
    shade = shade[:x,:y,...]
    
    array = array * shade
    array = N.where(array > 255, 255, array).astype(N.Int0)
    return pygame.surfarray.make_surface(array)

Probably someone more familiar with the surfarray can make it faster,
but should beat get_at/set_at at least.

-- 
Sami Hangaslammi