All pastes #523315 Raw Edit

Anonymous

public text v1 · immutable
#523315 ·published 2007-05-30 19:18 UTC
rendered paste body
#!/usr/bin/perl -w

use POSIX;
use Term::Cap;
use Time::HiRes qw( usleep );


my $setterm = '/usr/bin/setterm';

my $x = 40;
my $y = 12;
my $xdir = 1;
my $ydir = 1;

my $maxx = 77;
my $maxy = 22;

my $tailcount = 15;

my $xx = 0;
my $yy = 0;

#system("$setterm -cursor off");

init();
clear_screen();

while ( 1 ) {
  gotoxy($x,$y);

  print ".";

  usleep(20000);

  if (@xtail >= $tailcount) {
    $xx = shift(@xtail);
    $yy = shift(@ytail);

    gotoxy($xx,$yy);
    print " ";
  }

  push(@xtail,$x);
  push(@ytail,$y);


  $xdir = -1 if ($x > $maxx);
  $xdir = 1 if ($x < 1);
  $ydir = -1 if ($y > $maxy);
  $ydir = 1 if ($y < 1);

  $x = $x + $xdir;
  $y = $y + $ydir;

  gotoxy(0,0);
  print "X: $x, $xdir, $xx / Y: $y, $ydir, $yy   ";
}

sub clear_screen { $tcap->Tputs('cl', 1, *STDOUT) } 

sub gotoxy {
    my($x, $y) = @_;
    $tcap->Tgoto('cm', $x, $y, *STDOUT);
} 

sub init { 
    $| = 1;
    #$delay = (shift() || 0) * 0.005;
    my $termios = POSIX::Termios->new();
    $termios->getattr;
    my $ospeed = $termios->getospeed;
    $tcap = Term::Cap->Tgetent ({ TERM => undef, OSPEED => $ospeed });
    $tcap->Trequire(qw(cl cm cd));
}