Recursive circle paths

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

Recursive circle paths

Post by threedslider »

Hello I would like to share you some my code in Purebasic based on the French book from algorithm in C programming :)

Here is the code :

Code: Select all

; Based on book : Algorithmes et structures de données by Michel Divay (C programming)
; Coded and adapted by threedslider 08.07.2022

Procedure Cercle(X.i, Y.i, R.i)
  For n=0 To 1800
        cx = R * Cos(n)
        cy= R * Sin(n)
        Plot(cx+X,cy+Y,RGB(255,0,0)) 
      Next
EndProcedure

Procedure DeuxCercles(X.i, Y.i, R.i)
  _r.i = 0
  If R > 10
      cercle(X, Y, R)    
      _r = R / 2
      DeuxCercles(X+_r, Y, _r)
      DeuxCercles(X-_r, Y, _r)
    EndIf       
EndProcedure
  
If OpenWindow(0, 0, 0, 600, 600, "Two circles in recursive", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    If CreateImage(0, 600, 600) And StartDrawing(ImageOutput(0))
      
      DeuxCercles(300,300,200)
    
      StopDrawing() 
      ImageGadget(0, 0, 0, 200, 200, ImageID(0))
    EndIf
    
    Repeat
      Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow
EndIf
threedslider
Enthusiast
Enthusiast
Posts: 466
Joined: Sat Feb 12, 2022 7:15 pm

Re: Recursive circle paths

Post by threedslider »

Same here but in three recursive circle paths.

Code: Select all

; Based on book : Algorithmes et structures de données by Michel Divay (C programming)
; Coded and adapted by threedslider 08.07.2022

Procedure Cercle(X.i, Y.i, R.i)
  For n=0 To 1800
        cx = R * Cos(n)
        cy = R * Sin(n)
        Plot(cx+X,cy+Y,RGB(255,0,0)) 
      Next
EndProcedure

Procedure TroisCercles(X.i, Y.i, R.i)
  _r.i = 0
  If R > 10
      cercle(X, Y, R)
      _r = Int((2*Sqr(3.0)-3)*R)
      H = R-_r
      TroisCercles(X-H, Y, _r)
      TroisCercles(X+H/2, Y+_r, _r)
      TroisCercles(X+H/2, Y-_r, _r)
    EndIf       
EndProcedure
  
If OpenWindow(0, 0, 0, 600, 600, "Three circles in recursive", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    If CreateImage(0, 600, 600) And StartDrawing(ImageOutput(0))
      
      TroisCercles(300,300,200)
    
      StopDrawing() 
      ImageGadget(0, 0, 0, 200, 200, ImageID(0))
    EndIf
    
    Repeat
      Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow
EndIf
Post Reply