Tree lines in recursive

Share your advanced PureBasic knowledge/code with the community.
threedslider
Enthusiast
Enthusiast
Posts: 466
Joined: Sat Feb 12, 2022 7:15 pm

Tree lines in recursive

Post by threedslider »

Last example based from the French book for algorithm in C programming as I say before but with Tree lines in recursive.

Code: Select all

; Based on book : Algorithmes et structures de données by Michel Divay (C programming)
; Coded and adapted by threedslider 09.07.2022
; update some minor by threedslider 10.07.2022


Structure Pos_AB
  NX.i
  NY.i
EndStructure

Procedure Avance(L.i, X.i, Y.i, Angle.i, *pointer.Pos_AB)
  i.i = 0
 
  *pointer\NX = X + Int(L * Cos(Angle*2*#PI / 360.0))
  
  *pointer\NY = Y - Int(L * Sin(Angle*2*#PI / 360.0))
  
  Len = L/15
  
  
  For i=0 To Len
    LineXY(X+i, Y, *pointer\NX+i, *pointer\NY, RGB(255,0,0)) 
  Next
  
EndProcedure

Procedure Arbres(H.i, X.i, Y.i, Angle.i)
  Define.Pos_AB variable_AB
  variable_AB\NX = 0
  variable_AB\NY = 0
  N.i 
  I.i
  Dev.i
   
  H = Int(H + 0.1 * Random(H))
  
  Avance(H, X, Y, Angle, @variable_AB)
    
  H = 2*H / 3
  
  If H > 1
    N = Random(3) + 2
    Dev = 180/N
    For I = 1 To N
       Arbres(H, variable_AB\NX, variable_AB\NY, Angle - 90 - Dev/2 + I*Dev)
    Next
  EndIf  
EndProcedure

If OpenWindow(0, 0, 0, 600, 600, "Tree lines in recursive", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    If CreateImage(0, 600, 600) And StartDrawing(ImageOutput(0))
      
      Arbres(80,300,450,90) 
           
      StopDrawing() 
      ImageGadget(0, 0, 0, 600, 600, ImageID(0))
    EndIf
    
    Repeat
      Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow
EndIf
Happy coding !
User avatar
idle
Always Here
Always Here
Posts: 6095
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Tree lines in recursive

Post by idle »

Thanks, fractal trees never ceases to amaze.
Have you ever seen or heard of slime molds intelligence, they grow like fractal trees but have feed back and can solve complex networks. Original papers about it were from around ~2010 but here's a recent articles about them https://phys.org/news/2022-01-virtual-s ... twork.html
AZJIO
Addict
Addict
Posts: 2241
Joined: Sun May 14, 2017 1:48 am

Re: Tree lines in recursive

Post by AZJIO »

Well done here, you can zoom in on the fractal and it is drawn even further.
https://www.autoitscript.com/forum/topi ... -have-fun/
threedslider
Enthusiast
Enthusiast
Posts: 466
Joined: Sat Feb 12, 2022 7:15 pm

Re: Tree lines in recursive

Post by threedslider »

idle wrote: Mon Jul 11, 2022 9:54 am Thanks, fractal trees never ceases to amaze.
Have you ever seen or heard of slime molds intelligence, they grow like fractal trees but have feed back and can solve complex networks. Original papers about it were from around ~2010 but here's a recent articles about them https://phys.org/news/2022-01-virtual-s ... twork.html
Yes heard and seen but on 3D software like Houdini does this kind of thing, this link shows that : https://www.youtube.com/watch?v=oes6NzqC4DY
threedslider
Enthusiast
Enthusiast
Posts: 466
Joined: Sat Feb 12, 2022 7:15 pm

Re: Tree lines in recursive

Post by threedslider »

AZJIO wrote: Mon Jul 11, 2022 10:00 am Well done here, you can zoom in on the fractal and it is drawn even further.
https://www.autoitscript.com/forum/topi ... -have-fun/
Thanks, yes fractal has a lot of possibility to draw :)
Little John
Addict
Addict
Posts: 4812
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Tree lines in recursive

Post by Little John »

idle wrote: Mon Jul 11, 2022 9:54 am Thanks, fractal trees never ceases to amaze.
Have you ever seen or heard of slime molds intelligence, they grow like fractal trees but have feed back and can solve complex networks. Original papers about it were from around ~2010 but here's a recent articles about them https://phys.org/news/2022-01-virtual-s ... twork.html
Very interesting, thanks for the link!
Post Reply