[Tutor] Array pointers

Liam Clarke cyresse at gmail.com
Wed Jan 5 04:44:37 CET 2005


Sorry rephrase - 

So I have a list - 

[0,0,0,0,0,1,1,1,0,1,1,0,1,0]

I want to move all the 1's move to the right, 1 index at a time,
preserving any spacing.

i.e.

[1,0,0,0,0,1,1,1,0,1,1,0,1,0]

[0,1,0,0,0,0,1,1,1,0,1,1,0,1]

[0,0,1,0,0,0,0,1,1,1,0,1,1,1]

[0,0,0,1,0,0,0,0,1,1,1,1,1,1]

[0,0,0,0,1,0,0,0,1,1,1,1,1,1]

[0,0,0,0,0,1,0,0,1,1,1,1,1,1]

[0,0,0,0,0,0,1,0,1,1,1,1,1,1]

[0,0,0,0,0,0,0,1,1,1,1,1,1,1]


Now, I have a whole list of these lists.... and I create an array of them.
Is there a way to apply these changes wholescale without a large
calculation time?

I'm starting to think I'm going to have to go Cpp for this kind of
direct pixel tweaking stuff.
(640x480 (let alone 1024x768) is a lot of pixels to run through a for... loop)

So yeah, anyone had this before?

Regards,

Liam Clarke

On Tue, 4 Jan 2005 22:36:55 -0500, Byron Saltysiak <byronsalty at gmail.com> wrote:
> perhaps I don't understand the question exactly cause I don't remember
> the game but I think a nice way to do this would be to create a list
> of 5-tuples. Randomly generate a 5-tuple and push it onto the
> beginning of the list... pop the last off.
> 
> 
> On Wed, 5 Jan 2005 15:31:59 +1300, Liam Clarke <cyresse at gmail.com> wrote:
> > Hi all,
> >
> > Just playing with Pygame, attempting to build a version of Scorched
> > Earth if you remember it.
> >
> > I want to represent dirt, and so far I've come up with using a surface array -
> >
> > 0         64412    0         64412  64412
> > 0            0     64412     64412  64412
> > 0         64412    0             0        0
> > 64412  64412    0          64412    0
> >
> > Where a 0 indicates no pixel, 64412 is a representative pixel colour mapping.
> >
> > Now, that works OK, but I wanted to animate each pixel of dirt
> > falling,so pseudocode -
> >
> > if there's no pixel below, move value down one, unless value is at the
> > bottom of the column
> >
> > so -
> >
> > Frame 0 -
> >
> > 0         64412    0         64412  64412
> > 0            0     64412     64412  64412
> > 0         64412    0             0        0
> > 64412  64412    0          64412    0
> >
> > Frame 1:
> >
> > 0             0            0            0              0
> > 0         64412         0         64412       64412
> > 0         64412      64412     64412       64412
> > 64412  64412         0         64412          0
> >
> > 64412
> > 64412
> >    0
> >    0
> >
> > becoming
> >
> >    0
> > 64412
> > 64412
> >    0
> >
> > I envisage as a two step process  with the below as an intermediate.
> > This is wasteful, I'm sure.
> >
> > 64412
> >    0
> > 64412
> >    0
> >
> > Frame 2:
> >
> > 0             0            0            0              0
> > 0         64412         0         64412          0
> > 0         64412         0         64412       64412
> > 64412  64412       64412    64412       64412
> >
> > Frame 3+
> >
> > 0             0            0            0              0
> > 0         64412         0         64412          0
> > 0         64412         0         64412       64412
> > 64412  64412       64412    64412       64412
> >
> > Has anyone used Numeric for this kind of thing before? Any little
> > quirk of array mathematics  I could exploit?
> >
> > Or, should I shuffle this one to the back of the ideas folder for when
> > I've (if ever) learn Cpp?
> >
> > Regards,
> >
> > Liam Clarke
> >
> > PS
> >
> > --
> > 'There is only one basic human right, and that is to do as you damn well please.
> > And with it comes the only basic human duty, to take the consequences.
> > _______________________________________________
> > Tutor maillist  -  Tutor at python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
> 


-- 
'There is only one basic human right, and that is to do as you damn well please.
And with it comes the only basic human duty, to take the consequences.


More information about the Tutor mailing list