I found this one from KPL (http://www.k-p-l.org/index.php) and converted it to the Blitz3d (some unneeded code is commented out..)
It is quite fast I must say.. even if it traces only edges of set.
How about little "challenge", could you make this faster or improve it otherwise? (like fillingspace between trace edges..)
It is quite fast I must say.. even if it traces only edges of set.
How about little "challenge", could you make this faster or improve it otherwise? (like fillingspace between trace edges..)
;Program MandelbrotTria ; This .kpl program runs in KPL - see <a href="http://www.k-p-l.org" target="_blank">http://www.k-p-l.org</a> ; Triangulate a mandelbrot set, by Michael Hoger ; Idia taken from " Fractals for the Classroom " by Peitgen/jürgens/Saupe. ; This is a different And faster algorithm For approximating And displaying ; a fractal image, compared To a previous KPL example, Mandelbrot.kpl. ; It would be a very interesting exercise of both mathematics And computer ; programming To examine And contrast the two example programs side by side. ; Difficulty level: Advanced (based on the complex math, Not the code) ; Concepts: String manipulation, array abstractions, nested looping, pen drawing ; KPL Lines: 91 ; Author: Michael Hoger ; Blitz3d conversion by FinJogi Graphics 800, 600, 32, 2 Origin 400,300 ; a triangle Dim trix(3) Dim triy(3) ;the verts ;vin=0 ;vout=0 ;vnew=0 ;vtemp=0 ; a coordinate To find the edge of the fractal ;ix=0 ; startcoordinates ;xin=0 ;yout=0 ; a complex number ;real#=0 ;imag#=0 ; two helper ;Outside=False ;Closed=False ; iterationindex k = 0 kend = -50 kstep = 1 scale# = 4.0 / Float( 600 - 30 ) ; start the iteration While k >= kend ; search the edge of the fractal along the x-axis ; For this iteration ix = 0 Outside = False While Not Outside real# = scale# * Float(ix) imag# = 0 Outside = Mandelbrottest( k, real#, imag# ) ix = ix + 1 Wend ; we found the edge now init the First triangle ; a triangle is formed about three points And look ; .................... ; like ..0....0...00...00.. ; ..00..00...0.....0.. ; .................... vin = 1 vout = 2 vnew = 3 trix(vin) = ix - 1 trix(vout) = ix trix(vnew) = ix triy(vin) = 0 triy(vout) = 0 triy(vnew) = 1 ; hold some information To see when we are around xin = trix(vin) yout = triy(vout) ; define the Color And move To First point Color( 100 - ( k * 3 Mod 255 ), 0, 128 ) ;ColorRGB( 100 - ( k * 3 Mod 255 ), 0, 0 ) ;Pen( False ) ;MoveTo( trix [ vin ], triy[ vin ] ) ;Pen( True ) Plot( trix(vin), triy(vin) ) ; Now the tricky part. We follow the funktion at this iteration ; by mirrorring our triangle along the x- And y- axis. ; The mandelbrottest inform us what we have To do Next. Closed = False While Not Closed ; New complex number real# = scale# * Float( trix(vnew) ) imag# = scale# * Float( triy(vnew) ) ; test For outside And mirror triangle If Outside = Mandelbrottest( k, real#, imag# ) Then vtemp = vout vout = vnew vnew = vtemp Else ;MoveTo( trix(vnew), triy(vnew) ) Plot(trix(vnew), triy(vnew)) vtemp = vin vin = vnew vnew = vtemp End If ; calculate the New vertex trix(vnew) = trix(vin) + trix(vout) - trix(vtemp) triy(vnew) = triy(vin) + triy(vout) - triy(vtemp) ; see If we are closed For this iteration If trix(vout) = xin Then If triy(vout) = yout Then Closed = True End If End If Wend kstep = kstep + 2 k = k - kstep Wend WaitKey() End ; this Function tests If an complex number is in Or outside the mandelbrot set ; depend on the number of iteration. Function Mandelbrottest(Iter, real#, imag# ) re# = real# im# = imag# re2#=0 im2#=0 j = 2 While ( j ) >= Iter re2# = re# * re# im2# = im# * im# If ( re2# + im2# ) > 256 Then Return True End If im# = 2 * re# * im# + imag# re# = re2# - im2# + real# j = j - 1 Wend Return False End Function