缩放时如何调整平移 [英] How to adjust panning while zooming

查看:228
本文介绍了缩放时如何调整平移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在缩放到Mandelbrot集合时进行平移,以使函数的分形部分保持在窗口内.该代码输出一系列png图像,以后再制作成视频.现在,我可以进行缩放和平移了,但是我不知道在缩放功能时如何调整平移.

I want to pan while zooming into a Mandelbrot set so that the fractal portion of the function stays within the window. The code outputs a series of png images to later be made into a video. Right now, I have the zooming and panning working but I do not know how to adjust the panning while the function is zooming.

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)

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

I can zoom and pan, but how do I automate the panning to stay focused on the fractal? I want to run this code while I am sleeping.

推荐答案

我看到了更多实现此目的的方法

I see more ways to achieve this

  1. 预定位置

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

Use predetermined path that leads somewhere. But for that you would need to first zoom in manually to some interesting location and then just interpolate position and zoom from start view to target view.

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

Of coarse for unknown target location (not precomputed) is this not possible.

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

For example try to zoom to this location:

x  = 0.267334004847543;
y  =-0.102419298460876;

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

it is nice spiral like target aligned up to zoom 1.0e14here screenshot:

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

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

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

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

For example detect area that contains specified ratio between boundary and colored pixels and pan it to some fixed view position (like center or whatever).

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

The feature can be anything but I would advise to avoid shape detection as this kind of fractal tent to change the shape of itself in zooms and pans to wild shapes one would not expect at start...

这篇关于缩放时如何调整平移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆