A superellipse is a geometric figure defined as the set of all points (x, y) with



 





|


x
a


|


n



+


|


y
b


|


n



=
1
,


{\displaystyle \left|{\frac {x}{a}}\right|^{n}\!+\left|{\frac {y}{b}}\right|^{n}\!=1,}




where n, a, and b are positive numbers.



Task
Draw a superellipse with n = 2.5, and a = b = 200




_Title "Super Ellipse"
 
Dim As Integer sw, sh
Dim As Single i
sw = 480: sh = 480
 
Screen _NewImage(sw, sh, 8)
Cls , 15
 
'Show different possible Super Ellipse shapes
Color 10
For i = 0.2 To 5.0 Step .1
    Call SuperEllipse(sw \ 2, sh \ 2, 200, 200, i, 80)
Next
 
'Show task specified Super Ellipse
Color 0
Call SuperEllipse(sw \ 2, sh \ 2, 200, 200, 2.5, 200)
Sleep
System
 
Sub SuperEllipse (cX As Integer, cY As Integer, wide As Integer, high As Integer, pow As Double, segs As Integer)
    Dim As Double power, inc, theta, cosTheta, sinTheta
    Dim As Integer x1, y1
    'Limit 'pow' to acceptable values
    If pow < .1 Then pow = .1
    If pow > 150 Then pow = 150
    power = 2 / pow - 1
    inc = 360.0 / segs * 0.0174532925199432957692369
    PSet (wide + cX, cY)
    For theta = inc To 6.28318530717958647692528 + inc Step inc
        cosTheta = Cos(theta): sinTheta = Sin(theta)
        x1 = wide * cosTheta * Abs(cosTheta) ^ power + cX
        y1 = high * sinTheta * Abs(sinTheta) ^ power + cY
        Line -(x1, y1)
    Next
End Sub