Kartik Thakore wrote:
Um how do I get the x,y coords and the data you want me to put there from $sdl?

Here is a more complete program:

  use PDL;
  use PDL::NiceSlice;

  # Uncomment this if you can use TriD to display
  # use PDL::Graphics::TriD;

  # declare/init variables
  my $sdl = zeroes(byte, 3, 10, 11);
  my $life = zeroes(byte, 10, 11);
  my $n;

  # init Life piddle with a "glider"
  $life(1:3,1:3) .= pdl( [1,1,1],
                         [0,0,1],
                         [0,1,0] );

  while (1) {

     # calculate the number of neighbors
     $n = 
($life->range(ndcoords($life)-1,3,3)->reorder(2,3,0,1)->sumover->sumover)-$life;

     # propagate the cells that live in the next step
     $life = ((($n == 2) + ($n == 3))* $life) + (($n==3) * !$life);

     # copy data to an RGB byte array for SDL to access
     $sdl .= $life(*3);

     # display the timestep (uncomment if you have TriD)
     # nokeeptwiddling3d();
     # imagrgb $sdl;

     # this is a perl reference to a string containing the PDL data
     $sdl_dataref = $sdl->get_dataref;
     # print "\$sdl data is " . length($$sdl_dataref) . " bytes long\n";
  }

The $sdl_dataref is a perl reference to a string value containing
the packed representation of the PDL, that is the contents of the
string is the binary array data of the PDL, in this case a 10x11
array of RGB bytes ordered in memory for each row of 10 pixels as:

Byte#:  0  1  2  3  4  5  6  7  8  9 10 11     27 28 29
       R0 B0 G0,R1 B1 G1,R2 B2 G2,R3 B3 G3,...,R9 B9 G9  (row  0)

Byte#: 30 31 32 33 34 35 36 37 38 39 40 41     57 58 59
       R0 B0 G0,R1 B1 G1,R2 B2 G2,R3 B3 G3,...,R9 B9 G9  (row  1)

Byte#: 60 61 62 63 64 65 66 67 68 69 70 71     87 88 89
       R0 B0 G0,R1 B1 G1,R2 B2 G2,R3 B3 G3,...,R9 B9 G9  (row  2)
        .
        .
        .
Byte#:300301302303304305306307308309310311    327328329
       R0 B0 G0,R1 B1 G1,R2 B2 G2,R3 B3 G3,...,R9 B9 G9  (row 10)

--Chris

On Mon, Nov 16, 2009 at 7:13 PM, Chris Marshall <c...@alum.mit.edu <mailto:c...@alum.mit.edu>> wrote:

    David Mertens wrote:

        On Mon, Nov 16, 2009 at 4:51 PM, Kartik Thakore
        <thakore.kar...@gmail.com <mailto:thakore.kar...@gmail.com>
        <mailto:thakore.kar...@gmail.com
        <mailto:thakore.kar...@gmail.com>>> wrote:

           How do I update this?  like animation?

           while(1)
           {

             $pdl_memory->get_dataref();

           }


        Yeah, you know, I used a terrible variable name for that piddle.
         Let's try this:
         --------%<--------

        use PDL;
        use PDL::NiceSlice;

        # Allocate a 10x10 array for rgb.  I think that only the zeroes
        function # allows you to declare a piddle with a specific data type



    perldl> ?sequence
    Module  PDL::Basic
     sequence
       Create array filled with a sequence of values

        $a = sequence($b); $a = sequence [OPTIONAL TYPE], @dims;

       etc. see zeroes.

        perldl> p sequence(10)
        [0 1 2 3 4 5 6 7 8 9]
        perldl> p sequence(3,4)
        [
         [ 0  1  2]
         [ 3  4  5]
         [ 6  7  8]
         [ 9 10 11]
        ]

       Docs from /c/site/perl/lib_pdl/cygwin-thread-multi-64int/PDL/Basic.pm

    So you can do:

    perldl> $a = sequence(byte, 3, 10, 10);

    perldl> p $a->info
    PDL: Byte D [3,10,10]


     > my $pdl = zeroes(byte, 3, 10, 10);

        # Set values. Use in place to be sure we don't get another
        allocation, which may be the wrong type.
        # Note that the sequence wraps back to zero after hitting 256,
        because they're bytes!
        $pdl->inplace->sequence;

        # Now for a really silly animation - turn all the pixels white
        for (my $i = 0; $i < 300; $i++) {
         $pdl()->clump(-1)->($i) = 255;
         # Do something with piddle data here.
        }

        --------%<--------

        Is that a bit clearer?  Does anybody have a better sample?


    You could use the PDL life example of threading that Matt posted
    earlier today.  Just make an empty $sdl piddle with dims [3,N,M],
    a $life piddle with shape [N,M] for the life updates, init $life,
    then copy each update from the $life to the $sdl, maybe like:

    $sdl .= $life(*3);



------------------------------------------------------------------------


No virus found in this incoming message.
Checked by AVG - www.avg.com Version: 8.5.425 / Virus Database: 270.14.68/2507 - Release Date: 11/16/09 19:53:00


Reply via email to