私はジュリアの画像を作り、これをCでプログラミングしようとしています。私はJuliaセットの画像を作成するアルゴリズムを研究しようとしましたが、ほとんどの例がオンラインで混乱しています(ほとんどの例はコピーされているようですが、ステップごとに何が起こるかほとんど説明していません)。ジュリアは実数で計算する
私は自分のコードをオンラインで見つかったアルゴリズムに合わせて数回書き直しましたが、ほとんど成功しませんでした。現在、私は次のように、各ピクセルの色を定義するために反復機能を使用しています:ループは、私がオンラインで見つける第2のアルゴリズムであるが、また間違っていながら
// Loop through each pixel to work out new image set
int x, y;
for(x = 0; x < SIZE; x++){
for(y = 0; y < SIZE; y++){
int i = iterate(x, y, maxIterations, c);
image[x][y] = i % 256 + 255 + 255 * (i < maxIterations);
}
}
/* Iterate function */
int iterate(int x, int y, int maxI, double c[]){
double z, zx, zy, oldRe, oldIm; //real and imaginary parts of new and old
double xmin = -1.0, xmax = 1.0, ymin = -1.0, ymax = 1.0;
int k; // number of times iterated
//calculate the initial real and imaginary part of z
// z0 = (x + yi)^2 + c = (0 + 0i) + c = c
zx = 1.5*(x - SIZE/2)/(0.5*SIZE);
zy = 1.0*(y - SIZE/2)/(0.5*SIZE);
//start the iteration process
for(k = 1; k < maxI; k++){
//remember value of previous iteration
oldRe = zx;
oldIm = zy;
z = zx*zx - zy*zy + c[0];
//the actual iteration, the real and imaginary part are calculated
zx = oldRe * oldRe - oldIm * c[1] + c[0];
zy = 2 * oldRe * oldIm + c[1];
zy = 2.0*zx*zy + c[1];
zx = z;
//if the point is outside the circle with radius 2: stop
if((zx * zx + zy * zy) > 4) break;
}
/*
while(((zx * zx + zy * zy) > 4) && (k < maxI)) {
//remember value of previous iteration
z = zx*zx - zy*zy + c[0];
zy = 2*x*y-c[1];
zx = z;
//if the point is outside the circle with radius 2: stop
}
return k;
} */ コメントアウト。私は方程式から何が欠けているのか分かりません。どんな推測?
(私は解決策を探していません。実数、虚数の複素数をバウンディングボックスの位置(この場合は-1,1)に変換できる擬似コードです)。ここで
複素数型は、C言語でタイプに内蔵されています – Adam