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

[pygame] Need help with Surfarray



So I'm currently working on making a plasma demo for python, I'm using a C source as basically my how-to.  The only problem is the C source of course has to use a for loop w/ a nested for loop, so in all there are 64000 calls.  In C++ this is absolutely no problem, however in Pygame this makes for a SLOW SLOW plasma effect.

I was on the IRC chat #pygame and Illume suggested using surfarray's for converting over the algorithm, however I've gotten it all over and now its going at < 1 fps.  I've already determined it is because of the for loops, so now I want to use Numerics to calculate the screen.

My question is can anyone help me convert this to a few simple surfarray functions?

        for c in range(0, 320):
            e=75+((sinc[(c << 1)+(a >> 1)]+sinc[c+(a << 1)]+(sinc[(c >> 1)+a] << 1)) >> 6)
            for d in range(0, 200):
                f=75+(((sinc[d+(a << 1)] << 1)+sinc[(d << 1)+(a >> 1)]+(sinc[d+a] << 1)) >> 5)
                screenpal[c-1][d] = ((e*f) >> 5);

basically if you want to make this easier on your eyes, lets call ALL the junk after e FIRSTSTEP, and all the junk after f SECONDSTEP, so

for c in range(0, 320):
   e = FIRSTSTEP(c)
   for d in range(0, 200):
      f = SECONDSTEP(d)

Now illume suggested to me that you could make e and f both surfarrays, then boil it down to screenpal = ((multiplyFunc(e, f) >> 5)) (or screenpal[:] = ((multiplyFunc(e,f) >> 5)) not sure which.)  I've been trying to figure out how you could declare e and f to satisfy this function, but I'm stuck.  I understand that Numerics allow you to automatically and efficiently go through arrays, 1D, 2D or 3D, but I do not get how I could turn e and f into surfarrays and use the equation in them.

-Thanks