I recently found out about the graphics functionality that can be utilized during the paint event of a report. So I wanted to stress test it. I realize this is far outside the realm of what Access was designed for, but I'm still getting some weird behavior that I'd like to fix if possible.
Plotting a Mandelbrot is fairly simple. (given a complex c, and a complex series Z, with Z_0 = 0, and Z_(n+1) = (Z_n)^2 + c), iff Z diverges, c is not in the set.
The result of plotting all values that lie within the set is the famous Mandelbrot fractal.
The code below seems to work to a degree. It has a roughly Mandelbrot'ish shape. But it seems to be different overall.
I've checked and rechecked my math and all I can think is that there is some bug or harsh limitation in VBA.
Here is the code:
Any thoughts on why this looks so different from how a Mandelbrot should?
Plotting a Mandelbrot is fairly simple. (given a complex c, and a complex series Z, with Z_0 = 0, and Z_(n+1) = (Z_n)^2 + c), iff Z diverges, c is not in the set.
The result of plotting all values that lie within the set is the famous Mandelbrot fractal.
The code below seems to work to a degree. It has a roughly Mandelbrot'ish shape. But it seems to be different overall.
I've checked and rechecked my math and all I can think is that there is some bug or harsh limitation in VBA.
Here is the code:
Code:
Option Compare Database
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
'parameter declarations
Dim width As Integer 'the width (in pixels) of the draw field
Dim height As Integer 'the height (in pixels) of the draw field
Dim checkDepth As Integer 'the amount of iterations of the mandelbrot formula used to determine if point diverges
'parameter initializations
width = 2700
height = 1800
checkDepth = 20
'draw borders
Me.Line (0, 0)-(width, 0)
Me.Line (width, 0)-(width, height)
Me.Line (width, height)-(0, height)
Me.Line (0, height)-(0, 0)
'z series
Dim z_REAL As Double
Dim z_IMAG As Double
'value to check
Dim c_REAL As Double
Dim c_IMAG As Double
For x = 0 To width Step 5
For y = 0 To height Step 5
z_REAL = 0
z_IMAG = 0
'set c_REAL and c_IMAG to a mapping of (x,y) to ([-2,2],[-2,2])
c_REAL = 3 * (x / width) - 2
c_IMAG = 1 - 2 * (y / height)
For i = 1 To checkDepth
'multiply z by itself
z_REAL = z_REAL * z_REAL - z_IMAG * z_IMAG
z_IMAG = 2 * z_REAL * z_IMAG
'add c to z
z_REAL = z_REAL + c_REAL
z_IMAG = z_IMAG + c_IMAG
If Abs(z_REAL) > 2 Or Abs(z_IMAG) > 2 Then Exit For
If i = checkDepth Then
Me.PSet (x, y)
End If
Next i
Next
Next
End Sub
Any thoughts on why this looks so different from how a Mandelbrot should?
Last edited: