哪个颜色渐变用于维基百科中的mandelbrot?

Afr*_*Afr 21 c++ qt gradient colors mandelbrot

在维基百科的Mandelbrot页面上,有很多美丽的Mandelbrot图像.

细节Mandelbrot

我也刚刚实现了自己的mandelbrot算法.给定n是用于计算每个像素的迭代次数,我将它们从黑色到绿色非常简单地着色(使用C++和Qt 5.0):

QColor mapping(Qt::white);
if (n <= MAX_ITERATIONS){
    double quotient = (double) n / (double) MAX_ITERATIONS;
    double color = _clamp(0.f, 1.f, quotient);
    if (quotient > 0.5) {
        // Close to the mandelbrot set the color changes from green to white
        mapping.setRgbF(color, 1.f, color);
    }
    else {
        // Far away it changes from black to green
        mapping.setRgbF(0.f, color, 0.f);
    }
}
return mapping;
Run Code Online (Sandbox Code Playgroud)

我的结果看起来像这样:

在此输入图像描述

我已经非常喜欢它,但维基百科中的图像使用了哪种颜色渐变?如何使用给定n的迭代计算该梯度?

(这个问题与平滑无关.)

Nig*_*fik 25

渐变可能来自Ultra Fractal.它由5个控制点定义:

Position = 0.0     Color = (0,   7,   100)
Position = 0.16    Color = (32,  107, 203)
Position = 0.42    Color = (237, 255, 255)
Position = 0.6425  Color = (255, 170, 0)
Position = 0.8575  Color = (0,   2,   0)
Run Code Online (Sandbox Code Playgroud)

其中position位于[0,1]范围内,颜色是RGB从0到255.

问题在于它不是线性渐变.点之间的插值是立方(或类似的).下图显示了线性和单调立方插值之间的差异:

线性与立方梯度

如你所见,立方体更平滑,更"漂亮".我使用单调立方插值来避免可能由基本立方体引起的颜色范围的"过冲".插值的单调立方体总是在输入点的范围内(0-255).

我使用以下代码来计算基于迭代的颜色i:

double size = Math.Sqrt(re * re + im * im);
double smoothed = Math.Log(Math.Log(size) * ONE_OVER_LOG2) * ONE_OVER_LOG2;
int colorI = (int)(Math.Sqrt(i + 1 - smoothed) * gradient.Scale + gradient.Shift) % colors.Length;
Color color = colors[colorI];
Run Code Online (Sandbox Code Playgroud)

i分歧的迭代次数reim分叉坐标在哪里是gradient.Scale256,gradient.Shift是0,并且colors是上面显示的具有预离散梯度的数组.它的长度通常是2048.


Afr*_*Afr 17

好吧,我使用Photoshop吸管对维基百科中使用的颜色进行了一些逆向工程.此渐变有16种颜色:

  R   G   B
 66  30  15 # brown 3
 25   7  26 # dark violett
  9   1  47 # darkest blue
  4   4  73 # blue 5
  0   7 100 # blue 4
 12  44 138 # blue 3
 24  82 177 # blue 2
 57 125 209 # blue 1
134 181 229 # blue 0
211 236 248 # lightest blue
241 233 191 # lightest yellow
248 201  95 # light yellow
255 170   0 # dirty yellow
204 128   0 # brown 0
153  87   0 # brown 1
106  52   3 # brown 2
Run Code Online (Sandbox Code Playgroud)

只需使用模数和QColor数组,我就可以迭代渐变中的所有颜色:

if (n < MAX_ITERATIONS && n > 0) {
    int i = n % 16;
    QColor mapping[16];
    mapping[0].setRgb(66, 30, 15);
    mapping[1].setRgb(25, 7, 26);
    mapping[2].setRgb(9, 1, 47);
    mapping[3].setRgb(4, 4, 73);
    mapping[4].setRgb(0, 7, 100);
    mapping[5].setRgb(12, 44, 138);
    mapping[6].setRgb(24, 82, 177);
    mapping[7].setRgb(57, 125, 209);
    mapping[8].setRgb(134, 181, 229);
    mapping[9].setRgb(211, 236, 248);
    mapping[10].setRgb(241, 233, 191);
    mapping[11].setRgb(248, 201, 95);
    mapping[12].setRgb(255, 170, 0);
    mapping[13].setRgb(204, 128, 0);
    mapping[14].setRgb(153, 87, 0);
    mapping[15].setRgb(106, 52, 3);
    return mapping[i];
}
else return Qt::black;
Run Code Online (Sandbox Code Playgroud)

结果看起来非常像我在寻找:

曼德尔布罗特集

:)