Last active
December 11, 2016 18:31
-
-
Save 8q/6047af61a95c45588926102126916900 to your computer and use it in GitHub Desktop.
processingでローレンツカオス、ヘノンアトラクタ、ロジスティック写像
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void setup(){ | |
size(700,700); | |
background(255,255,255); | |
drawHenonMap(); | |
} | |
void draw(){ | |
} | |
void drawHenonMap(){ | |
float x = 0.1, y = 0.0; | |
float a = 1.4, b = 0.3; | |
for(int n = 0; n < 100; n++){ | |
float x_ = 1-a*x*x+y; | |
float y_ = b*x; | |
x = x_; | |
y = y_; | |
} | |
for(int n = 0; n < 100000; n++){ | |
float x_ = 1-a*x*x+y; | |
float y_ = b*x; | |
x = x_; | |
y = y_; | |
stroke(0,100,255); | |
rect(map(x, -1.5,1.5, 0, width), map(y, 0.5,-0.5, 0, height), 1,1); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void setup(){ | |
size(700,350); | |
//background(0); | |
logisticMap(2.5, 0.0, 4.0, 1.0); | |
noStroke(); | |
} | |
void draw(){ | |
} | |
void logisticMap(float x, float y, float x2, float y2){ | |
float scaleX = (x2-x)/width; | |
float scaleY = (y2-y)/height; | |
for(int i = 0; i < width; i++){ | |
float a = x + i*scaleX; | |
float b_ = 0.1; | |
float b; | |
for(int n = 0; n < 300; n++){ | |
b = a*b_*(1-b_); | |
b_ = b; | |
} | |
for(int n = 0; n < 300; n++){ | |
b = a*b_*(1-b_); | |
point(i, (b-y)/scaleY); | |
b_ = b; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RungeKutta rgk; | |
int fps = 60; | |
float theta = 90.0f; | |
float phi = 0.0f; | |
float distance = 1000.0f; | |
void setup(){ | |
size(700,700, P3D); | |
background(0); | |
frameRate(fps); | |
rgk = new RungeKutta(10d, 28d, 8d/3d, 1d,0.5d, 0.5d, 1d/ fps); | |
//ortho(); | |
} | |
void draw(){ | |
camera(distance*sin(theta)*sin(phi), distance*cos(theta), 1000*sin(theta)*cos(phi), // 視点X, 視点Y, 視点Z | |
0, 0, 0.0, // 中心点X, 中心点Y, 中心点Z | |
0.0, 1.0, 0.0); // 天地X, 天地Y, 天地Z | |
//degree += 0.05; | |
//if(degree >= 360.0) degree = 0.0; | |
ambientLight(20, 20, 20); //環境光を当てる | |
lightSpecular(255, 255, 255); //光の鏡面反射色(ハイライト)を設定 | |
directionalLight(100, 100, 100, 0, 1, -1); //指向性ライトを設定 | |
drawLorenzKaos(); | |
updateLorenzKaos(); | |
delay(10); | |
} | |
public void drawLorenzKaos(){ | |
pushMatrix(); | |
specular(255, 0,0); | |
noStroke(); | |
translate((float)(rgk.getX()*10), (float)(rgk.getY()*10), (float)(rgk.getZ()*10)); | |
println("x =" + rgk.getX() + " y=" + rgk.getY() + " z=" + rgk.getZ()); | |
box(5,5,5); | |
popMatrix(); | |
} | |
public void updateLorenzKaos(){ | |
rgk.nextstep(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RungeKutta { | |
public double p,r,b,x,y,z,dt; | |
public RungeKutta(double p, double r, double b, double initx, double inity, double initz, double dt){ | |
this.p = p; | |
this.r = r; | |
this.b = b; | |
this.x = initx; | |
this.y = inity; | |
this.z = initz; | |
this.dt = dt; | |
} | |
public void nextstep(){ | |
double j1[] = new double[4]; //x | |
double j2[] = new double[4]; //y | |
double j3[] = new double[4]; //z | |
j1[0] = dt * funcX(x,y,z); | |
j2[0] = dt * funcY(x,y,z); | |
j3[0] = dt * funcZ(x,y,z); | |
j1[1] = dt * funcX(x + j1[0]*0.5,y + j2[0] * 0.5 ,z + j2[0] * 0.5); | |
j2[1] = dt * funcY(x + j1[0]*0.5,y + j2[0] * 0.5 ,z + j2[0] * 0.5); | |
j3[1] = dt * funcZ(x + j1[0]*0.5,y + j2[0] * 0.5 ,z + j2[0] * 0.5); | |
j1[2] = dt * funcX(x + j1[1]*0.5,y + j2[1] * 0.5 ,z + j2[1] * 0.5); | |
j2[2] = dt * funcY(x + j1[1]*0.5,y + j2[1] * 0.5 ,z + j2[1] * 0.5); | |
j3[2] = dt * funcZ(x + j1[1]*0.5,y + j2[1] * 0.5 ,z + j2[1] * 0.5); | |
j1[3] = dt * funcX(x + j1[2], y + j2[2] ,z + j3[2]); | |
j2[0] = dt * funcY(x + j1[2], y + j2[2] ,z + j3[2]); | |
j3[0] = dt * funcZ(x + j1[2], y + j2[2] ,z + j3[2]); | |
x += (j1[0] + 2* j1[1] + 2*j1[2] + j1[3])/6.0; | |
y += (j2[0] + 2* j2[1] + 2*j2[2] + j2[3])/6.0; | |
z += (j3[0] + 2* j3[1] + 2*j3[2] + j3[3])/6.0; | |
} | |
private double funcX(double x, double y, double z){ | |
return -p*x+p*y; | |
} | |
private double funcY(double x, double y, double z){ | |
return -x*z+r*x-y; | |
} | |
private double funcZ(double x, double y, double z){ | |
return x*y-b*z; | |
} | |
public double getX(){ | |
return x; | |
} | |
public double getY(){ | |
return y; | |
} | |
public double getZ(){ | |
return z; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment