Title says it all, but a picture is worth a thousand words.
set display mode 1024,768,32
cls
set cursor 0,0
ink rgb(0,255,0),0
fern(512,668,7,90,7,50,150)
fern(511,668,7,90,7,50,150)
fern(513,668,7,90,7,50,150)
fern(510,668,7,90,7,50,150)
fern(514,668,7,90,7,50,150)
line 512,668,512,768
box 510,668,514,768
blur bitmap 0,2
repeat
until spacekey()
end
REM ====== FERN FRACTAL =======
REM X,Y - starting position for fern, root of first stem
REM passes - number of iterations
REM startAngle - angle to start drawing on this pass
REM bendAngle - overall bending angle of the whole leaf
REM branchAngle - angle to branch off each stem at
REM height - starting height
function fern(x as float, y as float, passes as integer, startAngle as float, bendAngle as float, branchAngle as float, height as float)
rootAngle# = wrapvalue(startAngle - bendAngle)
x2 = x + cos(rootAngle#)*height
y2 = y - sin(rootAngle#)*height
line x,y,x2,y2
height = height*0.5
x3 = x + cos(wrapvalue(rootAngle#+branchAngle))*height
y3 = y - sin(wrapvalue(rootAngle#+branchAngle))*height
line x,y,x3,y3
x4 = x + cos(wrapvalue(rootAngle#-branchAngle))*height
y4 = y - sin(wrapvalue(rootAngle#-branchAngle))*height
line x,y,x4,y4
if passes > 1
fern(x2,y2,passes-1, rootAngle#, bendAngle, branchAngle, height)
fern(x3,y3,passes-1, wrapvalue(rootAngle#+branchAngle), bendAngle, branchAngle, height)
fern(x4,y4,passes-1, wrapvalue(rootAngle#-branchAngle), bendAngle, branchAngle, height)
endif
endfunction
"Using Unix is the computing equivalent of listening only to music by David Cassidy" - Rob Pike