02-18-2023, 10:59 AM
here another simple example of recursion in tail for draw a circle
Code: (Select All)
_Title "Circle by recursion demo"
Screen _NewImage(1000, 1000, 32)
Randomize Timer
_ScreenMove 1, 1
Const Tail = 2, Head = 1
Dim Radius As Integer, centerX As Integer, centerY As Integer, Mode As Integer
Radius = 50
centerX = 500
centerY = 500
Mode = Tail
While InKey$ <> " "
Locate 1, 1: Print "press spacebar to quit"
Radius = Radius + 5
colo~& = _RGB32((Rnd * 255) + 1, (Rnd * 255) + 1, (Rnd * 255) + 1)
DrawPoint colo~&, 1, CInt(Sin(1) * 100), CInt(Cos(1) * 100), centerX, centerY, Radius
_Limit 10
Wend
End
Sub DrawPoint (c~&, Sec As Single, Px As Integer, Py As Integer, Cx As Integer, Cy As Integer, Radius As Integer)
If Sec < 360 Then Sec = Sec + 1 Else Exit Sub
PSet (Cx, Cy), c~&
PSet (Px + Cx, Py + Cy), c~&
Px = CInt(Sin(Sec) * Radius)
Py = CInt(Cos(Sec) * Radius)
DrawPoint c~&, Sec, Px, Py, Cx, Cy, Radius ' this is an example of recursion in tail
End Sub