BImage[] acc; int compteur,compteur2,incr; float xc, yc, zc; float tempo; DoubleTriedre triedre; void setup() { size(600, 500); xc= width/2.0f; yc=height/2.0f; zc=347; noStroke(); background(150,140,90); triedre= new DoubleTriedre(500.0f); ellipseMode(CENTER_DIAMETER); acc= new BImage[3]; acc[0]=loadImage("bois.jpg"); acc[1]=loadImage("bois.jpg"); acc[2]=loadImage("bois.jpg"); compteur=4;compteur2=8;incr=-1; } void loop() { clear(); translate(xc, yc, zc); rotateY(0.01f * (mouseX - width/2)); rotateZ(0.01f * (mouseY - height/2)); scale(25.0f/compteur); tempo += 0.02; triedre.calculer(tempo,PI/compteur2); triedre.dessinerCycle(0); } void mousePressed(){incremente();println(compteur); } void incremente(){ if(compteur==7||compteur==2) incr*=-1; compteur=compteur+incr; compteur2=2*compteur; } class DoubleTriedre{ Vecteur ab,cd,ac; Vecteur[] v,w; float cote; public DoubleTriedre(float lacote){ v=new Vecteur[8]; w=new Vecteur[8]; cote=lacote; } public void calculer(float t,float alph){ ab=new Vecteur(cos(t),0.0f,sin(t)); float norm=1.0f/sqrt(1.0f+sq(sin(t)*tan(alph))); cd=new Vecteur(norm*sin(t),norm*sin(t)*tan(alph),-norm*cos(t)); ac=ab.cross(cd); Vecteur cc=new Vecteur(ac.y/tan(alph),ac.y,ac.z); Vecteur aa=new Vecteur(cc.x-ac.x,0,0); v[0]=aa; v[1]=aa.ajouter(ab,1); v[2]=ac.ajouter(v[1],1); v[3]=cc; ab=new Vecteur(cos(2*t),0.0f,sin(2*t)); norm=1.0f/sqrt(1.0f+sq(sin(t*2)*tan(alph))); cd=new Vecteur(norm*sin(t*2),norm*sin(t*2)*tan(alph),-norm*cos(t*2)); ac=ab.cross(cd); cc=new Vecteur(ac.y/tan(alph),ac.y,ac.z); aa=new Vecteur(cc.x-ac.x,0,0); v[4]=aa.ajouter(cd,1); v[5]=aa.ajouter(ab,1); v[6]=ac.ajouter(v[5],1); v[7]=cc.ajouter(cd,1); Vecteur norplan=new Vecteur(-sin(alph),cos(alph),0); for(int i=0;i<8;i++){ w[i]=v[i].symetrique(norplan);} } public void dessiner(int niv){ fill(55,255,0); noStroke(); fill(255); if(niv<2){ beginShape(QUADS); texture(acc[niv]); vertex(v[0].x,v[0].y,v[0].z,0,0); vertex(v[1].x,v[1].y,v[1].z, acc[niv].width,0); vertex(v[2].x,v[2].y,v[2].z, acc[niv].width,acc[niv].height); vertex(v[3].x,v[3].y,v[3].z,0, acc[niv].height); endShape(); beginShape(QUADS); texture(acc[niv]); vertex(w[0].x,w[0].y,w[0].z,0,0); vertex(w[1].x,w[1].y,w[1].z, acc[niv].width,0); vertex(w[2].x,w[2].y,w[2].z, acc[niv].width,acc[niv].height); vertex(w[3].x,w[3].y,w[3].z,0, acc[niv].height); endShape(); }else{ beginShape(QUADS); texture(acc[niv]); vertex(v[4].x,v[4].y,v[4].z,0,0); vertex(v[5].x,v[5].y,v[5].z, acc[niv].width,0); vertex(v[6].x,v[6].y,v[6].z, acc[niv].width,acc[niv].height); vertex(v[7].x,v[7].y,v[7].z,0, acc[niv].height); endShape(); beginShape(QUADS); texture(acc[niv]); vertex(w[4].x,w[4].y,w[4].z,0,0); vertex(w[5].x,w[5].y,w[5].z, acc[niv].width,0); vertex(w[6].x,w[6].y,w[6].z, acc[niv].width,acc[niv].height); vertex(w[7].x,w[7].y,w[7].z,0, acc[niv].height); endShape(); } } public void dessinerCycle(int niv){ if(niv<3){ for(int i=0;i