Skip to content

Instantly share code, notes, and snippets.

@jrc03c
Created May 6, 2016 02:04
Show Gist options
  • Select an option

  • Save jrc03c/9057153b5f06cbdcdab8cf08087d3456 to your computer and use it in GitHub Desktop.

Select an option

Save jrc03c/9057153b5f06cbdcdab8cf08087d3456 to your computer and use it in GitHub Desktop.
A JavaScript Lorenz Attractor (based on https://www.youtube.com/watch?v=gw_TR1tycWQ)
var x, y, z, a, b, c, dt;
var points;
function setup(){
createCanvas(600, 600, WEBGL);
points = [];
x = 0.01;
y = 0;
z = 0;
a = 10;
b = 28;
c = 8/3;
dt = 0.015;
}
function draw(){
var dx = (a * (y - x)) * dt;
var dy = (x * (b - z) - y) * dt;
var dz = (x * y - c * z) * dt;
x += dx;
y += dy;
z += dz;
if (points.length > 500) points.splice(0, 1);
points.push(createVector(x, y, z));
rotateY(frameCount * 0.01);
camera(0, 0, 500);
scale(15);
ambientLight(255);
points.forEach(function(p){
push();
translate(p.x, p.y, p.z);
sphere(0.1);
pop();
})
}
function mousePressed(){
setup();
}
@BLayman
Copy link

BLayman commented May 17, 2016

I tried copy and pasting this into a sketch.js to see it in action, but it didn't seem to work. Do I need to take some extra steps?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment