Fractale de Mandelbrot sur Excel

Comment générer la fameuse fractale de Mandelbrot sur une feuille Excel


Scripts VBA
Sub drawMandelbrot()
Dim c As Variant
n = 201
xmax = 1.2
xmin = -1.2
ymax = 0.6
ymin = -1.5

For i = 1 To n
    For j = 1 To n
        c = WorksheetFunction.Complex((ymax - ymin) * (j - 1) / (n - 1) + ymin, (xmax - xmin) * (i - 1) / (n - 1) + xmin)
        Call iterate(c, Range("A1").Offset(i - 1, j - 1))
    Next
Next
End Sub

Sub iterate(c As Variant, cel As Range)
k = 1
cond = True
Z = 0
While cond = True
    'Zn+1=Zn^2+c
    Z = WorksheetFunction.ImSum(WorksheetFunction.ImProduct(Z, Z), c)
    If WorksheetFunction.ImAbs(Z) > 2 Then
        cond = False
    Else
        k = k + 1
    End If
    If k > 255 Then
        cond = False
        cel.Interior.Color = vbBlack
    End If
Wend
End Sub

Commentaires

Posts les plus consultés de ce blog

Nom des services Windows en Français et en Anglais

How to determine eigenvalues and eignevectors of a matrix in Excel

Analyse de Fourrier sur Excel