Does anyone have Mandelbrot and Julia Sets fractal generation code that does NOT have any drawing code associated with it?
I just want to iterate the fractals and get their equation's values at each step. But every program I find is for drawing the fractals.
Each of these fractal drawing programs that I find set some values that can obviously be used for a drawing canvas to plot pixels on - distance and zoom levels - and coloring of pixels. But I can't figure out if I also need some of those variables and their values when I am only trying to evaluate the fractal equations.
Thanks in advance!
CBruce
Mandelbrot and Julia Sets fractals without any drawing code?
Re: Mandelbrot and Julia Sets fractals without any drawing code?
Does this help?
Code: Select all
Dim Shared As ULong iW, iH
iW = 100
iH = 60
Dim as Ulong iMax = iW * iH - 1 , iX, iY
Function MandelIter(cx As Single, cy As Single, maxIter As ULong) As ULong
Dim As Single x = 0.0, y, xx, yy, xy
Dim As ULong i = maxIter
While (xx + yy <= 4 And i > 0)
xy = x * y
xx = x * x
yy = y * y
x = xx - yy + cx
y = xy + xy + cy
i -= 1
Wend
Return maxIter - i
End Function
Sub Mandelbrot(xmin As Single, xmax As Single, ymin As Single, ymax As Single, iterations As ULong)
Dim As ULong i
Dim As Double c, x, y
Dim As ULong iX, iY, iW1 = iW - 1, iH1 = iH - 1, iColor
For iY = 0 To iH - 1
For iX = 0 To iW - 1
x = xmin + (xmax - xmin) * iX / iW1
y = ymin + (ymax - ymin) * iY / iH1
i = mandelIter(x, y, iterations)
'calculate color values
If (i < iterations) Then
c = 3 * Log(i) / Log(iterations - 1.0)
If (c < 1) Then
iColor = &hFF000000 or ((255 * c) Shl 16)
ElseIf ( c < 2 ) Then
iColor = &hFF000000 or (255 Shl 16) or ((255 * (c - 1)) Shl 8)
Else
iColor = &hFFFFFF00 or ((255 * (c - 2)))
Endif
Else
iColor = &hFF000000
EndIf
? Hex(iColor, 8)
Next
Next
End Sub
Mandelbrot(-2, 1, -1, 1, 1000)
? "Done"
Sleep
Re: Mandelbrot and Julia Sets fractals without any drawing code?
Here, the Julia set.
Code: Select all
'Julia fractals
Type complex
As Single re,im
End Type
Operator +(n1 As complex,n2 As complex) As complex
Return Type<complex>(n1.re+n2.re,n1.im+n2.im)
End Operator
Operator *(n1 As complex,n2 As complex) As complex
Return Type<complex>(n1.re*n2.re - n1.im*n2.im,n1.im*n2.re + n1.re*n2.im)
End Operator
Type jpoints
As Long x,y
As Ulong colour
End Type
Declare Sub Julia ( As Single,() As jpoints)
Screen 20
Color ,0
Cls
windowtitle "Please wait filling array . . ."
Redim As jpoints j()
Julia(500,j())
Print "done, array size = ";Ubound(j)
Print "Press a key"
Sleep
windowtitle "Julia points:"
For n As Long=Lbound(j) To Ubound(j)
Pset(j(n).x,j(n).y),j(n).colour
Next
Sleep
' ___________________________________
Sub Julia (Scaler As Single,j() As jpoints)
#define absolute2(p) p.re*p.re+p.im*p.im
Dim As Integer xres ,yres,i,ctr
Screeninfo xres,yres
Redim j(5*xres*yres)
Dim Z As Complex
Dim As Complex initial=Type(.138341,.649857)
Dim As Single ConstX = -.090010013,ConstY = -.00002514951
Dim As Long x1,y1
Dim As Single StartX = -1/Scaler+ConstX, EndX = 1/Scaler+ConstX
Dim As Single StartY = -1/Scaler+ConstY,EndY=1/Scaler+ConstY
Dim As Single IncrementReal=.006245/(Scaler*8),IncrementImag=.01/(Scaler*8)
For real As Single = StartX To EndX Step IncrementReal
For imag As Single = StartY To EndY Step IncrementImag
If Inkey <> "" Then End
z=Type(real,imag)
i=0
Do
i+=1 And 255 ' = Mod 256 'colour
z=z*z+initial '(Julia iterator)
Loop Until absolute2(z)>5
x1=(real-ConstX)*xres*Scaler
If x1>=0 Then Exit For
x1=Abs(x1)
y1=Abs((imag-ConstY)*yres*Scaler)
If Point(x1,y1)=0 Then
j(ctr)=Type(x1,y1,i)
ctr+=1
End If
Pset(x1,y1),7
Next imag
Next real
Redim Preserve j(ctr)
End Sub
Re: Mandelbrot and Julia Sets fractals without any drawing code?
Silent Julia.
Code: Select all
'Julia fractals
Type complex
As Single re,im
End Type
Operator +(n1 As complex,n2 As complex) As complex
Return Type<complex>(n1.re+n2.re,n1.im+n2.im)
End Operator
Operator *(n1 As complex,n2 As complex) As complex
Return Type<complex>(n1.re*n2.re - n1.im*n2.im,n1.im*n2.re + n1.re*n2.im)
End Operator
Type jpoints
As Long x,y
As Ulong colour
End Type
Declare Sub Julia ( As Single,() As jpoints)
Sub CreateJulia(wide As Long,high As Long,num As Single,j() As jpoints)
If Screenres(wide,high,8,,-1)=0 Then Julia num,j()
Screen 0, 0, 0, &h80000000
End Sub
Sub ShowJulia(j() As jpoints)
Print "done, array size = ";Ubound(j)
Print "Press a key"
Sleep
Screen 20
Windowtitle "Julia points:"
For n As Long=Lbound(j) To Ubound(j)
Pset(j(n).x,j(n).y),j(n).colour
Next
Sleep
Screen 0, 0, 0, &h80000000
End Sub
Print "Please wait, filling array . . ."
Redim As jpoints j()
CreateJulia(800,600,20,j())
showJulia(j())
Print "Please wait, re-filling array . . ."
CreateJulia(950,700,200,j())
showJulia(j())
Print "Please wait, re-filling array . . ."
CreateJulia(1024,768,600,j())
showJulia(j())
' ___________________________________
Sub Julia (Scaler As Single,j() As jpoints)
#define absolute2(p) p.re*p.re+p.im*p.im
Dim As Integer xres ,yres,i,ctr
Screeninfo xres,yres
Redim j(5*xres*yres)
Dim Z As Complex
Dim As Complex initial=Type(.138341,.649857)
Dim As Single ConstX = -.090010013,ConstY = -.00002514951
Dim As Long x1,y1
Dim As Single StartX = -1/Scaler+ConstX, EndX = 1/Scaler+ConstX
Dim As Single StartY = -1/Scaler+ConstY,EndY=1/Scaler+ConstY
Dim As Single IncrementReal=.006245/(Scaler*8),IncrementImag=.01/(Scaler*8)
For real As Single = StartX To EndX Step IncrementReal
For imag As Single = StartY To EndY Step IncrementImag
' If Inkey <> "" Then End
z=Type(real,imag)
i=0
Do
i+=1 And 255 ' = Mod 256 'colour
z=z*z+initial '(Julia iterator)
Loop Until absolute2(z)>5
x1=(real-ConstX)*xres*Scaler
If x1>=0 Then Exit For
x1=Abs(x1)
y1=Abs((imag-ConstY)*yres*Scaler)
If Point(x1,y1)=0 Then
j(ctr)=Type(x1,y1,i)
ctr+=1
End If
Pset(x1,y1),7
Next imag
Next real
Redim Preserve j(ctr)
End Sub