Re: [Pdl-porters] SDL::Surface::new_from and PLot question
[email protected] (Chris Marshall)
| Newsgroups | perl.sdl.devel |
|---|---|
| Message-ID | <[email protected]> |
David Mertens wrote: > On Mon, Nov 16, 2009 at 4:51 PM, Kartik Thakore > <[email protected] <mailto:[email protected]>> 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);