Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Recursion: 4 ways to get it working
#17
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
Reply


Messages In This Thread
RE: Recursion: 4 ways to get it working - by TempodiBasic - 02-18-2023, 10:59 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  plotting shapes not working madscijr 6 653 10-22-2025, 05:29 AM
Last Post: SMcNeill
  why isn't _FULLSCREEN working? madscijr 5 532 09-20-2025, 01:47 AM
Last Post: SMcNeill
  I'm working on an old MS-DOS thingy... KlamPs 2 517 08-25-2025, 09:43 AM
Last Post: hsiangch_ong
  blue circle isn't drawing and print isn't working? madscijr 12 2,343 09-21-2024, 06:13 PM
Last Post: madscijr
  Updating Clock at a different rate to program loop-example not working as expected? dowster 1 615 08-15-2024, 12:06 PM
Last Post: luke

Forum Jump:


Users browsing this thread: 1 Guest(s)