Superellipse: Difference between revisions

m
 
(7 intermediate revisions by 5 users not shown)
Line 267:
closegraph();
}</syntaxhighlight>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
 
[[File:DelphiSuperElipse.png|frame|none]]
<syntaxhighlight lang="Delphi">
 
procedure DrawSuperElipse(Image: TImage);
var Points: array of double;
const N = 2.5;
const Border = 10;
var A: integer;
var X: integer;
var W2,H2: integer;
begin
{Make elipse size and position based on window size}
W2:=Image.Width div 2;
H2:=Image.Height div 2;
A:=Min(W2,H2)-Border;
{Fill array with points}
SetLength(Points,A);
for X:=0 to High(Points) do
Points[X]:=Power(Power(A, N) - Power(X, N), 1 / N);
 
Image.Canvas.Pen.Color:=clRed;
Image.Canvas.Pen.Width:=2;
 
{Starting point}
Image.Canvas.MoveTo(W2+High(Points),trunc(H2-Points[High(Points)]));
{Draw Upper right}
for X:=High(Points) downto 0 do
begin
Image.Canvas.LineTo(W2+x, trunc(H2-Points[X]))
end;
{Draw Upper left}
for X:=0 to High(Points) do
begin
Image.Canvas.LineTo(W2-X, trunc(H2-Points[X]))
end;
 
{Draw Lower left}
for X:=High(Points) downto 0 do
begin
Image.Canvas.LineTo(W2-X, trunc(H2+Points[X]))
end;
{Draw Lower right}
for X:=0 to High(Points) do
begin
Image.Canvas.LineTo(W2+X, trunc(H2+Points[X]))
end;
{Connect back to beginning}
Image.Canvas.LineTo(W2+High(Points),trunc(H2-Points[High(Points)]));
Image.Repaint;
end;
 
 
</syntaxhighlight>
{{out}}
<pre>
Elapsed Time: 13.282 ms.
</pre>
 
=={{header|EasyLang}}==
[https://easylang.dev/show/#cod=Vc1LCsMgFEbh+V3FGbYJGLHYUV2MtqERgikomOw+2Bft6L9wPrgJh1FWfFutJbx3jmms8VYmtDJSpziPFC6O01kLsOJ4LBUfMtclUzgYBtKRDk9Hjvf0Ck1vPzrH9KfDRz9D0+03KwOWHqvZvmerhd6hlRUlOw== Run it]
<syntaxhighlight>
n = 2.5
a = 200
b = 200
linewidth 0.2
while t <= 360
x = pow abs cos t (2 / n) * a * sign cos t
y = pow abs sin t (2 / n) * b * sign sin t
line x / 5 + 50 y / 5 + 50
t += 0.5
.
</syntaxhighlight>
 
=={{header|EchoLisp}}==
Line 715 ⟶ 792:
| superellipse
</syntaxhighlight>
{{output}}
Similar to [https://github.com/SqrtNegInf/Rosettacode-Perl-Smoke/blob/master/ref/superellipse.svg Perl solution].
 
=={{header|Julia}}==
Line 824 ⟶ 903:
}
}</syntaxhighlight>
 
=={{header|Lambdatalk}}==
 
Drawing four super-ellipses, a circle, a rounded square, a square, an astroid.
 
<syntaxhighlight lang="scheme">
{def superellipse
{def sgn {lambda {:n} {if {< :n 0} then - else +}}}
 
{lambda {:a :n :t}
{let { {:a :a} {:n {/ 2 :n}}
{:cost {cos {* {PI} :t}}}
{:sint {sin {* {PI} :t}}}
} {sgn :cost}{* :a {pow {abs :cost} :n}}
{sgn :sint}{* :a {pow {abs :sint} :n}}
}}}
-> superellipse
</syntaxhighlight>
 
We use SVG and the lib_plot library defining the SVG, AXES, stroke functions to draw four superellipses, a circle, a rounded square (as required), a square and an astroid.
 
<syntaxhighlight lang="scheme">
{{SVG 600 600}
{g {AXES 600 600}
{polyline
{@ points="{S.map {superellipse 200 2.5} {S.serie -1 1.01 0.01}}"
{stroke #f00 4}}}
{polyline
{@ points="{S.map {superellipse 200 0.5} {S.serie -1 1.01 0.01}}"
{stroke #0f0 4}}}
{polyline
{@ points="{S.map {superellipse 200 1} {S.serie -1 1.01 0.01}}"
{stroke #888 2}}}
{polyline
{@ points="{S.map {superellipse 200 2} {S.serie -1 1.01 0.01}}"
{stroke #888 2}}}
}}
</syntaxhighlight>
 
The output can be seen in http://lambdaway.free.fr/lambdawalks/?view=super_ellipse
 
=={{header|Liberty BASIC}}==
Line 1,695 ⟶ 1,814:
{{libheader|DOME}}
Uses Go's drawing code but produces a more complex image.
<syntaxhighlight lang="ecmascriptwren">import "graphics" for Canvas, Color, Point
 
class Game {
2,049

edits