//Dodecahedron created by Koo-Chul Lee (Sept. 17 2005) float xmag, ymag = 0; float newXmag, newYmag = 0; float faces[][][]= new float [12][5][3]; void setup() { size(300, 300, P3D); noStroke(); colorMode(HSB, 100); float lam = 0.5*(sqrt(5) + 1); float rho = 1/lam; float verts[][] = {{lam, -rho, 0}, {1, -1, -1}, {rho, 0, -lam},{1, 1, -1},{lam, rho, 0},{-rho, 0, -lam},{-1, -1, -1}, {-lam, -rho, 0},{-lam, rho, 0},{-1, 1, -1}, {-1, -1, 1},{-rho, 0, lam},{-1, 1, 1},{rho, 0, lam}, {1, -1, 1}, {1, 1, 1}, {0, lam, rho},{0, lam, -rho},{0, -lam, rho},{0, -lam, -rho}}; int vertsIndex[][] = {{0, 1, 2, 3, 4},{5, 6, 7, 8, 9},{7, 10, 11, 12, 8},{0, 4, 15, 13, 14},{0, 14, 18, 19, 1},{6, 19, 18, 10, 7}, {8, 12, 16, 17, 9},{3, 17, 16, 15, 4},{1, 19, 6, 5, 2},{2, 5, 9, 17, 3},{11, 13, 15, 16, 12},{10, 18, 14, 13, 11}}; for (int i = 0; i<12; i ++) for (int j = 0; j <5; j++) for (int k =0; k<3; k++) faces[i][j][k] = verts[vertsIndex[i][j]][k]; } void draw() { background(0,0,0); pushMatrix(); translate(width/2, height/2, -30); newXmag = mouseX/float(width) * TWO_PI; newYmag = mouseY/float(height) * TWO_PI; float diff = xmag-newXmag; if (abs(diff) > 0.01) { xmag -= diff/4.0; } diff = ymag-newYmag; if (abs(diff) > 0.01) { ymag -= diff/4.0; } rotateX(-ymag); rotateY(-xmag); scale(50); beginShape(TRIANGLES); for (int i = 0; i<12; i++) { fill( (19*i)%100, 90,100); vertex(faces[i][0][0],faces[i][0][1], faces[i][0][2]); vertex(faces[i][1][0],faces[i][1][1], faces[i][1][2]); vertex(faces[i][2][0],faces[i][2][1], faces[i][2][2]); vertex(faces[i][0][0],faces[i][0][1], faces[i][0][2]); vertex(faces[i][2][0],faces[i][2][1], faces[i][2][2]); vertex(faces[i][3][0],faces[i][3][1], faces[i][3][2]); vertex(faces[i][0][0],faces[i][0][1], faces[i][0][2]); vertex(faces[i][3][0],faces[i][3][1], faces[i][3][2]); vertex(faces[i][4][0],faces[i][4][1], faces[i][4][2]); } endShape(); popMatrix(); }