[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pygame] Surfarray slicing



> Enough praise, let's get down to the surfarray.
> What's not so easy is getting the hang of the slicing, especially as I've
> got a brain bug about the first index should be the row index and the second
> should be line index. Too much C++ I guess.

in reality, the Numeric arrays want to work like this. row first, then column.
at one point a long long time ago there was an interface that worked like
that, but in the end i just kept stumbling over the ordering, and decided
to stick with the X,Y format. Numeric makes it quite easy to work with either
with the transpose() call, which will return an array that references all the
same data as the original array, with the axis orders swapped.


> What I really wondered about is the surfarray tutorial, it says that to flip
> you can do like this:
> flipped = imgarray[:,-1:0:-1]
> But on my machine (and I guess most others too) this slices away the first
> line in the bitmap.

hmm. perhaps numeric has changed slightly in a newer/older version?
the "::-1" syntax is a lot cleaner, and i think i remember back to that
not working. i ended up needing to specify the range when using negative
increments. anyways, it seems your grasp on the slicing isn't that bad if
you've managed to roll your own solution.

i'll revisit this example before the pygame-1.1 release and see if i can
figure out what the situation really is.



> PS: What is the point of the pygame.surfarray.array_colorkey(<surface>)
> factory method any way?. It seems to create a mask of the visible portions
> of the bitmap.

it is basically a complement to the surfarray.array_alpha() function.
it returns an array that treats the surface colorkey like it was a
pixel-alpha channel. it's a quick way to find out which pixels are
"transparent" and which are "opaque". it could be applied to pixel-level
collision detection routines and that sort of fun.


good luck with your continued hacking :]


____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org