# 分形逃逸时间算法中的 Normalized Iteration Count（NIC）技术 让颜色更柔和

### Normalized Iteration Count (NIC) 技术解析

μ=n+1−  log(log(∣Z(n)∣))/ log(p)

mu = n + 1 - log (log (|Z(n)|) ) / log (p)

• Zn 表示迭代次数，
• Z(n) 表示最后一次迭代后复数Z的模长
• p 通常取为2。

### 实现代码示例

#### Ruby 实现

Ruby

NormalizedIterationCount = lambda do |fractal|
z = fractal.args[:z]**2 + fractal.c; fractal.last_iteration += 1
z = z**2 + fractal.c; fractal.last_iteration += 1

modulus = Math.sqrt(fractal.args[:z].real**2 + fractal.args[:z].imag**2).abs
mu = fractal.last_iteration + Math.log(2 * Math.log(fractal.bailout)) - Math.log(Math.log(modulus)) / Math.log(fractal.args[:p])

(mu / fractal.max_iterations * 765).to_i
end

#### Maxima 实现

Lisp

GiveNormalizedIteration(z,c,E_R,i_Max):=
/* */
block(
[i:0,r],
while abs(z)<E_R and i<i_Max
do (z:z*z + c,i:i+1),
r:i-log2(log2(cabs(z))),
return(float(r))
)\$

#### C 语言伪代码实现

C

int iter_count = 0;
complex Z, C;
loop (forever) {
Z = Z*Z +C;
iter_count ++;
float modulus = sqrt (ReZ*ReZ + ImZ*ImZ);
if (modulus > escape_radius) goto stop;
if (iter_count > maxiter) goto stop;
}

stop:
Z = Z*Z +C; iter_count ++;    // a couple of extra iterations helps
Z = Z*Z +C; iter_count ++;    // decrease the size of the error term.
float modulus = sqrt (ReZ*ReZ + ImZ*ImZ);
float mu = iter_count - (log (log (modulus)))/ log (2.0);
color_value = colormap_lookup (mu);
draw_pixel (C, color_value);

|
7天前
|

24 9
|
22天前
|

17 1
|
23天前
|

20 0
|
23天前
|

22 0
|
23天前
|

13 0
|
23天前
|
Java BI C#

16 0
|
23天前
|

14 0
|
23天前
|

13 0
|
23天前
|

15 0
|
23天前
|

23 0