メニュー 閉じる

034. p5.jsでローレンツ方程式の軌跡を空間に描いてみる

ローレンツ方程式に値を代入した結果をプロットしてみました。これも係数を変化させると面白い動きになるのかな?

http://www.velvet-number.com/p5_test/test024/

var x = 0.01;
var y = 0;
var z = 0;

var a = 10;
var b = 28;
var c = 8.0 / 3.0;

var points = [];

var point_num = 5000;

var rad = 0.0;

function setup () {

	pixelDensity (displayDensity ());
	createCanvas (windowWidth, windowHeight, WEBGL);
	colorMode (HSB, 256);
	background (0);

}

function draw () {

	background (0);

	rotateY (rad);

	var dt = 0.01;
	var dx = (a * (y - x)) * dt;
	var dy = (x * (b - z) - y) * dt;
	var dz = (x * y - c * z) * dt;
	x = x + dx;
	y = y + dy;
	z = z + dz;

	points.push (new p5.Vector (x, y, z));

	if (points.length > point_num) {
		points = subset (points, points.length - (point_num - 1), point_num);
	}

	noFill ();

	beginShape ();
	for (var i = 0; i < points.length; i++) {
		stroke (255, 0, 255);
		strokeWeight (1);
		vertex (points[i].x * 10, points[i].y * 10, points[i].z * 10);
	}
	endShape ();

	rad += 0.01;

}
Posted in p5.js , processing