Superellipse: Difference between revisions
m
syntax highlighting fixup automation
SqrtNegInf (talk | contribs) m (→{{header|Perl}}: a little nicer with v5.36) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 16:
=={{header|Action!}}==
{{libheader|Action! Tool Kit}}
<
PROC Superellipse(INT x0 BYTE y0 REAL POINTER n BYTE a)
Line 73:
DO UNTIL CH#$FF OD
CH=$FF
RETURN</
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Superellipse.png Screenshot from Atari 8-bit computer]
Line 79:
=={{header|Ada}}==
{{libheader|SDLAda}} Brute force calculation.
<
with SDL.Video.Windows.Makers;
Line 151:
Window.Finalize;
SDL.Finalise;
end Superelipse;</
=={{header|AutoHotkey}}==
Requires [https://www.autohotkey.com/boards/viewtopic.php?t=6517 Gdip Library]
<
a := 200
b := 200
Line 234:
ExitApp
Return
;----------------------------------------------------------------</
=={{header|C}}==
Interactive program to draw a SuperEllipse. Requires the [http://www.cs.colorado.edu/~main/bgi/cs1300/ WinBGIm] library.
<syntaxhighlight lang="c">
#include<graphics.h>
#include<stdio.h>
Line 266:
closegraph();
}</
=={{header|EchoLisp}}==
Link to the super-ellipse [http://www.echolalie.org/echolisp/images/super-ellipse.png image].
<
(lib 'plot)
(define (eaxpt x n) (expt (abs x) n))
Line 277:
(plot-xy Ellie -400 -400)
→ (("x:auto" -400 400) ("y:auto" -400 400))
</syntaxhighlight>
=={{header|FreeBASIC}}==
<
' compile with: fbc -s console
Line 334:
Print : Print "hit any key to end program"
Sleep
End</
=={{header|Go}}==
{{libheader|Go Graphics}}
<
import (
Line 382:
superEllipse(dc, 2.5, 200)
dc.SavePNG("superellipse.png")
}</
{{out}}
Line 391:
=={{header|Haskell}}==
Use the [https://github.com/ghcjs/ghcjs ghcjs compiler ] to compile to JavaScript that runs in a browser. The [https://github.com/reflex-frp/reflex-dom reflex-dom ] library is used to help with SVG rendering and input.
<
import Reflex
import Reflex.Dom
Line 491:
-- At end to avoid Rosetta Code unmatched quotes problem.
elSvgns :: forall t m a. MonadWidget t m => Text -> Dynamic t (Map Text Text) -> m a -> m (El t, a)
elSvgns = elDynAttrNS' (Just "http://www.w3.org/2000/svg")</
Link to live demo: https://dc25.github.io/superEllipseReflex/
Line 500:
We will fill the ellipse so that we do not have to worry about the size and shape of our pixels:
<
'n a b'=. y
1 >: ((n^~a%~]) +&|/ n^~b%~]) i:x
Line 506:
require'viewmat'
viewmat 300 selips 2.5 200 200</
=={{header|Java}}==
[[File:superellipse.png|300px|thumb|right]]
{{works with|Java|8}}
<
import java.awt.geom.Path2D;
import static java.lang.Math.pow;
Line 636:
});
}
}</
=={{header|JavaScript}}==
<
var n = 2.5, a = 200, b = 200, ctx;
Line 662:
}
}
</syntaxhighlight>
=={{header|Julia}}==
<
@assert n > 0 && a > 0 && b > 0
na = 2 / n
Line 684:
x, y = superellipse(2.5, 200, 200)
println(lineplot(x, y))</
<pre>
┌────────────────────────────────────────┐
Line 709:
=={{header|Kotlin}}==
The following is based on the Java entry but dispenses with the grid and slider as these aren't really part of the task.
<
import java.awt.*
Line 771:
}
}
}</
=={{header|Liberty BASIC}}==
Reworked the Julia version to work and added a loop with a spread on n values.
<syntaxhighlight lang="lb">
[start]
nomainwin
Line 820:
if x=0 then sign=0
end function
</syntaxhighlight>
=={{header|Lua}}==
Scale of a and b were reduced to facilitate an ASCII solution:
<
local bitmap = {
init = function(self, w, h, value)
Line 862:
bitmap:init(80, 60, "..")
bitmap:superellipse(40, 30, 2.5, 38, 28, "[]")
bitmap:render()</
{{out}}
<pre style="font-size:25%">................................................................................................................................................................
Line 928:
=={{header|Maple}}==
The built-in command ImplicitPlot accepts an equation in 2 variables:
<
=={{header|Mathematica}}/{{header|Wolfram Language}}==
The built-in function ContourPlot accepts and equation in 2 variables and creates the desired plot
<
=={{header|Nim}}==
{{libheader|imageman}}
<
import imageman
Line 972:
image.fill(Background)
image.drawSuperEllipse(2.5, 200, 200)
image.savePNG("super_ellipse.png", compression = 9)</
=={{header|ooRexx}}==
Line 982:
black 280,280,4</pre>
<
* Create a BMP file showing a few super ellipses
**********************************************************************/
Line 1,058:
Return
::requires rxMath library</
=={{header|Perl}}==
{{trans|Raku}}
<
my($a, $b, $n, @q) = (200, 200, 2.5);
Line 1,085:
style="fill:none;stroke:black;stroke-width:3"
transform="translate($a, $b)" />\n|
}</
[https://github.com/SqrtNegInf/Rosettacode-Perl5-Smoke/blob/master/ref/superellipse.svg Superellipse] (offsite image)
Line 1,092:
{{libheader|Phix/online}}
You can run this online [http://phix.x10.mx/p2js/Superellipse.htm here].
<!--<
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\Superellipse.exw
Line 1,167:
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<!--</
=={{header|Processing}}==
{{trans|C}}
<
//Aamrun, 29th June 2022
Line 1,195:
}
</syntaxhighlight>
=={{header|Python}}==
<
# Superellipse drawing in Python 2.7.9
# pic can see at http://www.imgup.cz/image/712
Line 1,225:
plt.title("Superellipse with parameter "+str(n))
plt.show()
</syntaxhighlight>
=={{header|QB64}}==
<
Dim As Integer sw, sh
Line 1,264:
Line -(x1, y1)
Next
End Sub</
=={{header|QBasic}}==
<
CLS
a = 200
Line 1,282:
t = t + .02
LINE -(xp, yp), 1, BF
NEXT i</
=={{header|Racket}}==
<
(require plot)
#;(plot-new-window? #t)
Line 1,295:
(plot (isoline (superellipse 200 200 2.5) 1
-220 220 -220 220))</
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku"
# y in terms of x
Line 1,319:
style="fill:none;stroke:black;stroke-width:3"
transform="translate({a}, {b})" />\n|
}</
[https://github.com/SqrtNegInf/Rosettacode-Perl6-Smoke/blob/master/ref/superellipse.svg Superellipse] (offsite image)
Line 1,326:
Here you can see a picture: http://austria-forum.org/af/User/Pachl%20Walter
<
* Create a BMP file showing a few super ellipses
**********************************************************************/
Line 1,487:
r=r/ln(b)
Numeric Digits (prec)
Return r+0</
=={{header|Scala}}==
===Java Swing Interoperability===
<
import java.awt.geom.Path2D
import java.util
Line 1,594:
})
}</
=={{header|Sidef}}==
{{trans|Raku}}
<
a = 200,
b = 200,
Line 1,631:
].each { .print }
say '</svg>'</
=={{header|Stata}}==
<
sca b=200
sca n=2.5
twoway function y=b*(1-(abs(x/a))^n)^(1/n), range(-200 200) || function y=-b*(1-(abs(x/a))^n)^(1/n), range(-200 200)</
=={{header|Wren}}==
{{libheader|DOME}}
Uses Go's drawing code but produces a more complex image.
<
class Game {
Line 1,699:
}
}
}</
=={{header|XPL0}}==
<
real X, Y; int IX, IY;
Line 1,724:
IX:= IX+1;
until IX >= IY;
]</
{{out}}
Line 1,732:
=={{header|Yabasic}}==
<
backcolor 0,0,0
clear window
Line 1,747:
t=t+.02
line to xp, yp
next i</
=={{header|zkl}}==
Uses the PPM class from http://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm#zkl
[[File:SuperEllipse.zkl.jpg|250px|thumb|right]]
<
a,p:=(plot.w/2).toFloat(), 1.0/n; // just calculate upper right quadrant
foreach x in ([0.0 .. a]){
Line 1,760:
}
plot
}</
<
plot:=PPM(w+1,h+1,0x909090); plot.cross(w/2,h/2);
foreach n in ([0.01..1, 0.14]){ superEllipse(plot,n, 0x0000bb) }// 0-1: blue
Line 1,767:
foreach n in ([2.0..10, 1.4]) { superEllipse(plot,n, 0xff0000) }// 2+: red
plot.writeJPGFile("superEllipse.jpg");</
|