27
28

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

processingで綺麗な方程式を可視化する

Last updated at Posted at 2015-11-25

cli.jpg

世の中には様々な数式が存在していてその中一つにClifford Attractorというものがあります
xn+1 = sin(a yn) + c cos(a xn)
yn+1 = sin(b xn) + d cos(b yn)
と非常にシンプルですが計算を繰り返す事でとても綺麗な数式です

ネットとかでsourcecodeがあるのか調べてみましたがなっかったので(もしあったらすいません...)
式を解析して書きました 独学なのでこの解析が正解どうかはわかりませんが

clifford_attractor.pde
int count=40000;

float x=1;
float y=1;
float z=1;

float a=1.4;
float b=1.6;
float c=1;
float d=1.7;

float xn;
float yn;
float zn;

float rotate_x;
float rotate_y;




float [][] points=new float[3][count];

void setup(){
size(750,400,P3D);

//xn+1= sin(a*yn)-c*cos(a*xn)
//yn+1= sin(b*xn)-d*cos(d*yn)
//zn+1= sin(xn)

for(int i=0;i<count;i++){
 
xn= sin(a*y)-c*cos(a*x);
yn= sin(b*x)-d*cos(d*y);
zn= sin(x);

x=xn;
y=yn;
z=zn;

points[0][i]=x*100;
points[1][i]=y*50;
points[2][i]=z*100;

}

}

void draw(){
background(#000000);
 fill(#FFFFFF);
translate(width/2,height/2);

rotateX(rotate_x);
rotateY(rotate_y);

for(int i=0;i<count;i++){
 pushMatrix();

  beginShape(POINTS);
  vertex(points[0][i],points[1][i],points[2][i]);
  endShape();

stroke(#FFFFFF);
popMatrix();
 
}

 rotate_x+=0.03;
 rotate_y+=0.03;

}

ちなみにZ座標の式zn= sin(x)は奥行きを出したかったので僕が適当に書いたものです
100行のないのでコピペして使って下さい
PVectorクラスやシェーダーなど使ってアニメーションさせたら面白いかもですね~。
参考サイト
http://paulbourke.net/fractals/clifford/

27
28
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
27
28

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?