use strict; use warnings; use PDL; use PDL::IO::Pic; my ($width, $height, $framecount, $xvel, $maxheight, $ballsize) = (320, 80, 100, 15, 60, 8); my $frames = zeros byte, $width, $height, $framecount; my $coords = yvals(3, $framecount); # coords for drawing ball, all val=frameno my ($xcoords, $ycoords) = map $coords->slice($_), 0, 1; $xcoords *= $xvel; # moves $xvel pixels/frame $xcoords .= $width - abs(($xcoords % (2*$width)) - $width); # back and forth my $sqrtmaxht = sqrt $maxheight; $ycoords .= indx($maxheight - ((($ycoords % (2*$sqrtmaxht)) - $sqrtmaxht)**2)); my $val = pdl(byte,250); # start with white $frames->range($coords, [$ballsize,$ballsize,1], 't') .= $val; $frames = $frames->dummy(0, 3)->copy; # now make the movie $frames->wmpeg('bounce.gif'); # or bounce.mp4, ffmpeg deals OK #### perl scriptname.pl && animate bounce.gif