[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] PixelArray vs SurfArray
Does the code change anything? I've had no insights on how to use either PixelArray or SurfArray.
On Sat, Mar 7, 2009 at 1:48 PM, Ian Mallett <geometrian@xxxxxxxxx> wrote:
Actually,
I think it might be more useful to go with what I'm trying to do. I'm
not sure how I would go optimizing it--I don't know if it can be.
Here's the code I want to optimize using surfarray/whatever:
for x in xrange(size):
for y in xrange(size):
value = permutation[(y+permutation[x]) & (size-1)]
red = grad3[value&15][0]*127.5 + 127.5
green = grad3[value&15][1]*127.5 + 127.5
blue = grad3[value&15][2]*127.5 + 127.5
surf.set_at((x,y),map(rndint,[red,green,blue]))
Note that:
rndint = int(round(x))
that:
grad3 = [[ 0, 1, 1],[ 0, 1,-1],[ 0,-1, 1],[ 0,-1,-1],
[ 1, 0, 1],[ 1, 0,-1],[-1, 0, 1],[-1, 0,-1],
[ 1, 1, 0],[ 1,-1, 0],[-1, 1, 0],[-1,-1, 0],
[ 1, 0,-1],[-1, 0,-1],[ 0,-1, 1],[ 0, 1, 1]]
and that:
permutation = []
for value in xrange(size):
permutation.append(value)
random.shuffle(permutation)
Any ideas for optimization?
Thanks,
Ian
Ian