[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] Optimizing a noise-maker
- To: pygame-users <pygame-users@xxxxxxxx>
- Subject: [pygame] Optimizing a noise-maker
- From: "Rikard Bosnjakovic" <rikard.bosnjakovic@xxxxxxxxx>
- Date: Sat, 8 Jul 2006 22:48:13 +0200
- Delivered-to: archiver@seul.org
- Delivered-to: pygame-users-outgoing@seul.org
- Delivered-to: pygame-users@seul.org
- Delivery-date: Sat, 08 Jul 2006 16:48:22 -0400
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=REOLgB/qHnRJ6blzKc7+tb21ksqq5zhvPqvWc8MugPl91HxTqa0FvxSPN2A+w5W0w8QnLwiJBkufHVEJgguOHYB4zsj+2bBQTLqn1BI/RyzXela++CUHIiad8fClx7Fg9qYuB9G38ejLqjLP6aLvDsv34aAkMiN7U7PIPSnJefc=
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
At the end of each level for my game, the screen is supposed to become
"noisy" (like a TV with no show on). Currently, I'm doing this:
# plot a surface
from random import random as r
sa = surface.set_at
for x in xrange(_x):
for y in xrange(_y):
if int(r() * 10) > 5:
# plot white pixels
sa( (x, y), (255, 255, 255))
else:
# plot black pixels
sa( (x, y), (0, 0, 0))
Then, I'm flipping the surface three times to new surfaces, and
finally I animate the four by blitting them one at a time.
This works.
However, the game-screen is pretty big and the plotter-loop is awfully
slow. What I'm doing to speed it up is to plot the pixels on a surface
that's half the size of the full screen (i.e. screen = 640x480,
plot-screen = 320x240), then scaling it up just before using
transform.flip().
This works, too, but the pixels are due to the scale too big so it
doesn't look too god.
What I _really_ want to do instead of faking like this is to plot four
(preferably six-eight) independant screens and animate them all. Using
a set_at()-loop as above is unfortunately too slow for this.
I guess this can be solved using surfarray, but I'm not sure how. I
haven't learned how to use surfarrays yet.
Anyone got a solution?
--
- Rikard.