topical media & game development
graphic-processing-learning-14-example-14-10-example-14-10.pde / pde
// Learning Processing
// Daniel Shiffman
// http://www.learningprocessing.com
// Example 14-10: Pyramid
float theta = 0.0;
void setup() {
size(200,200,P3D);
}
void draw() {
background(255);
theta += 0.01;
translate(100,100,0);
rotateX(theta);
rotateY(theta);
drawPyramid(50);
// translate the scene again
translate(50,50,20);
// call the pyramid drawing function
drawPyramid(10);
}
void drawPyramid(int t) {
stroke(0);
// this pyramid has 4 sides, each drawn as a separate triangle
// each side has 3 vertices, making up a triangle shape
// the parameter " t " determines the size of the pyramid
beginShape(TRIANGLES);
fill(150,0,0,127);
vertex(-t,-t,-t);
vertex( t,-t,-t);
vertex( 0, 0, t);
fill(0,150,0,127);
vertex( t,-t,-t);
vertex( t, t,-t);
vertex( 0, 0, t);
fill(0,0,150,127);
vertex( t, t,-t);
vertex(-t, t,-t);
vertex( 0, 0, t);
fill(150,0,150,127);
vertex(-t, t,-t);
vertex(-t,-t,-t);
vertex( 0, 0, t);
endShape();
}
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.