Author Topic: Fractal Tree (Rosetta Code task)  (Read 3001 times)

0 Members and 1 Guest are viewing this topic.

Offline AndyA

  • Newbie
  • Posts: 73
    • View Profile
Fractal Tree (Rosetta Code task)
« on: April 13, 2021, 10:30:01 pm »
https://rosettacode.org/wiki/Fractal_tree


The task is described as follows:
'=================================================
Generate and draw a fractal tree.

Draw the trunk
At the end of the trunk, split by some angle and draw two branches
Repeat at the end of each branch until a sufficient level of branching is reached
'=================================================

Code: QB64: [Select]
  1. _Title "Fractal Tree"
  2. Const sw% = 640
  3. Const sh% = 480
  4.  
  5. Screen _NewImage(sw, sh, 8)
  6.  
  7. Call tree(sw \ 2, sh - 10, _Pi * 1.5, _Pi / 180 * 29, 112, 15)
  8.  
  9.  
  10. Sub tree (x As Integer, y As Integer, initAngle As Double, theta As Double, length As Double, depth As Integer)
  11.     Dim As Integer iL, newX, newY, iX, iY, iD
  12.     iL = length: iX = x: iY = y: iD = depth
  13.     newX = Cos(initAngle) * length + iX
  14.     newY = Sin(initAngle) * length + iY
  15.     Line (iX, iY)-(newX, newY)
  16.     iL = length * .78
  17.     iD = iD - 1
  18.     If iD > 0 Then
  19.         Call tree(newX, newY, initAngle - theta, theta, iL, iD)
  20.         Call tree(newX, newY, initAngle + theta, theta, iL, iD)
  21.     End If
  22.