Author Topic: Peano Curve (Rosetta Code task)  (Read 3153 times)

0 Members and 1 Guest are viewing this topic.

Offline AndyA

  • Newbie
  • Posts: 73
    • View Profile
Peano Curve (Rosetta Code task)
« on: April 13, 2021, 11:42:40 pm »
https://rosettacode.org/wiki/Peano_curve

'==================================================
Task
Produce a graphical or ASCII-art representation of a Peano curve of at least order 3.
'==================================================

Code: QB64: [Select]
  1. _Title "Peano Curve"
  2. Const wide = 243 'must be a power of 3
  3. Dim As Integer sw, sh
  4. sw = 729: sh = sw
  5. Screen _NewImage(sw, sh, 8)
  6. Cls , 15: Color 0: PSet (0, 0)
  7.  
  8. Call Peano(0, 0, wide, 0, 0)
  9.  
  10.  
  11. Sub Peano (x As Integer, y As Integer, lg As Integer, p As Integer, q As Integer)
  12.     Dim As Integer iX, iY, iL
  13.     iX = x: iY = y: iL = lg
  14.     If iL = 1 Then
  15.         Line -(iX * 3, iY * 3)
  16.         Exit Sub
  17.     End If
  18.     iL = iL \ 3
  19.     Call Peano(iX + (2 * p * iL), iY + (2 * p * iL), iL, p, q)
  20.     Call Peano(iX + ((p - q + 1) * iL), iY + ((p + q) * iL), iL, p, 1 - q)
  21.     Call Peano(iX + iL, iY + iL, iL, p, 1 - q)
  22.     Call Peano(iX + ((p + q) * iL), iY + ((p - q + 1) * iL), iL, 1 - p, 1 - q)
  23.     Call Peano(iX + (2 * q * iL), iY + (2 * (1 - q) * iL), iL, p, q)
  24.     Call Peano(iX + ((1 + q - p) * iL), iY + ((2 - p - q) * iL), iL, p, q)
  25.     Call Peano(iX + (2 * (1 - p) * iL), iY + (2 * (1 - p) * iL), iL, p, q)
  26.     Call Peano(iX + ((2 - p - q) * iL), iY + ((1 + q - p) * iL), iL, 1 - p, q)
  27.     Call Peano(iX + (2 * (1 - q) * iL), iY + (2 * q * iL), iL, 1 - p, q)