# 处理中的创意编程|S2（洛伦茨吸引子）

2021年5月11日14:25:55 发表评论 1,427 次浏览

Java中微分方程的示例实现：

``````int i = 0 ;
double x0, y0, z0, x1, y1, z1;
double h = 0.01 , a = 10.0 , b = 28.0 , c = 8.0 /3.0 ;

x0 = 0.1 ;
y0 = 0 ;
z0 = 0 ;
for (i = 0 ; i <N; i++) {
x1 = x0 + h * a * (y0 - x0);
y1 = y0 + h * (x0 * (b - z0) - y0);
z1 = z0 + h * (x0 * y0 - c * z0);
x0 = x1;
y0 = y1;
z0 = z1;
//Printing the coordinates
if (i> 100 )
System.out.println(i + " " + x0 + " " + y0 + " " + z0);
}``````

• beginShape()–开始记录形状的顶点。
• endShape()–停止记录形状的顶点。
• 顶点()–此功能用于指定点, 线, 三角形, 四边形和多边形的顶点坐标。它仅在beginShape()和endShape()职能。

Lorenz吸引子在Java处理中的实现：-

``````/* FINAL SKETCH FOR LORENZ ATTRACTOR */

import peasy.*; //Importing peasy package

//Initialization
float x = 0.01 , y = 0 , z = 0 ;
float a = 10 , b = 28 , c = 8.0 /3.0 ;

//ArrayList of PVector objects to store
//the position vectors of the points to be plotted.
ArrayList<PVector> points = new ArrayList<PVector>();
PeasyCam cam; //Declaring PeasyCam object

void setup()
{
//Creating the output window
//and setting up the OPENGL renderer
size( 800 , 600 , OPENGL);

//Initializing the cam object
cam = new PeasyCam( this , 500 );
}

void draw()
{
background( 0 );

//Implementation of the differential equations
float dt = 0.01 ;
float dx = (a * (y - x)) * dt;
float dy = (x * (b - z) - y) * dt;
float dz = (x * y - c * z) * dt;
x += dx;
y += dy;
z += dz;

//Adding the position vectors to points ArrayList
translate( 0 , 0 , - 80 );
scale( 5 );
stroke( 255 );
noFill();

//Beginning plotting of points
beginShape();
for (PVector v : points) {
//Adding random color to the structure in each frame
stroke(random( 0 , 255 ), random( 0 , 255 ), random( 0 , 255 ));
vertex(v.x, v.y, v.z); //plotting the vertices
}
endShape(); //Drawing ends
}``````

• Daniel Shiffman编写的编码挑战.
• Paul Bourke制作的3D洛伦兹吸引子.