How to adjust panning while zooming

对着背影说爱祢 提交于 2020-05-14 09:11:31

问题


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.


回答1:


I see more ways to achieve this

  1. predetermined location

    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;
    

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

  2. you can use specific locations in fractal which due to symmetry is always inside fractal ...

    for example center on (-0.75,0.0):

  3. Lock onto some kind of feature and pan it to predetermined location of view

    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...



来源:https://stackoverflow.com/questions/55830855/how-to-adjust-panning-while-zooming

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!