in reply to How do I get my ascii tile code to refresh without looking weird
The main difference to your approach is that it sets up the entire image as an array of lines instead of printing every character as it comes along. This is done by the sub image(). It uses the core module Time::HiRes to set the frame rate with sub-second resolution. The "@" is moved through a sample of six positions and back again.
Annouse Time::HiRes qw( sleep); use constant SIZE => 15; my @map = do { my @ones = ( 1) x SIZE; my @mixed = ( 1, ( 0) x (SIZE - 2), 1); ( [ @ones], map( [ @mixed], 1 .. SIZE - 2), [ @ones], ); }; my @positions = ( [ 8, 4], [ 9, 5], [ 10, 6], [10, 7], [10, 8], [ 10, +9]); my $clear_string = `clear`; for my $pos ( @positions, reverse @positions ) { print $clear_string; print image( \ @map, @$pos); sleep 0.2; } exit; sub image { my ( $map, $x, $y) = @_; my @image = map join( '', map $_ ? '* ' : ' ', @$_), @$map; $_ .= "\n" for @image; substr( $image[ $y], 2*$x, 1) = '@'; @image; }
|
---|