Created
May 6, 2016 02:04
-
-
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)
This file contains hidden or 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
| 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(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?