diff options
| author | James Smith <baggy@baggy.me.uk> | 2021-08-03 16:36:32 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-03 16:36:32 +0100 |
| commit | 14b4f82a65fdacfa264c1499c025e8a7d476daf2 (patch) | |
| tree | b07032374594c2c693ad94bde6c911a77d4da452 | |
| parent | 6e9ee61e609c70c4e559a61a01261c1d5a3153cb (diff) | |
| download | perlweeklychallenge-club-14b4f82a65fdacfa264c1499c025e8a7d476daf2.tar.gz perlweeklychallenge-club-14b4f82a65fdacfa264c1499c025e8a7d476daf2.tar.bz2 perlweeklychallenge-club-14b4f82a65fdacfa264c1499c025e8a7d476daf2.zip | |
Update ch-1.pl
| -rw-r--r-- | challenge-124/james-smith/perl/ch-1.pl | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/challenge-124/james-smith/perl/ch-1.pl b/challenge-124/james-smith/perl/ch-1.pl index 34cdf2cd64..4340825447 100644 --- a/challenge-124/james-smith/perl/ch-1.pl +++ b/challenge-124/james-smith/perl/ch-1.pl @@ -16,6 +16,7 @@ my $cross = @ARGV ? shift @ARGV : $radius; $cross++ if $cross&1; ### A simple one to render the cross as drawin the question... +### This is what we show if the radius (first parameter is 0) unless($radius) { my @pts = qw(-1 3 4 5 5 5 5 5 4 3 -1 0 0 0 -1 0 0); @@ -32,21 +33,22 @@ unless($radius) { my @a = map { ' ' x ($radius*2+1) } 0..$radius*2+$cross; ## Now we draw the circle... -foreach my $x (0 .. ceil($radius*0.71)) { - my $y = int sqrt( ($radius-.5)**2 - $x**2 ); - substr $a[ $radius - $x ],$radius-$y,1,'^'; - substr $a[ $radius + $x ],$radius-$y,1,'^'; - substr $a[ $radius - $x ],$radius+$y,1,'^'; - substr $a[ $radius + $x ],$radius+$y,1,'^'; - substr $a[ $radius - $y ],$radius-$x,1,'^'; - substr $a[ $radius + $y ],$radius-$x,1,'^'; - substr $a[ $radius - $y ],$radius+$x,1,'^'; - substr $a[ $radius + $y ],$radius+$x,1,'^'; +foreach my $x ( 0 .. ceil($radius*0.71) ) { ## Only need to do 45 deg {X = r/sqrt(2)} + my $y = int sqrt( ($radius-.5)**2 - $x**2 ); ## Do a circle of radius r-.5 as we want + ## to draw the mid point of the squares + substr $a[ $radius - $x ], $radius-$y, 1, '^'; # W -> NW + substr $a[ $radius + $x ], $radius-$y, 1, '^'; # W -> SW + substr $a[ $radius - $x ], $radius+$y, 1, '^'; # E -> NE + substr $a[ $radius + $x ], $radius+$y, 1, '^'; # E -> SE + substr $a[ $radius - $y ], $radius-$x, 1, '^'; # N -> NW + substr $a[ $radius + $y ], $radius-$x, 1, '^'; # S -> SW + substr $a[ $radius - $y ], $radius+$x, 1, '^'; # N -> NE + substr $a[ $radius + $y ], $radius+$x, 1, '^'; # S -> SE } ## And the two parts of the cross... -substr $a[2*$radius+$_],$radius,1,'^' foreach 0..$cross; -substr $a[2*$radius+$cross/2],$radius-$cross/2,$cross+1,'^'x($cross+1); +substr $a[2*$radius+$_], $radius, 1, '^' foreach 0..$cross; +substr $a[2*$radius+$cross/2], $radius-$cross/2, $cross+1, '^' x ($cross+1); ### Finally we render the canvas... say $_ foreach @a; |
