#!/usr/bin/perl
use Term::ANSIColor qw(:constants);
use termfusion;
set_clients_from_file("clients.fusion");
# set_clients( [
# 	      { host => "10.1.0.23", port => "4200" },
# 	      { host => "localhost", port => "4201" }
# 	      ]
# 	     );
connect_clients();
show_clients_info();

$cls="\e[H\e[2J";$home="\e[H"; #$xmax=79;$ymax=24;
($xmax,$ymax) = get_global_dimensions();
$off="\e[?25l";
$on="\e[?25h";
$text=" C3H." x 5 ."." x 15 .":)"."."x30 ."photon";

#print $cls;
clrscr;
$foo = 1;
$foobar="[ O W N E D ]";
init_phreak();

while(1)
{	printallcenter( $off.$home );
	for($xx=0;$xx<$xmax;$xx++)
	{$BLOAT[$xx][int($xx^int($foo))]=substr($text,$xx,1)||" "}
	if($mode==1){$foo--}else{$foo++}
	if($foo>$xmax){$mode=1}
	elsif($foo<1){$mode=0}
	for($ii=0;$ii<length($foobar);$ii++)
	{$a+=0.001;if($a>360){$a=0}
	$xbla=int(sin($a)*10)+int($xmax/4);
	$ybla=int(cos($a)*6)+int($ymax/2);
	$BLOAT[$xbla+$ii][$ybla]=substr($foobar,$ii,1)}
	$vieh_id++;if($vieh_id>2){$vieh_id=1}set_phreak($x_vieh++,$ymax-7,"vieh_".$vieh_id);if($x_vieh>$xmax+6){$x_vieh=-6}
	draw();
}

       draw();
sub draw
	{for($y=0;$y<$ymax;$y++)
        {$bloat="";if(int(rand()*5)==1){printallcenter( BOLD,WHITE)}else{printallcenter( GREEN)}
	for ($x=0;$x<$xmax;$x++){$bloat.=$BLOAT[$x][$y]||" ";$BLOAT[$x][$y]=" "}printsxy(0,$y,$bloat,1);}flushallsendbuffers();}#select(undef, undef,undef,0.2);clrscr;}

sub set_phreak
{	my $xx,$yy; @t_vieh=@{$_[2]};
	$foo_name="phreak_".$mode; $count=scalar(@t_vieh);
	for($yy=0;$yy<$count;$yy++)
	{	for($xx=0;$xx<length($t_vieh[$yy]);$xx++)
		{$BLOAT[$_[0]+$xx][$_[1]+$yy]=substr($t_vieh[$yy],$xx,1)}
	}
}


sub init_phreak
{
	@vieh_1=("",	"  \\\\\\" , 
			"  C()() <- fork(y)",
			"   \\_^",
			"   |",
			"   /\\",
			"  /  __",
			"  \\    "
	);

	@vieh_2=(	"  ///" , 
			" C()()",
			"  \\_^  <- fork(Y)",
			"   |",
			"   /\\",
			"   _|",
			"       \\");


}

