Superellipse: Difference between revisions
Content added Content deleted
SqrtNegInf (talk | contribs) m (→{{header|Raku}}: redundant 'flat's) |
SqrtNegInf (talk | contribs) m (→{{header|Perl}}: a little nicer with v5.36) |
||
Line 1,062: | Line 1,062: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
{{trans|Raku}} |
{{trans|Raku}} |
||
<lang perl> |
<lang perl>use v5.36; |
||
my $b = 200; |
my($a, $b, $n, @q) = (200, 200, 2.5); |
||
my $n = 2.5; |
|||
# y in terms of x |
# y in terms of x |
||
sub y_from_x { |
sub y_from_x ($x) { int $b * abs(1 - ($x/$a) ** $n ) ** (1/$n) } |
||
my($x) = @_; |
|||
int $b * abs(1 - ($x / $a) ** $n ) ** (1/$n) |
|||
} |
|||
# find point pairs for one quadrant |
# find point pairs for one quadrant |
||
push @q, $_, y_from_x($_) for 0.. |
push @q, $_, y_from_x($_) for 0..$a; |
||
# Generate an SVG image |
|||
open $fh, '>', 'superellipse.svg'; |
open $fh, '>', 'superellipse.svg'; |
||
print $fh |
print $fh |
||
Line 1,085: | Line 1,080: | ||
'</svg>'; |
'</svg>'; |
||
sub pline { |
sub pline ($sx, $sy, @q) { |
||
(@q[2*$_] *= $sx, @q[1+2*$_] *= $sy) for 0 .. $#q/2; |
|||
⚫ | |||
for (0..$#q/2) { |
|||
$q[ 2*$_] *= $sx; |
|||
$q[1+2*$_] *= $sy; |
|||
} |
|||
⚫ | |||
style="fill:none;stroke:black;stroke-width:3" |
style="fill:none;stroke:black;stroke-width:3" |
||
transform="translate($a, $b)" />\n| |
transform="translate($a, $b)" />\n| |