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

Re: [pygame] Using Numeric & Surfarray with alpha values



Sorry about the lack of explicitness in the last few emails,
this is all I've been doing for the past couple days and I'm
clearly leaving things unsaid which are not obvious. Here is
what's going on, laid out for ya:

I'm making a tile-based game, which has a grid of hexagons
on the screen. Some of these hexagons, when they enter a
certain state, we want to have particle emitters orbiting
them in a circle, spitting out particles. We want these
particles to each fade out gradually over a certain amount
of time. 

So, each hexagon, or Cell, has a list of emitters (so we can
have more than one emitter orbiting at once, i.e. at
opposite angles). Each emitter has a list of particles,
which is being added to and taken away from at each tick.
Each particle has a Decay, which is how long it takes that
particle to go from opaque to transparent, and Life, which
is how much time that particle has left to live. Each tick,
each particle's Life is decremented by some amount, and if
it reaches 0, that particle is removed. Each particle also
has a position.

So, in our renderer, we want to render a master particle
image, which has per-pixel alpha, once for each particle in
existence, and with alpha values which are Life / Decay of
the original's. We would like to do this with Surfarray and
Numeric, but we are having trouble with this. Here is a link
to some code which seems to us like it should work, but
returns an error "return array has incorrect type":

http://pastebin.com/439375


Hope this is clearer, and thanks,
-Mike Rotondo

PS it looks from my end like my school's webmail client has
been spamming the list. If it is, I'm really sorry!


> On Sat, 2005-11-26 at 18:28 -0500, Mike Rotondo wrote:
> > We are writing a 2D particle engine and we would like to
> > render each  particle with gradually decreasing alpha
> > values. However, our original  image for the particles
> > has per-pixel alpha, so we can't use set-alpha.  So, we
> are going to have to modify each pixel's alpha value ith
> > Numeric,  it seems.
> 
> > [[pixel and (pixel * particle.life / particle.decay) for
> > pixl in row]  for row in array]
> 
> I'm a bit rusty with my surfarray mojo. I would think
> directly rendering the particles is going to win over
> creating an offscreen temporary. In fact it must be a
> pretty good speedup.
> 
> It looks like you may be dealing with one "particle" for
> every pixel? I don't see how just dividing pixel alphas
> will move anything around?
> 
> 
>