【发布时间】:2014-08-01 02:51:17
【问题描述】:
在渲染巴恩斯利蕨类分形时,我想出了单色图像或最多四色图像,即左下角、右下角、底部茎和叶子的其余部分。例如,这是我得到的图像:
然而我想要的是给叶子带来阴影,让茎更粗,颜色不同,比如:
我对可以使用的算法进行了一些挖掘,然后我在Draves's paper about fractal flames 中读到,在迭代函数系统的迭代过程中,如果我们使用单一颜色,可能会多次渲染单个点这会导致信息丢失,因此我们需要创建一个点被渲染多少次的直方图,然后使用带有颜色阴影对数密度着色的直方图执行渲染通道。
我已经达到了我有直方图但不知道如何使用它来渲染阴影或使用对数密度渲染技术的地步。 有人可以帮助我进行此类渲染,或者至少将我引导到可以通过实际示例阅读更多相关信息的来源。
这是我尝试过的:
AffineTransformation f1 = new AffineTransformation(0,0,0,0.25,0,-0.4);
AffineTransformation f2 = new AffineTransformation(0.95,0.005,-0.005,0.93,-0.002,0.5);
AffineTransformation f3 = new AffineTransformation(0.035,-0.2,0.16,0.04,-0.09,0.02);
AffineTransformation f4 = new AffineTransformation(-0.04,0.2,0.16,0.04,0.083,0.12);
int N=Width*Height;
int pixelhistogram[] = new int[N];
for(int i=0;i< N*25;i++)
{
Point newpoint = new Point();
double probability = Math.random();
if(probability < 0.01)
{
newpoint = f1.transform(point);
}
else if(probability < 0.94)
{
newpoint = f2.transform(point);
}
else if(probability < 0.97)
{
newpoint = f3.transform(point);
}
else
{
newpoint = f4.transform(point);
}
point = newpoint;
// Translating the point to pixel in the image and
// incrementing that index in the pixelHistogram array by 1
// W and H are the Width and Height
int X=((int)(point.getX()*W/3)+W/2)/2 + W/4-1;
int Y=H-((int)(point.getY()*H/8) + H/9) -1;
pixelhistogram[W*Y+X]++;
}
// Now that I have the pixelhistogram
// I don't know how to render the shades using this
AffineTransformation 是一个简单的类,它对一个点执行仿射变换。我省略了代码,否则问题会变得太冗长。
【问题讨论】:
标签: java algorithm colors fractals