Superellipse: Difference between revisions
Content added Content deleted
Line 687: | Line 687: | ||
<lang Mathematica>ContourPlot[ |
<lang Mathematica>ContourPlot[ |
||
Abs[x/200]^2.5 + Abs[y/200]^2.5 == 1, {x, -200, 200}, {y, -200, 200}]</lang> |
Abs[x/200]^2.5 + Abs[y/200]^2.5 == 1, {x, -200, 200}, {y, -200, 200}]</lang> |
||
=={{header|Nim}}== |
|||
{{libheader|imageman}} |
|||
<lang Nim>import math |
|||
import imageman |
|||
const |
|||
Size = 600 |
|||
X0 = Size div 2 |
|||
Y0 = Size div 2 |
|||
Background = ColorRGBU [byte 0, 0, 0] |
|||
Foreground = ColorRGBU [byte 255, 255, 255] |
|||
proc drawSuperEllipse(img: var Image; n: float; a, b: int) = |
|||
var yList = newSeq[int](a + 1) |
|||
for x in 0..a: |
|||
let an = pow(a.toFloat, n) |
|||
let bn = pow(b.toFloat, n) |
|||
let xn = pow(x.toFloat, n) |
|||
let t = max(bn - xn * bn / an, 0.0) # Avoid negative values due to rounding errors. |
|||
yList[x] = pow(t, 1/n).toInt |
|||
var pos: seq[Point] |
|||
for x in countdown(a, 0): |
|||
pos.add (X0 + x, Y0 - yList[x]) |
|||
for x in 0..a: |
|||
pos.add (X0 - x, Y0 - yList[x]) |
|||
for x in countdown(a, 0): |
|||
pos.add (X0 - x, Y0 + yList[x]) |
|||
for x in 0..a: |
|||
pos.add (X0 + x, Y0 + yList[x]) |
|||
img.drawPolyline(true, Foreground, pos) |
|||
var image = initImage[ColorRGBU](Size, Size) |
|||
image.fill(Background) |
|||
image.drawSuperEllipse(2.5, 200, 200) |
|||
image.savePNG("super_ellipse.png", compression = 9)<lang> |
|||
=={{header|ooRexx}}== |
=={{header|ooRexx}}== |