Craig Hales讓我開始創建Mandelbrot設置圖像和視頻序列(參見 https://community.jmp.com/t5/Uncharted/Mandelbrot-shallow-tour/ba-p/53295 因為我得到了我的開始)。 這是一個有趣的學習經歷,不僅關於分形集的內部,還有關於JSL編程,視頻編輯和為YouTube創建內容。
我最近遇到了一些關於Mandelbrot電源組的視頻(有時也被稱為“Multibrot Set”( https://en.wikipedia.org/wiki/Multibrot_set))。 我不會詳細介紹Mandelbrot電源功能的所有細節,但您使用它的方式如下:
- 讓 f_c(z)= z ^ d + c(其中z是複數 z = x + iy,c = xc + i yc)。
- 對於給定的值 C ,迭代如下
- 讓 z_0 = 0
- 讓 f_c(z_i)=(z_(i-1))^ d + c
- 重複直到
- 已經滿足了“救助”次數的迭代(即 i>指定的最大迭代次數 ) 要么
- ||ž|| =(x ^ 2 + y ^ 2)>(停止半徑)^ 2 (哪裡停止半徑通常等於2,但可能更小)
- 記錄價值一世作為點的迭代次數(或深度) C
雖然有一個JSL函數Mandelbrot()可以幫助生成mandelbrot集圖像,但是要做多佈景集,我需要編寫自己的JSL函數。
f_mandelbrotpowercount = Function( {x, y, d = 2, radius=2, max_n = 100},
{zx, zy, n_iter = 0, r = 0, theta = 0},
if ( x ^ 2 + y ^ 2 <4,
While( (r < radius) & (n_iter < max_n),
zx = r ^ d * Cos( d * theta ) + x;
zy = r ^ d * Sin( d * theta ) + y;
r = Sqrt( zx ^ 2 + zy ^ 2 );
theta = ArcCosine( zx / r ) * ((zy > 0) * 2 - 1);
n_iter++;
);
);
n_iter;
);如果您對複數和復數的乘法有一點了解,您可以看到我正在利用它的標識
z = x + iy = R e ^(i Theta)
哪裡
R = sqrt(x ^ 2 + y ^ 2),Theta = ArcCosine(x / R) ( 西塔被約束在兩者之間 (-Pi,PI)
語法是:
f_mandelbrotpowercount(XC,YC,<功率= 2>,<半徑= 2>,)
默認功率為2,默認半徑為2,默認救助交互為100,應返回與JSL Mandelbrot()函數相同的結果。
如果計算此函數的結果,則當power = 2時,跨越矩形定義
左x值= -2.27,右x值= 2.27
頂部y值= 1.5,底部y值= -1.5
然後根據縮放結果對結果進行一些縮放並設置RGB顏色,您可以得到這樣的圖像
經典的Mandelbrot設置圖像!
當power = 7時,你得到一個這樣的圖像!
Mandelbrot動力裝置,功率= 7
創建映像文件的JSL就在這裡
pow=7;<BR />xleft = -1.5*1640/1080;<BR />xright = 1.5*1640/1080;<BR />ytop = 1.5;<BR />ybottom = -1.5;
Parallel Assign(
{f = Name Expr( f_mandelbrotpowercount ), p = pow},
mat[r( ytop, ybottom ), c( xleft, xright )] = f( c, r, p )
);
mat = mat / 100;
green = mat ^ .3;
red = mat ^ 6;
blue = 1 - mat ^ .2;
img = New Image( "rgb", {red, green, blue} );
img << Save image("power7.png");請注意,這利用了Parallel Assign()JSl函數,允許我使用機器上的所有核心進行計算。 即便如此,此分辨率下的單個圖像也需要2分鐘以上才能生成。
一個非常酷的視覺是觀察當你將功率從2變為10並返回時會發生什麼。 我創建了一個這樣的視頻如果您想觀看它,請將其發佈在YouTube上。 該序列的功率= 2到10,增量為0.005。 創建圖像序列大約需要53個小時。
這是創建圖像序列的完整代碼(公平警告,見上文,我花了53個小時生成圖像!)
Names Default To Here( 1 );
f_mandelbrotpowercount = Function( {x, y, d = 2, radius=2, max_n = 100},
{zx, zy, n_iter = 0, r = 0, theta = 0},
if ( x ^ 2 + y ^ 2 <4,
While( (r < radius) & (n_iter < max_n),
zx = r ^ d * Cos( d * theta ) + x;
zy = r ^ d * Sin( d * theta ) + y;
r = Sqrt( zx ^ 2 + zy ^ 2 );
theta = ArcCosine( zx / r ) * ((zy > 0) * 2 - 1);
n_iter++;
);
);
n_iter;
);
xleft = -1.5*1640/1080;
xright = 1.5*1640/1080;
ytop = 1.5;
ybottom = -1.5;
xres = 1640;
yres = 1080;
filenamebase="m000";
fileindex=100000;
mat = J( yres, xres, . );
For( pow = 2, pow <= 10, pow += .005,
Parallel Assign(
{f = Name Expr( f_mandelbrotpowercount ), p = pow},
mat[r( ytop, ybottom ), c( xleft, xright )] = f( c, r, p )
);
mat = mat / 100;
green = mat ^ .3;
red = mat ^ 6;
blue = 1 - mat ^ .2;
img = New Image( "rgb", {red, green, blue} );
img << Save image("D:\mandelbrot\powerbrosequence\m"||char(fileindex)|| ".png");
fileindex+=1;
);讓我知道您的想法或者您是否有任何疑問。