[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] Need help with Surfarray
- To: pygame-users@xxxxxxxx
- Subject: [pygame] Need help with Surfarray
- From: Luke Arntson <cthulhu32@xxxxxxxxx>
- Date: Tue, 4 Oct 2005 04:14:34 -0700
- Delivered-to: archiver@seul.org
- Delivered-to: pygame-users-outgoing@seul.org
- Delivered-to: pygame-users@seul.org
- Delivery-date: Tue, 04 Oct 2005 07:14:46 -0400
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:mime-version:content-type; b=Efc6Mn4pYiPaFnaVYMC9UC1Hhob0w+TLatzURCF1VE/9bnAju8PEV+rRGafpHAnIJVb2qlkzRpLRLRbgrbbSNbwm3sNtfPV7qH1XCoBXefU9yzLt09gI+xv0zjs0L1xNkt9iUe72vRspJlBAoZacbBmJvZn3a2/Jfv9St49rcZA=
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
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