Voici le code dont je vous partage basé sur un livre de l'algorithme en C :
Code : Tout sélectionner
; 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
NX.i
NY.i
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
Define.Pos_AB _AB
_AB\NX = 0
_AB\NY = 0
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