Superellipse: Difference between revisions
Content added Content deleted
(Added Processing implementation) |
SqrtNegInf (talk | contribs) (→{{header|Raku}}: simplified) |
||
Line 1,310: | Line 1,310: | ||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
(formerly Perl 6) |
(formerly Perl 6) |
||
⚫ | |||
{{works with|rakudo|2018-10}} |
|||
Generate an svg image to STDOUT. Redirect into a file to capture it. |
|||
⚫ | |||
constant b = 200; |
|||
constant n = 2.5; |
|||
# y in terms of x |
# y in terms of x |
||
sub y ($x) { |
sub y ($x) { floor b × (1 - ($x / a).abs ** n ) ** (1/n) } |
||
# find point pairs for one quadrant |
# find point pairs for one quadrant |
||
my @q = flat map -> \x { x, y(x) }, ( |
my @q = flat map -> \x { x, y(x) }, ^(a+1); |
||
my $out = open('superellipse.svg', :w); |
|||
# Generate an SVG image |
|||
⚫ | |||
INIT say qq:to/STOP/; |
|||
⚫ | |||
<?xml version="1.0" standalone="no"?> |
|||
⚫ | |||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> |
|||
⚫ | |||
⚫ | |||
⚫ | |||
STOP |
|||
'</svg>' |
|||
; |
|||
.put for |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
sub pline (@q) { |
sub pline (@q) { |
||
⚫ | |||
qq:to/END/; |
|||
style="fill:none;stroke:black;stroke-width:3" |
|||
⚫ | |||
transform="translate({a}, {b})" />\n| |
|||
END |
|||
}</lang> |
}</lang> |
||
[https://github.com/SqrtNegInf/Rosettacode-Perl6-Smoke/blob/master/ref/superellipse.svg Superellipse] (offsite image) |
[https://github.com/SqrtNegInf/Rosettacode-Perl6-Smoke/blob/master/ref/superellipse.svg Superellipse] (offsite image) |