Skip to content

Instantly share code, notes, and snippets.

@volfegan
Last active January 13, 2020 04:42
Show Gist options
  • Save volfegan/3b0f2d7009f9a6b098e3b7e26d5337c3 to your computer and use it in GitHub Desktop.
Save volfegan/3b0f2d7009f9a6b098e3b7e26d5337c3 to your computer and use it in GitHub Desktop.
//https://twitter.com/ntsutae/status/1216186934172585984
float C=0, W=640, d, i;
boolean saveFrames = true;
//https://processing.org/examples/toroid.html
int segments = 32;
int pts = 32;
float angle = 0;
float radius = W/6;
float latheAngle = 0;
float latheRadius = W/6;
PVector vertices[], vertices2[];
void setup() {
size(640, 640, P3D);
noStroke();
}
void draw() {
clear();
background(0);
translate(width/2, height/2);
C+=2;
for (i=W*2/3; i>0; i--) {
d=noise(i-C)*TAU*2;
fill(map(sin(d), -1, 1, 255, 0), 120);
push();
translate(cos(d)*i, sin(d)*i, 0);
//sphereDetail(16);
//sphere(W/6);
//box(W/6);
toroid();
pop();
}
if (saveFrames) {
// Saves each frame as frame_000001.png, frame_000002.png, etc.
saveFrame("frame_######.png");
}
}
//https://processing.org/examples/toroid.html
void toroid() {
// draw toroid
// initialize point arrays
vertices = new PVector[pts+1];
vertices2 = new PVector[pts+1];
// fill arrays
for (int i=0; i<=pts; i++) {
vertices[i] = new PVector();
vertices2[i] = new PVector();
vertices[i].x = latheRadius + sin(radians(angle))*radius;
vertices[i].z = cos(radians(angle))*radius;
angle+=360.0/pts;
}
latheAngle = 0;
for (int i=0; i<=segments; i++) {
beginShape(QUAD_STRIP);
for (int j=0; j<=pts; j++) {
if (i>0) {
vertex(vertices2[j].x, vertices2[j].y, vertices2[j].z);
}
vertices2[j].x = cos(radians(latheAngle))*vertices[j].x;
vertices2[j].y = sin(radians(latheAngle))*vertices[j].x;
vertices2[j].z = vertices[j].z;
vertex(vertices2[j].x, vertices2[j].y, vertices2[j].z);
}
latheAngle+=360.0/segments;
endShape();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment