//Icosahedron created by Koo-Chul Lee (Sept. 17 2005) float xmag, ymag = 0; float newXmag, newYmag = 0; float faces[][][]= new float [20][3][3]; void setup() { size(300, 300, P3D); noStroke(); colorMode(HSB, 100); float aNum = 0.5*(sqrt(5)+1); float verts[][] = {{0, -aNum, 1}, {aNum, 1, 0}, {aNum, -1, 0}, {1, 0, -aNum}, {-1, 0, -aNum}, {-aNum, 1, 0}, {-aNum, -1, 0}, {-1, 0, aNum}, {1, 0, aNum}, {0, aNum,1}, {0, aNum, -1}, {0, -aNum, -1}}; int vertsIndex[][] = {{0, 11, 2}, {0, 2, 8}, {0, 8, 7}, {0, 7, 6}, {0, 6, 11}, {1, 2, 3}, {1, 8, 2}, {1, 9, 8}, {8, 9, 7}, {7, 9, 5}, {7, 5, 6}, {4, 6, 5}, {4, 11, 6}, {4, 3, 11}, {2, 11, 3}, {10, 1, 3}, {10, 9, 1}, {10, 5, 9}, {10, 4, 5}, {10, 3, 4}}; for (int i = 0; i<20; i ++) for (int j = 0; j <3; 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<20; i++) { fill( (27*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]); } endShape(); popMatrix(); }