Created
October 3, 2018 20:01
-
-
Save LadyScream/d5a79f22746c2b918b166dbb70a17c35 to your computer and use it in GitHub Desktop.
Inspired by Daniel Shiffman on The Coding Train
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
boolean recording = false; | |
int frame = 1; | |
float theta = 0; | |
float phi = 0; | |
float time = 0; | |
float r = 50; | |
int cols = 5; | |
int rows = 5; | |
Lissajou[][] curves; | |
void setup() { | |
size(720, 720, P3D); | |
curves = new Lissajou[rows][cols]; | |
for (int j = 0; j < rows; j++) { | |
for (int i = 0; i < cols; i++) { | |
curves[j][i] = new Lissajou(); | |
} | |
} | |
} | |
void draw() { | |
if (time < TWO_PI || !recording) { | |
background(28); | |
translate(width/2, height/2, 0); | |
pushMatrix(); | |
translate(-width/2, -height/2, -300); | |
rotateX(PI/6); | |
for (int j = 1; j < rows; j++) { | |
for (int i = 0; i < cols; i++) { | |
pushMatrix(); | |
translate(width/cols*i, height/rows*j, 0); | |
float x = r * sin(theta*i) * cos(phi*j); | |
float y = r * sin(theta*i) * sin(phi*j); | |
float z = r * cos(theta*i); | |
curves[j][i].addPoint(new PVector(x, y, z)); | |
curves[j][i].show(); | |
popMatrix(); | |
}; | |
}; | |
popMatrix(); | |
if (time > TWO_PI) { | |
curves = new Lissajou[rows][cols]; | |
for (int j = 0; j < rows; j++) { | |
for (int i = 0; i < cols; i++) { | |
curves[j][i] = new Lissajou(); | |
} | |
} | |
time = 0; | |
} | |
theta += 0.125/cols; | |
phi += 0.125/rows; | |
time += 0.01; | |
if (recording) save(frame+".gif"); | |
frame++; | |
} | |
} | |
class Lissajou { | |
ArrayList<PVector> points; | |
Lissajou() { | |
points = new ArrayList<PVector>(); | |
} | |
void addPoint(PVector p) { | |
points.add(p); | |
} | |
void show() { | |
pushMatrix(); | |
float Z = sin(time)*PI; | |
rotateZ(Z); | |
noFill(); | |
stroke(200); | |
strokeWeight(3); | |
beginShape(); | |
for (PVector p : points) { | |
vertex(p.x, p.y, p.z); | |
} | |
endShape(); | |
popMatrix(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
amazing!