#!/usr/bin/perl

use termfusion;
set_clients( [
	      { host => "localhost", port => "2300" },
	      { host => "localhost", port => "2301" }
	      ],
	     [
	      { host => "localhost", port => "2302" },
	      { host => "localhost", port => "2303" }
	      ],
	     [
	      { host => "localhost", port => "2304" },
	      { host => "localhost", port => "2305" }
	      ]
	     );
connect_clients();
show_clients_info();
$xoffset=15;
$yoffset=8;
$xmax=43;
$ymax=9;
($xmax, $ymax) = get_global_dimensions();

$density=0.8;

$ANSI{clear}="\e[J";
$ANSI{home}="\e[H";
$ANSI{cls}=$ANSI{home}.$ANSI{clear};

# open(OUT,">/dev/stdout");

# print OUT $ANSI{cls};
clrscr;
chop($hostname=`hostname`);

while(1)
{
	rand_em();
	$linelen=$xmax-length($hostname)-1; $yo=$yoffset-1;
	#print OUT $ANSI{home}."\n"x$yo." "x$xoffset."/"."-"x$linelen."[$hostname]\n";
	printxy(0,0, $ANSI{home}."\n"x$yo." "x$xoffset."/"."-"x$linelen."[$hostname]\n" );
	draw();
	$linelen=$xmax;
	# print OUT " "x$xoffset."\\"."-"x$linelen."/";
}

disconnect_clients();


exit();

sub rand_em
{	my $xx,$xx;
	for($yy=0;$yy<$ymax;$yy++)
	{	for($xx=0;$xx<$xmax;$xx++)
		{	my $rnd=int(rand()*2*$density);
			if($rnd==1){$DOT[$xx][$yy]="1";}else{$DOT[$xx][$yy]=" ";}
		}
	}
}


sub draw
{	#print OUT $ANSI{home}; print OUT "\n" x $yoffset;
    printxy(0,0, $ANSI{home} );
    printxy(0,0, "\n" x $yoffset );
	for(my $y=0;$y<$ymax;$y++){#print OUT " "x$xoffset."|".make_line($y)."|\n";}	}
	    printxy(0,$y, " "x$xoffset."|".make_line($y)."|\n");}
	}

sub make_line
{my $xx,$ret=""; for($xx=0;$xx<$xmax;$xx++){$ret.=$DOT[$xx][$_[0]];} return $ret; }

sub set_dot
{	my $x=$_[0],$y=$_[0];
	$DOT[$x][$y]="*";			}

sub del_dot
{	my $x=$_[0],$y=$_[0];
	$DOT[$x][$y]=" ";	}

sub get_rand_one
{	return int($rnd=rand()*2);	}

