Post by johnno56 on Apr 21, 2021 2:09:33 GMT -6
This is an SDLBasic listing of Fractal Tree and it's result.
This is the RCBasic version and its result.
As the syntax, in this case, between sdlbasic and rcbasic is practically the same, the results would conclude that RCBasic seems to have difficulties with recursion.
I wanted to test recursion on the fractal tree before attempting to experiment with 4 and 8 way flood filling which depends on recursion.
My question would be: Is recursion something that RC was not designed to do or would this be a possible bug?
NB: I am also not ruling out the possibility that my coding may be incorrect... lol
xmax = 640
ymax = 480
setDisplay(xmax, ymax, 32, 1)
setCaption("Fractal Tree")
sw = xmax
sh = ymax
pi = 3.141592654
ink(rgb(0, 255, 0))
'======================================================================
Sub tree (x, y, initAngle, theta, long, depth)
Dim iL
Dim newX
Dim newY
Dim iX
Dim iY
Dim iD
iL = long: iX = x: iY = y: iD = depth
newX = Cos(initAngle) * long + iX
newY = Sin(initAngle) * long + iY
Line (iX, iY, newX, newY)
iL = long * 0.78
iD = iD - 1
if iD > 0 then
tree(newX, newY, initAngle - theta, theta, iL, iD)
tree(newX, newY, initAngle + theta, theta, iL, iD)
'iD = iD - 1
end if
End Sub
'=====================================================================
tree(int(sw / 2), sh - 10, pi * 1.5, pi / 180 * 29, 112, 15)
waitkey(32)
This is the RCBasic version and its result.
xmax = 640
ymax = 480
title$ = "Fractal Tree?"
WindowOpen(1,title$,0,0,xmax,ymax,0)
CanvasOpen(1,xmax,ymax,0,0,xmax,ymax,0)
ClearCanvas
sw = xmax
sh = ymax
pi = 3.141592654
'======================================================================
Sub tree (x, y, initAngle, theta, long, depth)
Dim iL
Dim newX
Dim newY
Dim iX
Dim iY
Dim iD
iL = long: iX = x: iY = y: iD = depth
newX = Cos(initAngle) * long + iX
newY = Sin(initAngle) * long + iY
Line (iX, iY, newX, newY)
iL = long * 0.78
iD = iD - 1
if iD > 0 then
tree(newX, newY, initAngle - theta, theta, iL, iD)
tree(newX, newY, initAngle + theta, theta, iL, iD)
end if
End Sub
'======================================================================
setColor(rgb(0,255,0))
tree(int(sw / 2), sh - 10, pi * 1.5, pi / 180 * 29, 112, 15)
update()
waitkey(32)
As the syntax, in this case, between sdlbasic and rcbasic is practically the same, the results would conclude that RCBasic seems to have difficulties with recursion.
I wanted to test recursion on the fractal tree before attempting to experiment with 4 and 8 way flood filling which depends on recursion.
My question would be: Is recursion something that RC was not designed to do or would this be a possible bug?
NB: I am also not ruling out the possibility that my coding may be incorrect... lol