#MinVersion 1.11.1
#compiled "===Mandelbrot Example==="
'----------------------------------------------------------------------------
function Mandelbrot_Screen Cdecl (byval xXMax as long, byval yYMax as long, ByVal depth As Long) As long Export
'----------------------------------------------------------------------------
ScreenRes xXMax, yYMax, depth
end function
'----------------------------------------------------------------------------
function Mandelbrot_Show Cdecl (byval xXMax as long, byval yYMax as long, byval lLimit as long) As long Export
'----------------------------------------
dim hwin As long
dim as single tmr, xmin, xmax, ymin, ymax, cx, cy, dcx, dcy, x, y, zr, zi
dim as long xi, j,k, numiter, numxpix, numypix, te, ts
dim color_map(216) As Long
dim stuff_done As Long
dim s As String
xmin = -.65 : xmax = -.45 : ymin = .52 : ymax = .72 : numiter = 215
'xmin = -2.0 : xmax = 1 : ymin = -.8 : ymax = 1 : numiter = 215
numxpix = 800'400 '800
numypix = 600'300 '600
dcx = (xmax - xmin)/(numxpix - 1)
dcy = (ymin - ymax)/(numypix - 1)
dim i as long
for i = 1 to 1
'-----------------------> problem 1 solved array dimension ! --------------------------->
ReDim color_map(216) '(6*6*6) 216
For xi = 1 To 6
For j = 1 To 6
For k = 1 To 6 'but "6*j + 36*k" doesn't work here (I don't grasp it!)
color_map(xi + 5*j + 30*k) = Rgb(51*j,51*xi,51*k)
Next
Next
Next
'-----------------------> problem 1 solved array dimension ! --------------------------->
ts = Timer
tmr = Timer
cx = xmin
'-----------------------> 2 --------------------------->
For xi = 1 To numxpix
cy = ymax
For j = 1 To numypix
x = cx
y = cy
For k = 1 To numiter
zr = x*x - y*y + cx
zi = 2*x*y + cy
'-----------> important thingy solved !------------->
If (zr*zr + zi*zi) > 4 Then Exit For
x = zr : y = zi
'Console_WriteLine "FOR/NEXT zr=" + Format$(zr)
'Console_WriteLine "FOR/NEXT zi=" + Format$(zi)
'-----------> important thingy solved !------------->
Next
cy += dcy
'-------------------> problem zone 2 solved! --------------------------------->
'Canvas_SetPixel(xi, j, color_map(numiter+2-k) ) ' testing ok
PSet (xi, j), color_map(numiter+2-k) 'Rgb(0, 0, 0)
'-------------------> problem zone 2 solved --------------------------------->
Next
cx += dcx
Next
'Canvas_Clear(color_map(numiter+2-k)) 'starts rendering again ;)
'Canvas_Color(Rgb(255,10,10))
'Canvas_SetPos(20,120)
's = Format$(("Took ##.## seconds ") + Format$(Timer - tmr) )
'Canvas_Print s
'MsgBox 0, "testing ok?" ' example works
'Canvas_Redraw
'Loop
next
'te = Timer
'Canvas_WaitKey(27)
'Canvas_Window End
return 0
End Function
function Mandelbrot_Sleep Cdecl () As long Export
'----------------------------------------------------------------------------
sleep
end function
#endcompiled
long lWidth = 1024
long lHeight = 768
long lDepth = 32
long l
'---Call FreeBasic functions
Mandelbrot_Screen(lWidth, lHeight, lDepth)
'for l = 2 to 21
Mandelbrot_Show(lWidth, lHeight, l)
'next
Mandelbrot_Sleep
'console_close
Bookmarks