Author Topic: Super Ellipse (Rosetta Code task)  (Read 3283 times)

0 Members and 1 Guest are viewing this topic.

Offline AndyA

  • Newbie
  • Posts: 73
    • View Profile
Super Ellipse (Rosetta Code task)
« on: April 13, 2021, 10:22:20 pm »
'https://rosettacode.org/wiki/Superellipse

I have an old one, but it's new for QB64.

I originally did this code in JustBasic back in about 2006(?), not sure exactly when but it's included in the JustBasic or Liberty Basic download.

As TempodiBasic showed the code before posting on Rosetta, here it is.

Code: QB64: [Select]
  1. _Title "Super Ellipse"
  2.  
  3. Dim As Integer sw, sh
  4. sw = 480: sh = 480
  5.  
  6. Screen _NewImage(sw, sh, 8)
  7. Cls , 15
  8.  
  9. 'Show different possible Super Ellipse shapes
  10. For i = 0.2 To 5.0 Step .1
  11.     Call SuperEllipse(sw \ 2, sh \ 2, 200, 200, i, 80)
  12.  
  13. 'Show task specified Super Ellipse
  14. Call SuperEllipse(sw \ 2, sh \ 2, 200, 200, 2.5, 200)
  15.  
  16. Sub SuperEllipse (cX As Integer, cY As Integer, wide As Integer, high As Integer, pow As Double, segs As Integer)
  17.     Dim As Double power, inc, theta, cosTheta, sinTheta
  18.     Dim As Integer x1, y1
  19.     'Limit 'pow' to acceptable values
  20.     If pow < .1 Then pow = .1
  21.     If pow > 150 Then pow = 150
  22.     power = 2 / pow - 1
  23.     inc = 360.0 / segs * 0.0174532925199432957692369
  24.     PSet (wide + cX, cY)
  25.     For theta = inc To 6.28318530717958647692528 + inc Step inc
  26.         cosTheta = Cos(theta): sinTheta = Sin(theta)
  27.         x1 = wide * cosTheta * Abs(cosTheta) ^ power + cX
  28.         y1 = high * sinTheta * Abs(sinTheta) ^ power + cY
  29.         Line -(x1, y1)
  30.     Next

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Super Ellipse (Rosetta Code task)
« Reply #1 on: April 15, 2021, 06:58:00 pm »
Hi AndyA
Cool that you joined to post solutions of Rosetta Code tasks!
Fine demo of SuperEllipse.
Programming isn't difficult, only it's  consuming time and coffee

Offline AndyA

  • Newbie
  • Posts: 73
    • View Profile
Re: Super Ellipse (Rosetta Code task)
« Reply #2 on: April 15, 2021, 10:59:17 pm »
Hi TempodiBasic

Was going to post directly to Rossetta, but decided let the QB64 community see them here before the world sees the code, just like you did.