缩放时如何调整平移

时间:2019-04-24 13:10:06

标签: 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 @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)

我可以缩放和平移,但是如何自动平移以保持对分形的关注?我想在睡觉时运行这段代码。

1 个答案:

答案 0 :(得分:0)

我看到了实现这一目标的更多方法

  1. 预定位置

    使用通往某处的预定路径。但是为此,您需要首先手动放大到某个有趣的位置,然后仅插入位置并从开始视图缩放到目标视图。

    对于未知目标位置(未预先计算),这是不可能的。

    例如,尝试放大到该位置:

    x  = 0.267334004847543;
    y  =-0.102419298460876;
    

    这是一个不错的螺旋状,就像目标对齐以放大1.0e14此处的屏幕截图:

    spiral fixed position

  2. 您可以使用分形中的特定位置,由于对称性,该位置始终在分形中...

    例如以(-0.75,0.0)为中心:

    fixed position fixed position fixed position fixed position

  3. 锁定某种功能并将其平移到预定的视图位置

    例如,检测包含边界像素和彩色像素之间指定比率的区域,并将其平移到某个固定的视图位置(例如中心或其他位置)。

    feature

    该功能可以是任何东西,但我建议避免进行形状检测,因为这种分形帐篷可以将缩放和平移中的自身形状更改为开始时不会期望的野生形状...

相关问题