Page 1 of 1

Tree lines in recursive

Posted: Sun Jul 10, 2022 12:35 pm
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 !

Re: Tree lines in recursive

Posted: Mon Jul 11, 2022 9:54 am
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

Re: Tree lines in recursive

Posted: Mon Jul 11, 2022 10:00 am
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/

Re: Tree lines in recursive

Posted: Mon Jul 11, 2022 11:32 am
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

Re: Tree lines in recursive

Posted: Mon Jul 11, 2022 11:36 am
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 :)

Re: Tree lines in recursive

Posted: Mon Jul 11, 2022 3:26 pm
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!