超ピュアで美しい曲線(PeterのJong Attractor)
何気なくネットでHTML 5 Demoに基づくPeterのJong吸引子によって画像を生成するデモを見ました。Holdは住んでいません。
とても綺麗です。そこで研究したいのですが、専門用語のフラクタルがあります。一人の大家はこのようにフラクタル学科を評価します。
math,it is about art」 明らかに時にはプログラマーも芸術細胞があります。
効果図1
効果図2
効果図3:
発生の原理
PeterによるJong公式:PeterのJongの数学公式は以下の通りである。
Xn+1=sin(a*yn)-cos(b*xn)
Yn+1=sin(c*xn)-cos(d*yn)
ランダムなポイントP(x 0,y 0)から次のP(xn,yn)を得て、Xn=Xn+1,Yn=Yn+1とする。
反復により多くのデータが生成されます。
アルゴリズム
アルゴリズムはフラクタルファイヤーアルゴリズムに基づいて、まず反復されたデータポイントに基づいて、ヒストグラムの統計アルゴリズムを用いて指定されたサイズのヒストグラムデータ点を得て、
ヒストグラムの結果に基づいて、ピクセルの描画と色、透明度の生産を実現します。フラクタルファイアアルゴリズムについては、ここを参照することができる。
http://en.wikipedia.org/wiki/Fractal_flame
ランダムポイントの生成とヒストグラムの統計コードを完了しました。
とても綺麗です。そこで研究したいのですが、専門用語のフラクタルがあります。一人の大家はこのようにフラクタル学科を評価します。
math,it is about art」 明らかに時にはプログラマーも芸術細胞があります。
効果図1
効果図2
効果図3:
発生の原理
PeterによるJong公式:PeterのJongの数学公式は以下の通りである。
Xn+1=sin(a*yn)-cos(b*xn)
Yn+1=sin(c*xn)-cos(d*yn)
ランダムなポイントP(x 0,y 0)から次のP(xn,yn)を得て、Xn=Xn+1,Yn=Yn+1とする。
反復により多くのデータが生成されます。
アルゴリズム
アルゴリズムはフラクタルファイヤーアルゴリズムに基づいて、まず反復されたデータポイントに基づいて、ヒストグラムの統計アルゴリズムを用いて指定されたサイズのヒストグラムデータ点を得て、
ヒストグラムの結果に基づいて、ピクセルの描画と色、透明度の生産を実現します。フラクタルファイアアルゴリズムについては、ここを参照することができる。
http://en.wikipedia.org/wiki/Fractal_flame
ランダムポイントの生成とヒストグラムの統計コードを完了しました。
private void getPoint() { la = a; lb = b; lc = c; ld = d; // Add Noise to Coefficients for Smoothness if (noise) { la += getRandom(); lb += getRandom(); lc += getRandom(); ld += getRandom(); } // ************************************************* // ** Update Temp Variables -- Magic xn = (float)(Math.sin(la * y) - Math.cos(lb * x)); yn = (float)(Math.sin(lc * x) - Math.cos(ld * y)); // color here zn = (float)(Math.sin(e * x) - Math.cos(f * z)); // take current result as x0,y0,z0 in order to calculate next xn,yn,zn x = xn; y = yn; z = zn; // Convert to 2D Image Space for Plotting u = (int) ((x + 2.5) * K); v = (int) ((y + 2.5) * K); tr = (float)(z * 0.9 + (1.0 - z) * 0.6); // Map Z-Coordinate to Color tg = (float)(z * 0.2 + (1.0 - z) * 0.4); tb = (float)(z * 0.5 + (1.0 - z) * 0.9); pList[u][v][0] += 1.0f; // alpha value, normalization factor, must have it pList[u][v][1] += tr; //Add New Point to Total pList[u][v][2] += tg; pList[u][v][3] += tb; }
結果の正規化とピクセルの描画コード: private void renderPoints(int[] rgbData) { float max = -1.0f; for (int i=0; i < nSize; i++) { for (int j=0; j < nSize; j++) { if (pList[i][j][3] > max){ max = pList[i][j][3]; } } } //Adjust Values and Fill Image float logval, logmax = (float)Math.log(max); float M = (float)((logmax * logmax) / 255.0f); int[] color ={0,0,0,0}; for (int i=0; i < nSize; i++) { for (int j=0; j < nSize; j++) { for (int k=0; k < 4; k++) { logval = (float)Math.log(pList[i][j][k]); color[k] = (int) (logval * logval / M); } // rgbData[j*nSize + i] = (color[0] << 24) | (color[1] << 16) | (color[2] << 8) | color[3]; rgbData[j*nSize + i] = (255 << 24) | (color[1] << 16) | (color[2] << 8) | color[3]; } } }