【发布时间】:2020-04-12 00:14:24
【问题描述】:
我正在研究 java 中的 julia 集。以下是我的代码:
public class ColorJulia {
// return number of iterations to check z is in the Julia set of c
static int julia(Complex c, Complex z, int maximumIterations) {
for (int t = 0; t < maximumIterations; t++) {
if (z.abs() > 2.0) return t;
z = z.times(z).plus(c);
}
return maximumIterations - 1;
}
public static void main(String[] args) {
double real = -0.8;//Double.parseDouble(args[0]); // a
double imag = 0.1;//Double.parseDouble(args[1]); // b
Complex c = new Complex(real, imag); // c = a + ib
double xmin = -2.0;
double ymin = -2.0;
double width = 4.0;
double height = 4.0;
int n = 512;
int ITERS = 256;
int freq[]=new int[256];
Arrays.fill(freq, 0);
Picture picture = new Picture(n, n);
// read in color map
Color[] colors = new Color[ITERS];
for (int t = 0; t < ITERS; t++)
{
int r = t;
int g = t;
int b = t;
colors[t] = new Color(r, g, b);
}
for (int col = 0; col < n; col++)
{
for (int row = 0; row < n; row++)
{
double x = xmin + col * width / n;
double y = ymin + row * height / n;
Complex z = new Complex(x, y);
int t = julia(c, z, ITERS);
freq[t]++;
Color testPixel = new Color(t,t,t);
picture.set(col, row, testPixel);
}
}
picture.show();
for(int i=0;i<256;i++)
{
System.out.println("freq " + i + " = " + freq[i]);
}
}
}
在 julia set 中,我使用迭代的返回值生成 RGB 颜色。我不知道如何映射这些颜色以获得更好的图像。
【问题讨论】:
-
尝试使用
t / ITERS或255 / ITERS而不是t,这取决于您的像素使用的RGB 强度范围(不是JAVA 编码器)。您还可以通过任何渐变映射将t重新映射为颜色,这是我最喜欢的:RGB of visible spectra 只需线性插值t以匹配波长范围......您也可以交叉检查我的Mandelbrot set I did some years back -
嘿一个错字,第二个温度应该是粗糙的
255*t / ITERS(编辑太晚了)