Author Topic: Play Offs Chart - Recursion Example  (Read 3478 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Play Offs Chart - Recursion Example
« on: November 02, 2021, 11:29:20 am »
Get ready for Play Offs:
Code: QB64: [Select]
  1. _Title "Play Offs Chart - Recursion example" 'b+ 2021-10-27
  2. '2021-11-02 A few mods and ready for the playoffs
  3.  
  4. 'Recursion is a sub or function that calls itself until it's job is done
  5. 'Here is a grahics
  6. Const pi = _Pi
  7. Screen _NewImage(700, 700, 32)
  8.  
  9. recThis 700, 350, 350 / 2, 0
  10.  
  11. Sub recThis (x, y, arm, level As Integer)
  12.     'first thing to ask in recursive subroutine is are we done!!!
  13.     If arm < 2 Then Exit Sub ' recursion is finished
  14.     ' no not done
  15.     If level Mod 2 Then
  16.         x1 = x + 1.4 * arm * Cos(pi / 2): y1 = y + 1.4 * arm * Sin(pi / 2)
  17.         x2 = x + 1.4 * arm * Cos(1.5 * pi): y2 = y + 1.4 * arm * Sin(1.5 * pi)
  18.         Line (x1, y1)-(x2, y2)
  19.         recThis x1, y1, .7 * arm, level + 1
  20.         recThis x2, y2, .7 * arm, level + 1
  21.     Else
  22.         x1 = x: y1 = y
  23.         x2 = x + 100 * Cos(pi): y2 = y + 100 * Sin(pi)
  24.         Line (x1, y1)-(x2, y2)
  25.         recThis x2, y2, .7 * arm, level + 1
  26.     End If
  27.  

 
Play Offs Chart.PNG