Created
August 1, 2019 20:54
-
-
Save samclane/7fbd13fbb8a6aebaf7d957fa40b12e3d to your computer and use it in GitHub Desktop.
Source for the "unraveled" Lorenz Attractor. https://youtu.be/GKNx47T7uFc
This file contains 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
import peasy.*; | |
float x = 0.01; | |
float y = 0; | |
float z = 0; | |
float a = 10; | |
float b = 28; | |
float c = 8./3.; | |
ArrayList<PVector> points = new ArrayList<PVector>(); | |
PeasyCam cam; | |
void setup() { | |
size(1920, 1080, P3D); | |
colorMode(HSB); | |
cam = new PeasyCam(this, 700); | |
cam.rotateX(1.78); | |
cam.rotateY(-0.36); | |
cam.rotateZ(1.6); | |
} | |
void draw() { | |
background(0); | |
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 = x + dx; | |
y = y + dy; | |
z = z + dz; | |
points.add(new PVector(x,y,z)); | |
scale(8); | |
stroke(255); | |
noFill(); | |
float hue = 0; | |
beginShape(); | |
{ | |
for (PVector v: points) { | |
stroke(hue, 255, 255); | |
vertex(v.x, v.y, v.z); | |
float offset = .5*noise(v.x, v.y, v.z); | |
v.add(offset, offset, offset); | |
hue += dt * 10; | |
hue %= 255; | |
} | |
} | |
endShape(); | |
cam.beginHUD(); | |
{ | |
textAlign(LEFT); | |
text("Camera:", 0, 12); | |
text("X: " + cam.getPosition()[0], 0, 24); | |
text("Y: " + cam.getPosition()[1], 0, 36); | |
text("Z: " + cam.getPosition()[2], 0, 48); | |
text("D: " + cam.getDistance(), 0, 60); | |
text("rX: " + cam.getRotations()[0], 0, 72); | |
text("rY: " + cam.getRotations()[1], 0, 84); | |
text("rZ: " + cam.getRotations()[2], 0, 96); | |
} | |
cam.endHUD(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment