Python 如何在缩放时调整平移
我想在放大Mandelbrot集时平移,以便函数的分形部分保持在窗口内。该代码输出一系列png图像,稍后将其制作成视频。现在,我有缩放和平移工作,但我不知道如何调整平移,而功能是缩放Python 如何在缩放时调整平移,python,matplotlib,fractals,mandelbrot,panning,Python,Matplotlib,Fractals,Mandelbrot,Panning,我想在放大Mandelbrot集时平移,以便函数的分形部分保持在窗口内。该代码输出一系列png图像,稍后将其制作成视频。现在,我有缩放和平移工作,但我不知道如何调整平移,而功能是缩放 import numpy as np import matplotlib.pyplot as plt from os import path #6:36 @2560x1440 500 iter #2:51 @2560x1440 200 iter #0:56 @2560x1440 50 iter #1:35 @25
import numpy as np
import matplotlib.pyplot as plt
from os import path
#6:36 @2560x1440 500 iter
#2:51 @2560x1440 200 iter
#0:56 @2560x1440 50 iter
#1:35 @2560x1440 100 iter
#0:53 @1920x1080 100 iter
#0:24 @1280x720 100 iter -> run overnight to generate 1000pngs
#make a video out of images in blender
#resolution
col=720
rows=1280
#initial window
x1=0.24#-0.78#-2#this initial window captures the whole Mandelbrot
x2=0.39#-0.73#1
y1=-0.1#0.03#-1
y2=0.08#0.13#1
#DON'T FORGET TO CHANGE THE OUTPATH!!!
outpath='C:\Users\yourfilepath\Seahorse valley'
#run at n=1000 overnight
for k in range(3): #generates n images (WARNING: this can take a while for n>5 at high res)
zoom=0.1
def mandelbrot(x,c,maxiter):
c=complex(x,c) #x+ci
z=0.0j #j is python for imaginary numbers (i)
for i in range(maxiter):
z=z**2+c #change power of z to generate other epicycloids
if(z.real*z.real+z.imag*z.imag)>=4:
return i
return maxiter
result=np.zeros([rows,col])
for rowindex, x in enumerate(np.linspace(x1,x2,num=rows)):
for colindex, c in enumerate(np.linspace(y1,y2,num=col)):
result[rowindex,colindex]=mandelbrot(x,c,40)
plt.figure()
plt.imshow(result.T, cmap='jet_r') #[x1,x2,y1,y2])
plt.title('Mandelbrot')
plt.xlabel('Real C')
plt.ylabel('Complex C')
plt.savefig(path.join(outpath,'Seahorse {0}.png'.format(k)),dpi=1000)
#zooms in for the next image.
x1=x1+zoom #Change the zoom per iteration
x2=x2-zoom #changing individial values allows for panning
y1=y1+zoom #need to figure out how to adjust pan to stay on fractal
y2=y2-zoom
zoom+=zoom/2
#elephant valley coordinates in here
#(0.24,0.39,num=rows)
#(-0.1,0.08,num=col)
#coords for seahorse valley
#(-0.78,-0.73,num=rows)
#(0.03,0.13,num=col)
我可以缩放和平移,但如何自动平移以保持对分形的关注?我想在睡觉时运行这段代码。我看到了更多实现这一点的方法
x = 0.267334004847543;
y =-0.102419298460876;
这是一个很好的螺旋状目标,可向上缩放1.0e14
此处屏幕截图:
(-0.75,0.0)
为中心:
谢谢你的回复!自从我发帖以来,我已经尝试了你提到的前两种方法。如果我想实现一个边界检测系统来引导变焦,你会建议我怎么做?我不熟悉这种技术。@Ferko:你用探测器搜索整个图像。。。因此,通常对于任何测试位置,将周围的所有像素移到一定距离,然后从中计算出一些特征,如最小、最大强度、平均强度、直方图等。。。然后与选定的特征(从前一帧)比较,如果足够接近考虑它你的特点新的位置(变焦后的变化)…所以再次“居中”并设置为新的选定特征。。。