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 Variantn = 201xmax = 1.2xmin = -1.2ymax = 0.6ymin = -1.5For i = 1 To nFor j = 1 To nc = 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))NextNextEnd SubSub iterate(c As Variant, cel As Range)k = 1cond = TrueZ = 0While cond = True'Zn+1=Zn^2+cZ = WorksheetFunction.ImSum(WorksheetFunction.ImProduct(Z, Z), c)If WorksheetFunction.ImAbs(Z) > 2 Thencond = FalseElsek = k + 1End IfIf k > 255 Thencond = Falsecel.Interior.Color = vbBlackEnd IfWendEnd Sub
Commentaires