- 论坛徽章:
- 7
|
本帖最后由 rubyish 于 2016-03-28 22:22 编辑
shishi perl ~ 
biru:
perl abc.pl
abc.pl- #!/usr/bin/perl
- sub printC {
- my %setting = ( fg => '*', bg => ' ', size => 12, in => .3, eq => 1, @_ );
- my ( $size, $in, $fg, $bg ) = @setting{qw/size in fg bg/};
- my $R = ( $size - 4 ) / 3 / 2;
- my ( $move, $that, $this ) = ( 1 / 3, $R );
- my ( $R1, $R2, $R3 ) = ( $R - $in, $R + $in, $R + $move * 2 );
- my $mov2 = $setting{eq} ? $move / 2 : $move;
- $that -= $move for -1 .. $R / 2;
- $this = -$that - $move;
- for ( my $y = -$R3 ; $y <= $R3 ; $y += $move ) {
- for ( my $x = -$R3 ; $x <= $R3 ; $x += $mov2 ) {
- print $bg and next if $x > 0
- and $y > 0 && $y < $that || $y < 0 && $y > $this;
- my $r = sqrt( $x * $x + $y * $y );
- print $R1 < $r && $r < $R2 ? $fg : $bg;
- }
- print "\n";
- }
- }
- printC;
- printC size => 16;
- printC size => 16, in => .2;
- printC bg => 'C', fg => ' ', in => .2;
- printC size => 40, in => .16, bg => '#', fg => ' ';
- printC size => 40, in => .6, bg => '#', fg => ' ';
- printC fg => '# ', bg => '. ', in => .2;
- printC fg => '# ', bg => '. ', in => .2, eq => 0;
- printC fg => '#', bg => '.', in => .2, eq => 0;
复制代码 |
|