This code can be modified to generate almost any kind of fractal flame. At the moment it is set up with the four functions described
here to generate a fern fractal.
The result has 2x antialiasing and gamma correction applied, and the brightness and gamma can be varied in realtime.
The number of fractal functions is specified with the constant F_N, and the functions themselves are named V0, V1, etc.
The 'p' value of each function specifies the probabilty that the function will be used in a particular iteration.
sync on : sync rate 0
set display mode desktop width(), desktop height(), 32
#constant F_N 4
#constant SQUARE_SIZE 1000
#constant POINT_N 4000000
#constant PROGRESS_N 8000
#constant PIXEL_GAMMA 2.0
#constant POINT_SCALE 100
type F_t
F as integer
p as float
endtype
dim F(F_N-1) as F_t
dim COL(SQUARE_SIZE-1, SQUARE_SIZE-1) as integer
global pX as float
global pY as float
for i = 0 to F_N-1
F(i).F = get ptr to function("V" + str$(i))
next i
F(0).p = 0.01
F(1).p = 0.07
F(2).p = 0.07
F(3).p = 0.85
cls 0
for a = 1 to POINT_N
pX = 0 `(rnd(SQUARE_SIZE*1000)-SQUARE_SIZE*500)*10.0
pY = 0 `(rnd(SQUARE_SIZE*1000)-SQUARE_SIZE*500)*10.0
for i = 0 to 20
p# = rnd(999999)*0.000001
for j = 0 to F_N-1
if F(j).p > p# then exit
dec p#, F(j).p
next j
call function ptr F(j).F, pX, pY
if i = 20
if (pX >= SQUARE_SIZE*-0.5) and (-pY >= SQUARE_SIZE*-1)
if (pX <= SQUARE_SIZE*0.5-1) and (-pY <= SQUARE_SIZE*0-1)
inc COL(int(pX+SQUARE_SIZE*0.5), int(-pY+SQUARE_SIZE*1))
endif
endif
endif
next i
if (a MOD PROGRESS_N) = 1
print str$((a*100)/POINT_N) + "%"
sync : sync
cls 0
endif
next a
power# = 100.0
gamma# = 1.5
do
inc power#, (upkey()-downkey())*0.5
inc gamma#, (rightkey()-leftkey())*0.02
lock pixels
for y = 0 to SQUARE_SIZE/2-1
for x = 0 to SQUARE_SIZE/2-1
c1# = (log(COL(x*2,y*2)+1)^(1.0/gamma#))*power#
c2# = (log(COL(x*2+1,y*2)+1)^(1.0/gamma#))*power#
c3# = (log(COL(x*2,y*2+1)+1)^(1.0/gamma#))*power#
c4# = (log(COL(x*2+1,y*2+1)+1)^(1.0/gamma#))*power#
c = min(255,(c1#+c2#+c3#+c4#)*0.25)
dot x,y,rgb(0, c, 0)
`if COL(x,y) then dot x,y
next x
next y
unlock pixels
text SQUARE_SIZE+10, 10, "Power: " + str$(power#)
text SQUARE_SIZE+10, 30, "Gamma: " + str$(gamma#)
sync
cls 0
loop
end
function V0(x#, y#)
pX = 0
pY = y#*0.16
endfunction
function V1(x#, y#)
pX = 0.2*x#-0.26*y#
pY = 0.23*x#+0.22*y#+1.6*POINT_SCALE
endfunction
function V2(x#, y#)
pX = -0.15*x#+0.28*y#
pY = 0.26*x#+0.24*y#+0.44*POINT_SCALE
endfunction
function V3(x#, y#)
pX = 0.85*x#+0.04*y#
pY = -0.04*x#+0.85*y#+1.6*POINT_SCALE
endfunction
Enjoy
[b]