algorithm - 在我现有的 Mandelbrot 生成器中实现平滑颜色算法

标签 algorithm mandelbrot

我目前正在编写一个 Mandelbrot 生成器,并偶然发现了一种平滑颜色算法,顾名思义,它创建了一种“平滑颜色”,与我当前的示例相反。

enter image description here

如您所见,边缘情况非常明显且不平滑。

这是我的 drawFractal() 方法:

public static void drawFractal()
{
    Complex Z;
    Complex C;

    double x;
    double y;

    // The min and max values should be between -2 and +2
    double minX = -2.0; // use -2 for the full-range fractal image
    double minY = -2.0; // use -2 for the full-range fractal image
    double maxX = 2.0; // use 2 for the full-range fractal image
    double maxY = 2.0; // use 2 for the full-range fractal image

    double xStepSize = ( maxX - minX ) / width;
    double yStepSize = ( maxY - minY ) / height;
    int maxIterations = 100;
    int maxColors = 0xFF0000;

    // for each pixel on the screen
    for( x = minX; x < maxX; x = x + xStepSize)
    {
        for ( y = minY; y < maxY; y = y + yStepSize )
        {
            C = new Complex( x, y );
            Z = new Complex( 0, 0 );
            int iter = getIterValue( Z, C, 0, maxIterations );

            int myX = (int) ( ( x - minX ) / xStepSize );
            int myY = (int) ( ( y - minY ) / yStepSize );
            if ( iter < maxIterations )
            {
                myPixel[ myY * width + myX ] = iter * ( maxColors / maxIterations ) / 50; 
            }
        }
    }
}

根据平滑颜色伪代码,它要求:

nsmooth := n + 1 - Math.log(Math.log(zn.abs()))/Math.log(2)

话虽如此,从我的方法来看,我拥有的最好的方法是从这一行中得到一点点调整的 RGB:

if ( iter < maxIterations )
{
    myPixel[ myY * width + myX ] = iter * ( maxColors / maxIterations ) / 50; 
}

所以我不知道该怎么办。任何帮助将不胜感激。

附件也是获取我的迭代值的方法:

public static int getIterValue( Complex Z, Complex C, int iter, int maxNumIters )
    {
        if ( Z.getMag() < 2 && iter < maxNumIters )
        {
            Z = ( Z.multiplyNum( Z )).addNum( C );
            iter++;
            return getIterValue( Z, C, iter, maxNumIters );
        }
        else
        {
            return iter;
        }
    }

正如您所知,有一个类返回复数,但这本身应该是不言自明的。

最佳答案

您的getIterValue需要返回一个对象,其中包含Z的最终值以及迭代次数n。然后您的伪代码将转换为

nsmooth := iter.n + 1 - Math.log(Math.log(iter.Z.abs())/Math.log(2))

您可以将其转换为 0 到 1 之间的值

nsmooth / maxIterations

您可以使用它来选择颜色,方式与您已经执行的方式大致相同。

编辑:我查看了一些用于平滑着色的伪代码,我认为第一个日志应该以 2 为底:

nsmooth := iter.n + 1 - Math.log(Math.log(iter.Z.abs())/Math.log(2))/Math.log(2)

关于algorithm - 在我现有的 Mandelbrot 生成器中实现平滑颜色算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23589593/

相关文章:

c++ - Mandelbrot 集不会使用 pthread 加速

java - Mandelbrot set on Java - 我的算法有问题吗?

javascript - 寻找号码选择的可能性

java - 如何根据以前的选择顺序对购物 list 进行排序?

Java小球跑离光标

3d - 曼德尔布罗特集太快达到极限了

python - 如何标准化和标准化字符串数据

algorithm - Elo 对接会也考虑等待时间

c - Julia 用实数设置计算

go - 如何通过计算每个像素内几个点的颜色值并取平均值来减少像素化的影响?