Created
March 10, 2013 20:57
-
-
Save jordanorelli/5130377 to your computer and use it in GitHub Desktop.
3d animated gif with processing
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
import gifAnimation.*; | |
GifMaker gifExport; | |
int frames = 0; | |
int totalFrames = 180; | |
void setup() { | |
smooth(); | |
size(900, 300, P3D); | |
ortho(); | |
gifExport = new GifMaker(this, "export.gif", 100); | |
gifExport.setRepeat(0); // make it an "endless" animation | |
fill(255); | |
} | |
void draw() { | |
float r = float(frames) * TWO_PI / 180.0; | |
background(255); | |
directionalLight(51, 102, 126, -1, 0.3, -0.58); | |
ambientLight(128, 128, 128); | |
drawCube(r); | |
drawSphere(r); | |
drawPyramid(r); | |
frames++; | |
exportFrame(); | |
} | |
void drawCube(float r) { | |
// stroke(0); | |
strokeWeight(1); | |
noStroke(); | |
pushMatrix(); | |
translate(width / 4.0, height * 0.5); | |
rotateX(r); | |
rotateY(r); | |
box(100); | |
popMatrix(); | |
} | |
void drawSphere(float r) { | |
// strokeWeight(0.3); | |
noStroke(); | |
pushMatrix(); | |
translate(width / 2.0, height * 0.5); | |
rotateX(r); | |
rotateY(r); | |
sphere(50); | |
popMatrix(); | |
} | |
void drawPyramid(float r) { | |
pushMatrix(); | |
translate(width * 0.75, height * 0.5); | |
noStroke(); | |
rotateX(r); | |
rotateY(r); | |
scale(50); | |
// top face | |
beginShape(); | |
vertex(-1, -1, -1); | |
vertex(1, -1, -1); | |
vertex(0, 0, 1); | |
endShape(CLOSE); | |
// right face | |
beginShape(); | |
vertex(0, 0, 1); | |
vertex(1, 1, -1); | |
vertex(1, -1, -1); | |
endShape(CLOSE); | |
// bottom face | |
beginShape(); | |
vertex(0, 0, 1); | |
vertex(1, 1, -1); | |
vertex(-1, 1, -1); | |
endShape(CLOSE); | |
// left face | |
beginShape(); | |
vertex(0, 0, 1); | |
vertex(-1, 1, -1); | |
vertex(-1, -1, -1); | |
endShape(CLOSE); | |
// base | |
beginShape(); | |
vertex(-1, -1, -1); | |
vertex(1, -1, -1); | |
vertex(1, 1, -1); | |
vertex(-1, 1, -1); | |
endShape(CLOSE); | |
popMatrix(); | |
} | |
void exportFrame() { | |
if(frames < totalFrames) { | |
gifExport.setDelay(40); | |
gifExport.addFrame(); | |
frames++; | |
} else { | |
gifExport.finish(); | |
frames++; | |
println("gif saved"); | |
exit(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
running the above program will generate the following animated gif: