Skip to content

Instantly share code, notes, and snippets.

@reuk
Created September 3, 2013 06:46
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reuk/6420421 to your computer and use it in GitHub Desktop.
Save reuk/6420421 to your computer and use it in GitHub Desktop.
void drawFolder(int sides, float rad) {
float ang = (frameCount * 2 * PI * 0.05) / sides;
PVector maxy = new PVector(0, 0);
PVector[] v = new PVector[sides];
for (int i = 0; i != v.length; ++i) {
float angle = ((2 * PI * i) / sides) + ang;
float x = sin(angle) * rad;
float y = cos(angle) * rad;
v[i] = new PVector(x, y);
maxy = y > maxy.y ? v[i] : maxy;
}
pushMatrix();
translate(0, -maxy.y);
beginShape();
for (int i = 0; i <= sides; ++i)
vertex(v[i % sides].x, v[i % sides].y, rad);
endShape(CLOSE);
beginShape();
for (int i = 0; i <= sides; ++i)
vertex(v[i % sides].x, v[i % sides].y, -rad);
endShape(CLOSE);
for(int i = 0; i != v.length; ++i)
line(v[i].x, v[i].y, rad, v[i].x, v[i].y, -rad);
int segs = 100;
float extra = 2 * sin(PI / (sides)) * rad;
for (int i = 1; i != segs; ++i) {
line(maxy.x + extra * i, maxy.y, rad, maxy.x + extra * i, maxy.y, -rad);
}
line(maxy.x, maxy.y, rad, maxy.x + segs * extra, maxy.y, rad);
line(maxy.x, maxy.y, -rad, maxy.x + segs * extra, maxy.y, -rad);
popMatrix();
}
void setup() {
size(500, 500, P3D);
frameRate(25);
}
void draw() {
background(0);
noFill();
stroke(0, 255, 255, 255);
strokeWeight(2);
translate(width / 2, height * 0.7);
rotateX(-PI / 4);
rotateY(PI / 6);
float rad = 30;
translate(0, 0, 3 * rad);
for (int i = 2; i != 20; ++i) {
drawFolder(i, rad);
translate(0, 0, -3 * rad );
}
saveFrame("###-blah.png");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment