This example seems to work with its recursion properly
// set window properties
SetWindowTitle( "Fractal Math" )
SetWindowSize( 1024, 768, 0 )
SetSyncRate(30,0) `
// set display properties
SetVirtualResolution( 1024, 768 )
length#=1
do
if length#<250 then length#=length#+.25 //grows at the rate of.25 increase the number to grow faster
cantor2(512,768,length#,270) //draws a growing tree
Sync()
loop
function cantor2(x as float,y as float,length as float,ang as integer)
local x2 as float
local y2 as float
if length>1
x2= length * cos(ang) + x //calculate endx point given length and angle
y2= length * sin(ang) + y //calculate endy point given length and angle
DrawLine(x,y,x2,y2,MakeColor(255,255,255),MakeColor(255,255,255))
cantor2(x2,y2,length/1.5,ang+15)
cantor2(x2,y2,length/1.5,ang-15)
//if you change the above to this it will add some randomness but if you
//try to draw gradually with the draw command it will appear as if there is wind
//cantor2(x2,y2,length/1.5,ang+random(10,15))
//cantor2(x2,y2,length/1.5,ang-random(10,15))
endif
endfunction
but the recursion seems to get in an endless loop with this example and/or exits the main loop
#constant green = MakeColor(0,255,0)
#constant white = MakeColor(255,255,255)
#constant swidth=1024
#constant sheight=768
// show all errors
SetErrorMode(2)
SetVirtualResolution( swidth, sheight ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
do
floodFill4(100,100,10,10,MakeColor(0,255,0))
//DrawBox(0,0,100,100,green,green,green,green,1)
print("done")
//sleep(10)
sync()
loop
end
function floodFill4(w as integer, h as integer, x as integer, y as integer, newColor)
if x < 0 or x > w or y < 0 or y > h then exitfunction
if point(x,y) = newColor then exitfunction
drawLine(x,y,x,y,newColor,newColor)
floodFill4( w, h, x + 1, y , newColor)
floodFill4( w, h, x - 1, y , newColor)
floodFill4( w, h, x , y + 1, newColor)
floodFill4( w, h, x , y - 1, newColor)
endfunction
Function point(X,Y)
//color as integer
rem prepare image grab area
clearScreen()
setScissor(X,Y,X+1,Y+1)
render()
img = getImage(X,Y,X+1,Y+1)
rem create memblock
mem = createMemblockfromImage(img)
rem get memblock data
r = getMemblockbyte(mem,12):rem gets red channel data
g = getMemblockbyte(mem,13):rem gets green channel data
b = getMemblockbyte(mem,14):rem gets blue channel data
rem tidy up
deletememblock(mem)
deleteimage(img)
setScissor(0,0,getDeviceWidth(),getDeviceHeight())
clearScreen()
color = makeColor(r,g,b)
//color=0
endfunction color
and not sure why
fubar