xxxxxxxxxx
/*
Title: Lorenz SuperForm
Author: Elijah Ko
Contact: elijah.ko@network.rca.ac.uk
Date: 2020-04-11
Description:
Lorenz Attractor (aka Butterfly Effect), a differential mathematical model for atmospheric convection. What if ... we can use it to manifest climate change?
Reference:
http://paulbourke.net/fractals/lorenz/
https://www.youtube.com/watch?v=vD9lRmfwIxI
*/
let x = 10;
let y = 0.1;
let z = 1;
// These are constants
let sigma = 10; //sigma
let rho = 28;
let beta = 8.0 / 3.0;
// flexible size array
let points = new Array();
// Processing: ArrayList<PVector> points = new ArrayList<PVector>();
let angle = 0;
function setup() {
createCanvas(750, 750, WEBGL);
colorMode(HSB);
background(0);
}
function draw() {
/* Lorenz Accelerator */
let dt = 0.01; //change of time scale
let dx = (sigma * (y - x)) * dt; //x incremental change
x += dx;
let dy = (x * (rho - z) - y) * dt; //y incremental change
y += dy;
let dz = (x * y - beta * z) * dt; //z incremental change
z += dz;
points.push(new p5.Vector(x, y, z));
// Processing: points.add(new PVector(x, y, z));
// translate(width/2, height/2);
// translate(0, 0, -80);
// let camX = map(mouseX, 0, width, -700, 700);
// let camY = map(mouseY, 0, height, -700, 700);
// camera(camX, camY, height / 2.0 / tan((PI * 30.0) / 180.0), 0, 0, 0, 0, 1, 0);
rotate(angle);
scale(6);
stroke(255);
noFill();
let hu = 0;
beginShape();
for (let v of points) {
point(v.x, v.y, v.z);
stroke(hu, 255, 255);
strokeWeight(1);
// vertex(v.x, v.y, v.z); //doesn't work for p5.js
hu += 1;
if (hu > 255) {
hu = 0;
}
}
endShape(CLOSE);
//console.log(x, y, z);
print(x, y, z);
angle += 0.0015;
}