跳轉到內容

分形/xaos

來自 Wikibooks,開放世界的開放書籍

XaoS 是一個用 C++ 和 JS 編寫的互動式分形縮放程式。它允許使用者即時連續放大或縮小分形。

這裡是非官方的 XaoS wiki。





演算法

[編輯 | 編輯原始碼]

Hubička 演算法

[編輯 | 編輯原始碼]

XaoS 最初只是一個“寫得不好的”Mandelbrot 瀏覽器[1],直到 Jan Hubička 添加了高效縮放(= 即時縮放[2][3],使用了一種有時稱為 XaoS 演算法或 Hubička 演算法的技術。

當時,分形縮放電影是透過完全重新計算每一幀來製作的,即使它們自然地與彼此共享大部分割槽域。這使得在沒有非常強大的計算機的情況下,互動式縮放成為不可能。[4] 此外,除非使用更多處理來進行抗鋸齒,否則重新計算每一幀會產生“閃爍”效果,因為小的明亮區域會在畫素之間出現然後消失。[5]

然而,允許使用者縮放,而不是像Fractint那樣跳躍,似乎是與分形互動最自然的方式。為了建立一個互動式縮放,Hubička 需要找到一種方法來儲存已經完成的計算。儲存每個計算過的畫素會佔用太多記憶體,因此 Hubička 演算法只儲存上一幀,而不是記住每個畫素的位置,它可以將它們對齊成行和列並記住它們。

XaoS 演算法中最困難的部分是選擇將儲存的行和列繪製在哪裡。這樣做錯誤會導致影像失真,但必須快速完成才能有用。在嘗試了幾種不同的啟發式方法之後,最終將這個問題視為一個最佳化問題。

剩餘的行和列的顏色與最接近的行/列相同,並在CPU有時間這樣做時被重新計算。這在保持縮放進行和提高細節水平之間取得了平衡。計算影像正在縮放到的區域的優先順序更高,因為這些區域將在螢幕上停留時間最長,而且這很可能是使用者正在檢視的地方。縮小,則相反,優先順序在邊緣。[5]

Hubička 演算法也可以應用於放大其他畫素是計算出來的影像,並且已在其他軟體中使用,例如 rtzme 複函式繪圖程式[6],以及其他分形縮放器。

命令列選項

[編輯 | 編輯原始碼]

要找到它,使用 

xaos -help

輸出是 

 XaoS3.5 help text
 (This help is genereated automagically. I am sorry for all inconvencies)

option string   param   description

 -delay          number
                  Delay screen updates (milliseconds)
 -driver         string
                  Select driver
 -list            List available drivers. Then exit
 -config          Print configuration. Then exit
 -speedtest       Test speed of calculation loop. Then exit
 -threads        number
                  Set number of threads (CPUs) to use
 -pipe           string
                  Accept commands from pipe (use "-" for stdin)
 -maxframerate   number
                  Maximal framerate (0 for unlimited - default)

Screen size options:

  Knowledge of exact screen size makes random dot stereogram look better. 
  Also is used for choosing correct view area

 -screenwidth    f.point
                  exact size of screen in centimeters
 -screenheight   f.point
                  exact size of screen in centimeters

  Use this option in case you use some kind of virtual screen
  or something similar that confuses previous options

 -pixelwidth     f.point
                  exact size of one pixel in centimeters
 -pixelheight    f.point
                  exact size of one pixel in centimeters
 -formula        string
                  user formula
 -forminit       string
                  z0 for user formula

Animation rendering:

 -render         string
                  Render animation into seqence of .png files
 -basename       string
                  Name for .png files (XaoS will add 4 digit number and extension
 -size           string
                  widthxheight
 -renderimage    string
                  256 or truecolor
 -renderframerate  f.point
                  framerate
 -antialiasing    Perform antialiasing (slow, requires quite lot of memory)
 -alwaysrecalc    Always recalculate whole image (slowes down rendering, increases quality)
 -rendervectors   Render motion vectors (should be used for MPEG encoding)
 -iframedist     number
                  Recommended distance between I frames in pat file (should be used for MPEG encoding)

X11 driver options:

 -display        string
                  Select display
 -size           string
                  Select size of window (WIDTHxHEIGHT).
 -sync            Generate sync signals before looking for events. This
			helps on old and buggy HP-UX X servers.
 -shared          Use shared colormap on pseudocolor display.
 -usedefault      Use default visual if autodetection causes troubles.
 -nomitshm        Disable MITSHM extension.
 -fullscreen      Enable fullscreen mode.
 -windowid       number
                  Use selected window.
 -window-id      number
                  Use selected window.
 -root            Use root window.

AA driver options:

 -aadriver       string
                  Select display driver used by aa-lib
 -kbddriver      string
                  Select keyboard driver used by aa-lib
 -mousedriver    string
                  Select keyboard driver used by aa-lib
 -font           string
                  Select font
 -width          number
                  Set width
 -height         number
                  Set height
 -minwidth       number
                  Set minimal allowed width
 -minheight      number
                  Set minimal allowed height
 -maxwidth       number
                  Set maximal allowed width
 -maxheight      number
                  Set maximal allowed height
 -recwidth       number
                  Set recommended width
 -recheight      number
                  Set recommended height
 -normal          enable usage of narmal{{typo help inline|reason=similar to harmal|date=September 2022}} characters
 -nonnormal        disable usage of normal characters
 -dim             enable usage of dim(half bright) characters
 -nodim           disable usage of dim(half bright) characters
 -bold            enable usage of bold(double bright) characters
 -nobold          disable usage of bold(double bright) characters
 -boldfont        enable usage of boldfont characters
 -noboldfont      disable usage of boldfont characters
 -reverse         enable usage of reversed characters
 -noreverse       disable usage of reversed characters
 -all             enable usage of reserved characters
 -eight           enable usage of non ansi characters
 -extended        enable usage of extended character set
 -inverse         enable inverse
 -bright         number
                  set bright (0-255)
 -contrast       number
                  set contrast (0-255)
 -gamma          f.point
                  set famma (0-1)
 -nodither        Disable dithering
 -floyd_steinberg   Enable floyd steinberg dithering
 -error_distribution   Enable error distribution dithering
 -random         number
                  Set random dithering value
 -dimmul         f.point
                  Multiply factor for dim color (5.3)
 -boldmul        f.point
                  Multiply factor for bold color (5.3)
 -nomouse         Disable mouse

Command line options only

 -print_menus     print menus specifications of all menus
 -print_menu     string 
                  print menu specification
 -xshl_print_menustring 
                  print menu specification in xshl format
 -xshl_print_menus print all menu specifications in xshl format
 -print_dialog   string 
                  print dialog specification

File

 -loadpos        input_file 
                  Load
 -savepos        output_file 
                  Save
 -record         output_file 
                  Record
 -play           input_file 
                  Replay
 -saveimg        output_file 
                  Save image
 -loadexample     Load random example
 -savecfg         Save configuration

Fractal

 -usrform        string 
                  User formula
 -usrformInit    string 
                  User initialization
 -perturbation   real_number  real_number 
                  Perturbation
 -initstate       Reset to defaults
 -julia          on|off 
                  Julia mode
 -view           real_number real_number real_number real_number 
                  View
 -angle          real_number 
                  Set angle
 -plane          integer 
                  Set plane
 -incoloring     integer 
                  Inside coloring mode
 -outcoloring    integer 
                  Outside coloring mode
 -intcoloring    integer 
                  Inside truecolor coloring mode
 -outtcoloring   integer 
                  Outside truecolor coloring mode
 -juliaseed      real_number  real_number 
                  Julia seed

Calculation

 -periodicity     Periodicity checking
 -maxiter        integer 
                  Iterations
 -bailout        real_number 
                  Bailout
 -fastjulia       Fast julia mode
 -range          integer 
                  Solid guessing range

Filters

 -edge            Edge detection
 -edge2           Edge detection2
 -threed          Pseudo 3d
 -starfield       Starfield
 -stereogram      Random dot stereogram
 -interlace       Interlace filter
 -blur            Motionblur
 -emboss          Emboss
 -palettef        Palette emulator
 -anti            Antialiasing
 -truecolor       Truecolor emulator

UI

 -letterspersec  integer 
                  Letters per second
 -autopilot       Autopilot
 -inhibittextoutput VJ mode
 -recalculate     Recalculate
 -interrupt       Interrupt
 -speed          real_number 
                  Zooming speed
 -fixedstep       Fixed step
 -nogui           Disable XaoS's builtin GUI
 -status          Status
 -ministatus      Ministatus

Misc

 -playstr        string 
                  Play string
 -text           string 
                  Display text
 -color          white|black|red 
                  Color
 -textposition   left|center|right top|middle|bottom 
                  Text position
 -message        string 
                  Message

Help

 -help            Help

Formulae

 -mandel          Mandelbrot
 -mandel3         Mandelbrot^3
 -mandel4         Mandelbrot^4
 -mandel5         Mandelbrot^5
 -mandel6         Mandelbrot^6
 -newton          Newton
 -newton4         Newton^4
 -barnsley        Barnsley1
 -barnsley2       Barnsley2
 -barnsley3       Barnsley3
 -octal           Octal
 -phoenix         Phoenix
 -magnet          Magnet
 -magnet2         Magnet2

More formulae

 -trice           Triceratops
 -catseye         Catseye
 -mbar            Mandelbar
 -mlambda         Lambda
 -manowar         Manowar
 -spider          Spider
 -sier            Sierpinski
 -carpet          S.Carpet
 -koch            Koch Snowflake
 -hornflake       Spidron hornflake
 -user            User defined

Palette

 -defpalette      Default palette
 -randompalette   Random palette
 -palette        integer integer integer 
                  Custom palette
 -cycling         Color cycling
 -cyclingspeed   integer 
                  Color cycling speed
 -shiftpalette   integer 
                  Shift palette

Dynamic resolution

 -fastmode       zero|never|animation|new|allways 
                  Dynamic resolution mode

Rotation

 -rotationspeed  real_number 
                  Rotation speed
 -autorotate     on|off 
                  Automatic rotation
 -fastrotate     on|off 
                  Fast rotation mode

Quit

 -quit            Exit now

Xaos 動畫檔案 (*.xaf ) 是一個包含用於生成影像序列的函式的檔案

例如 

xaos-3.5/tutorial/julia.xaf

要建立 xaf 檔案,請使用記錄功能,語法 

(record bool [ file ])

示例 

 (record #t)

或 

(record #f)

如何從 xaf 檔案渲染影像序列 

xaos -render [xpf_filename] -size 352x240 -antialiasing -renderframerate 24 -basename [basename]

xpf 代表 **Xaos 位置檔案**。該檔案是人類可讀的,並且可以在儲存後輕鬆地手動改進,或者用作動畫的基礎。[7]

例如,請參見 

標準檢視(無縮放的 Mandelbrot 集 = 影像) 

;Position file automatically generated by XaoS 3.5
;  - a real-time interactive fractal zoomer
;Use xaos -load <filename> to display it
(initstate)
(defaultpalette 0)
(formula 'mandel)
(view -0.75 0 2.5 2.5)

當我們切換到 Julia 模式(停用 Mandelbrot 模式)時 

(initstate)
(defaultpalette 0)
(formula 'mandel)
(julia #t)
(view -0.75 0 2.5 2.5)

或將 c 值(= **Julia 種子**)從 c=0 更改為 c= -1

(initstate)
(defaultpalette 0)
(formula 'mandel)
(juliaseed -1 0)
(julia #t)
(view -0.8434 0.07535 2.744 2.744)

或顯示平面值(預設 = 0 不顯示) 

(initstate)
(defaultpalette 0)
(formula 'mandel)
(juliaseed -1 0)
(julia #t)
(plane 0)
(view -0.9127 -0.09268 2.285 2.285)

minibrot.xpf 

(initstate)
(palette 1 860134713 0)
(formula 'mandel)
(outcoloring 1)
(view -1.9854567 -1.351727E-05 0.00029196024 0.00029196024)

其中檢視[8] 描述了 視窗(平面的矩形部分)

 view float float float float
 view centerRe centerIm radius angle

xpf 檔案列表 

為了描述 平面(檢視),Xaos 使用

  • 指令碼中的 4 個數字
  • 選單中的 3 個數字

Xaos 用“半徑”來稱呼它,但它被定義為:” (x2-x1= 寬度) 和 y2-y1= 高度 的較大值。“ 這就是為什麼在 Xaos 中可以將半徑設定為 2/縮放的原因。

要使用 **選單** 在 Xaos 中設定相同的視點,請設定 3 個數字來定義圓形

  • 中心的實部為 (x1+x2)/2
  • 中心的虛部為 (y1+y2)/2
  • “半徑” = x2-x1 和 y2-y1 的較大值。

其中,可見點的左上角和右下角的座標,指定座標為四個數字 x1、y1、x2、y2。

在 **xpf 檔案** 中,平面可以用 4 個浮點數描述:[9]

  • 中心的實部
  • 中心的虛部
  • 世界座標系中的寬度 = x2-x1,稱為“實際半徑”。
  • 世界座標系中的高度 = y2-y1,稱為“虛半徑”。

語法

(view float float float float)

示例

(view -0.75 0 2.5 2.5)
"People specify fractal coordinates in many ways. Some people use the coordinates of the upper-left and lower-right visible points, specifying the coordinates as four numbers x1, y1, x2, y2. 
To set the same viewpoint in XaoS, set the real portion of the center to (x1+x2)/2, the imaginary   part of center to (y1+y2)/2, and the radius to the greater of x2-x1 and y2-y1.
Other programs use a zoom factor instead of a radius. For these, you can set the radius to 2/zoom."[10]
" ... lets you specify an ellipse instead of a circle. You can specify both a real and an imaginary radius "
(initstate)
(defaultpalette 0)
(formula 'user)
(usrform "Z^2+C")
(usrformInit "")
(view -0.4641 0.01977 2.444 2.444)
(bailout 6)

逃逸值或逃逸半徑。Xaos 在這裡使用逃逸半徑的平方,所以如果你想要逃逸值為 2,在這裡輸入 2*2 = 4。

語法:[11]

 (formula keyword)

示例

 (formula mandel)
名稱 描述 教程 使用者公式
mandel 標準曼德勃羅集或朱利亞集。 mset.xaf Z^2+C
mandel3 示例 power.xaf Z^3+C
mandel4 示例 power.xaf Z^4+C
mandel5 示例 power.xaf Z^5+C
mandel6 示例 power.xaf Z^6+C
newton 這是牛頓求解多項式根的近似方法。它使用多項式 x^3=1 newton.xaf
barnsley 示例 示例 示例
octo 示例 示例 示例
phenix 示例 示例 示例
magnet
trice

更改命名公式(選單/分形/公式)不會更改使用者公式!!!

語法

(plane integer)

允許的值:[12]

名稱 描述
0 mu 普通複平面(預設)
1 1/mu 反演:舊的無窮大現在在 0,而舊的 0 現在在無窮大。
2 1/(mu+0.25) 類似於反演,但也會將中心移到曼德勃羅集之外,使其看起來像拋物線。
3 lambda lambda 平面
4 1/lambda lambda 平面的反演
5 1/(lambda-1) 具有移動中心的反演
6 1/(mu-1.40115) 具有移動中心的反演
// from xaos-3.5\src\engine\plane.c 
/* 
 *     XaoS, a fast portable realtime fractal zoomer 
 *                  Copyright (C) 1996,1997 by
 *
 *      Jan Hubicka          (hubicka@paru.cas.cz)
 *      Thomas Marsh         (tmarsh@austin.ibm.com)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
CONST char *CONST planename[] = {
    "mu",
    "1/mu",
    "1/(mu+0.25)",
    "lambda",
    "1/lambda",
    "1/(lambda-1)",
    "1/(mu-1.40115)",
    NULL
};

// include/complex.h:57:
// #define myabs(x) ((x)>0?(x):-(x))

REGISTERS(3)
void recalculate(int plane, number_t * x1, number_t * y1)
{
    number_t x = *x1, y = *y1;
    switch (plane) {
    case 1:
	{			/* 1/mu */
	    number_t t;
	    if (myabs(x) + myabs(y) < 0.000001)
		t = INT_MAX, y = INT_MAX;
	    else {

		c_div(1, 0, x, y, t, y);
	    }
	    x = t;
	}
	break;
    case 2:
	{			/* 1/(mu + 0.25) */
	    number_t t;
	    if (myabs(x) + myabs(y) < 0.000001)
		t = INT_MAX, y = INT_MAX;
	    else {

		c_div(1, 0, x, y, t, y);
	    }
	    x = t;
	    x += 0.25;
	}
	break;
    case 3:			/* lambda */
	{
	    number_t tr, ti, mr, mi;

	    mr = x, mi = y;
	    c_pow2(x, y, tr, ti);
	    c_div(tr, ti, 4, 0, x, y);
	    c_div(mr, mi, 2, 0, tr, ti);
	    c_sub(tr, ti, x, y, mr, mi);
	    x = mr, y = mi;
	}
	break;
    case 4:			/* 1/lambda */
	{
	    number_t tr, ti, mr, mi;

	    c_div(1, 0, x, y, tr, y);
	    x = tr;
	    mr = x, mi = y;
	    c_pow2(x, y, tr, ti);
	    c_div(tr, ti, 4, 0, x, y);
	    c_div(mr, mi, 2, 0, tr, ti);
	    c_sub(tr, ti, x, y, mr, mi);
	    x = mr, y = mi;
	}
	break;
    case 5:			/* 1/(lambda-1) */
	{
	    number_t tr, ti, mr, mi;

	    c_div(1, 0, x, y, tr, y);
	    x = tr + 1;
	    mr = x, mi = y;
	    c_pow2(x, y, tr, ti);
	    c_div(tr, ti, 4, 0, x, y);
	    c_div(mr, mi, 2, 0, tr, ti);
	    c_sub(tr, ti, x, y, mr, mi);
	    x = mr, y = mi;
	}
	break;
    case 6:
	{			/* 1/(mu + 0.25) */
	    number_t t;
	    if (myabs(x) + myabs(y) < 0.000001)
		t = INT_MAX, y = INT_MAX;
	    else {

		c_div(1, 0, x, y, t, y);
	    }
	    x = t;
	    x -= 1.40115;
	}
	break;
    default:
	break;
    }
    *x1 = x;
    *y1 = y;
}

perturbation

[編輯 | 編輯原始碼]

它更改了軌道開始的點。傳統上使用零。[13]

(perturbation complex)
 info xaosdev.info

如何渲染大影像?

[編輯 | 編輯原始碼]

這並不簡單。[14] 可以使用以下方法:

  • 使用選單中的動畫(“將分形儲存到 .xpf 檔案(檔案->儲存),然後使用 Misc->Render Animation 功能渲染它”。[15]
  • 使用命令列選項[16]


XaoS -render fractal.xpf -size 18000x12000

如何更改解析度

[編輯 | 編輯原始碼]

"XaoS 通常以低解析度(約 320x200)啟動,以加快計算速度。如果您有快速的計算機或需要儲存更大的 .gif 影像,您可以更改解析度。這可以透過在全屏驅動程式中按 '=' 或簡單地調整 XaoS 視窗大小來完成。" [17]

  • 使用 xpf 檔案
  • 使用主選單/分形/使用者公式
  • 新增內建公式[18]
  • 編輯 src/engine/formulas.c 中的原始碼

formulas.c

[編輯 | 編輯原始碼]
#define VARIABLES register number_t n,sqrr,sqri,zre1,zim1;
#define INIT sqri=zim*zim,n=zre,zre=pre,pre=n,n=zim,zim=pim,pim=n,n=(number_t)1;
#define BTEST greater_then_1Em6(n)
#define FORMULA \
    zre1 = zre; \
    zim1 = zim; \
    n = zim * zim; \
    sqri = zre * zre; \
    sqrr = sqri - n; \
    sqri = n + sqri; \
    n = 0.3333333333 / ((sqri * sqri)); \
    zim = (0.66666666) * zim - (zre + zre) * zim * n + pim; \
    zre = (0.66666666) * zre + (sqrr) * n + pre; \
    zre1 -= zre; \
    zim1 -= zim; \
    n = zre1 * zre1 + zim1 * zim1;
#define CALC newton_calc
#include "docalc.c"

修改程式碼後,您必須重新編譯 XaoS 才能生效。[19]

參考文獻

[編輯 | 編輯原始碼]
  1. XaoS 手冊頁
  2. 由 Zoltán Kovács 編寫的即時縮放數學引擎
  3. xaosdev.info:演算法
  4. CS and Dance (PDF), archived from the original on 2005-12-20
  5. a b Hubička, Jan (1997), XaoS 演算法, archived from the original on 2014-03-28.
  6. 複平面的視覺化, archived from the original on 2006-10-17
  7. Xaos 格式說明
  8. Xaos - 檢視
  9. Xaos - 平面說明
  10. Xaos - 檢視
  11. Xaos 文件 - 公式
  12. GNU XaoS » 文件 » XaoS » 平面
  13. Xaos 文件 - 擾動
  14. 無法(輕鬆)渲染高解析度靜態影像 #53
  15. xaos-users 論壇:解析度
  16. xaos-users 論壇:Mac OSX 上的更高解析度
  17. Xaos 教程
  18. Xaos 文件:由阿帕德·費凱特新增內建公式
  19. xaos-users 論壇:牛頓分形
華夏公益教科書