我正在开发Python和LaTeX (最好是矢量图形TikZ/渐近图/PGF/Metapost/GeoGebra)代码,它们通过在终端上运行简单的代码来生成这个动画。
这是一个thread on Tex.SE,其中讨论了几种绘制Mandelbrot集的方法,但我不能像在LaTeX中那样简单地修改数学方程。因此,我转而使用Python,并生成尽可能接近矢量图形(~2,000 dpi)的高分辨率输出。我想把multibrots画得尽可能的笼统。例如,当d为负数时。
Enneabrot

下面的代码取自GitHub上的this Mandelbrot (dimension=2) project,我需要通过更改定义Mandelbrot集的递归方程中的指数来创建这个分形项目的高维版本,例如Triabrot (dimension=4),Pentabrot (dimension=6),Heptabrot (dimension=8)和Enneabrot (dimension=10)。换句话说,代替曼德尔布洛特分形的z_{n+1} = z_n * z_n + z_0,我们定义了一个维数变量d,然后d维Multibrot的方程将是z_{n+1} = z_n^d + z_0,每个这样的方程都将在其稳定区图中产生d-1个尖点。要了解有关此主题的更多信息,请观看以下两个YouTube视频:Times Tables by Mathologer和Mandelbrot Set by Numberphile。
有必要改变每一块输出的轴;这是因为分形在复杂的平面上移动,我们需要沿着镜头移动才能通过Python观察它们。我们还可以使用哪些公式?也许axisFix = ((d^2-4)/d)/10?在这个建议的公式中,d^2-4在那里,因为我希望在没有任何位移的情况下,将曼德尔布洛特分形(d=2)打印在中心。因此,轴平移的值将为零。这很有趣,因为对于d=-2,它也是零,这意味着我们还必须尝试查看像z_{n+1}=z_n^{-2.0} + z_0这样的方程。目标是找到最平滑的函数f(d),使得f(2)=0,并通过以小尺寸(0.01-0.1)的增量增加d的值并将这里定义的mandelbrot(阈值、密度、尺寸)函数的输出打印为动画来制作动画。函数越平滑,演示文稿中幻灯片动画中的幻灯片过渡就越平滑。
import numpy as np
import matplotlib.pyplot as plt
# counts the number of iterations until the function diverges or
# returns the iteration threshold that we check until
def countIterationsUntilDivergent(c, threshold, d):
z = complex(0, 0)
for iteration in range(threshold):
# here is the recurrence relation z_{n+1} = z_n^d + z_0, used for
# drawing d-1-dimensional Mandelbrot creatures (growing fractals)
z = z**d + c
if abs(z) > 4:
break
pass
pass
return iteration
# takes the iteration limit before declaring function as convergent and
# takes the density of the atlas
# create atlas, plot mandelbrot set, display set
def mandelbrot(threshold, density, d):
# it is necessary to change the axis for every patch of outputs;
# this happens because the fractals move in the complex plane
# and we need to move along our lens to watch them through Python
## what other formulas could we use? Maybe axisFix = ((d^2-4)/d)/10?
## d^2-4 is there because I want the Mandelbrot fractal (d=2)
## to be right there were it is printed without any replacement
## so the value of the axis translation would be zero. This is
## funny because it is also zero for d=-2 which means that
## we must also be trying to look at equations like
### z_{n+1}=z_n^{-2.0} + z_0
### the goal is to find the smoothest function
### f(d) such that f(2)=0 and make an animation
### by increasing the value of d by increments of small size (0.01-0.1)
### and printing the output of the mandelbrot function defined here
### as an animation. The smoother the function, the smoother
### the transition of slides in the animation
axisFix = d/10
# location and size of the atlas rectangle
realAxis = np.linspace(-2.25+axisFix, 0.75+axisFix, density)
imaginaryAxis = np.linspace(-1.5, 1.5, density)
# realAxis = np.linspace(-0.22, -0.219, 1000)
# imaginaryAxis = np.linspace(-0.70, -0.699, 1000)
realAxisLen = len(realAxis)
imaginaryAxisLen = len(imaginaryAxis)
# 2-D array to represent mandelbrot atlas
atlas = np.empty((realAxisLen, imaginaryAxisLen))
# color each point in the atlas depending on the iteration count
for ix in range(realAxisLen):
for iy in range(imaginaryAxisLen):
cx = realAxis[ix]
cy = imaginaryAxis[iy]
c = complex(cx, cy)
atlas[ix, iy] = countIterationsUntilDivergent(c, threshold, d)
pass
pass
# plot and display mandelbrot set
fig1 = plt.gcf()
plt.axis('off')
# plt.savefig('mandel.eps', format='eps')
plt.imshow(atlas.T, interpolation="nearest")
# plt.show()
output_name = str(d)+'.pdf'
fig1.savefig(output_name, format='pdf', bbox_inches='tight', dpi=2000)
# time to party!!
dimensions = np.arange(10, 100) / 10
# for d in dimensions:
# mandelbrot(120, 1000, d)
# Enneabrot
mandelbrot(120, 1000, 10)
# Heptabrot
mandelbrot(120, 1000, 8)
# Pentabrot
mandelbrot(120, 1000, 6)
# Triabrot
mandelbrot(120, 1000, 4)
# Mandelbrot
mandelbrot(120, 1000, 2)发布于 2021-01-08 00:00:59
以下是结果,感谢雅利安·赫马蒂通过将灵魂的Enneagram与十维Mandelbrot分形合并来编辑最终的照片。

我需要一个Python和LaTeX (最好是矢量图形TikZ/渐近/PGF/Metapost/GeoGebra,按那个顺序),它通过在您的终端上运行简单的代码来生成此动画。我们可以很容易地改变参数来制作一个七叶树(d=8),五叶树(d=6),甚至三叶树(d=4)。我附上了使用Python绘制Enneabrot (d=10)的代码,我已经由Danyaal Rangwala修改了this code,并在计算解的精确平衡区的递归方程中定义了一个新的变量d(维度),这最终显示Enneabrot是我尝试生成这种分形的最后一个数字(从d=1.0开始,增量为0.1,直到d=10.0)。
在这里,我将发布曼德尔布洛特分形(d=2)的输出,以及我在上面定义的分形: Enneabrot (d=10),Heptabrot (d=8),五叉树(d=6),甚至三叉树(d=4)。在此answer的下一个版本中将遵循的其他图表。
曼德尔布洛特(d=2)

三叉树(d=4)

五角星(d=6)

七叶树(d=8)

Enneabrot (d=10)

https://stackoverflow.com/questions/65615783
复制相似问题