海龟图(For Fun)(修改版)

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

#!/usr/bin/perl
#turtle walk in his room, writeing or doing nothing
#$pen=1(write) 0(do nothing) -1(end program)
use warnings;
use strict;

my $MaxSize = 30; my @turtle;
my $Now = 0; my $Old = 0;
my $pen = 0; my $step = 0;

while ($pen = <STDIN>){
	chomp $pen; last if $pen == -1;	

	chomp ($step = <STDIN>);
	$Now = $Old + $step;
	if ($Old <= $Now){
		for ($Old..$Now){
			$turtle[$_] = 1 if $pen == 1;	
		}
	}else{
		for ($Now..$Old){
			$turtle[$_] = 1 if $pen == 1;
		}
	}

	chomp ($step = <STDIN>);
	$Old = $Now;
	if ($step >= 0){
		for (1..$step){
			$turtle[$Old+$_*$MaxSize] = 1 
				if $pen==1;
		}
	}else{
		for ($step..-1){
			$turtle[$Old+$_*$MaxSize] = 1 
				if $pen==1;
		}
	}

	$Old = $Now + $step * $MaxSize;
	die "error, out of room." 
		if $Old>=$MaxSize*$MaxSize || $Old<0;

	for (0..$MaxSize*$MaxSize-1){
		print "\n" if ($_%$MaxSize==0 && $_!=0);
		$turtle[$_] ? print "*  " : print "-  ";
	}
}