// Représentation de A5 par action des rotations sur un icosaèdre.
// On partitionne les 30 arêtes de l'icosaèdre en 5 sous-ensembles de 6 arêtes, chaque sous-ensemble se voyant attribué une couleur.
// Une rotation laissant globalement invariant l'icosaèdre correspond à une permutation paire des couleurs, et réciproquement.

#include "colors.inc"
#include "textures.inc"
#include "shapes.inc"
#include "stones.inc"
#include "woods.inc"                                                
#include "glass.inc"

// ***************************
// Installation de la caméra *
// ***************************
// On installe la caméra et on définit son orientation.
// L'axe des x est vers la droite, l'axe des y vers le haut, l'axe des z vers le fond.


camera {orthographic
#declare DistanceObservateur = 4;
#declare HauteurObservateur = 1;
#declare Angle = -2;  // pour une vision stéréoscopique :
                     // < 0 pour l'oeil gauche (G.POV) . L'image devra être placée à DROITE en vision croisée
                     // > 0 pour l'oeil droit (D.POV) (en degré), l'image devra être placée à GAUCHE. 
                     // En général 3 à 5 degré d'écart entre les deux yeux. Angle est en degré. 
//Définir l'angle pour choisir l'oeil

location  <DistanceObservateur*cos(Angle/180*pi), HauteurObservateur, DistanceObservateur*sin(Angle/180*3.142)> 
look_at  <0,0,0>
rotate y*20
}

#declare cc=0;       // remplacer cc par clock pour une animation, clock variant de 1 à 120+250+80=450.
// L'animation prévue est :
// 120 images fixes identiques. Utiliser les commandes de copies en ligne de commande, par exemple :
//      for i in {2..9}; do cp G001.png G00$i.png; done
//      for i in {10..99}; do cp G001.png G0$i.png; done
//      for i in {100..120}; do cp G001.png G$i.png; done
// 250 images pour effectuer une rotation de 4*pi/5, d'axe passant par deux sommets diamétralement opposés,
// 80 images fixes sur la position finale.
//      for i in {371..450}; do cp G370.png G$i.png; done

// On définit le fond (par défaut noir)
background { color Black}  

// ********
// Objets *
// ********

#declare phi = 1.618033989;        // nombre d'or

#declare rayonSphere = 0.07;       // rayon des sphères sommets
#declare rayonCyl = 0.03;          // rayon des cylindres arêtes

#declare Couleur1 = Yellow;        // couleurs des cinq trirectangles
#declare Couleur2 = Red; 
#declare Couleur3 = SkyBlue;
#declare Couleur4 = Green;
#declare Couleur5 = Orange;

#if (cc<=120)                      // Définition de l'angle de rotation, en degrés
#declare anglerot5 = 0;            // anglerot5 pour les rotations d'axe passant par deux sommets diamétralement opposés, correspondant aux permutations circulaires (a b c d e)
#declare anglerot3 = 0;            // anglerot3 pour les rotations d'axe passant par les centres de deux faces diamétralement opposées, correspondant aux permutations circulaires (a b c)
#declare anglerot22 = 0;           // anglerot22 pour les rotations d'axe passant par les milieux de deux segment diamétralement opposées, correspondant aux permutations (a b)(c d)
#elseif (cc<=370) 
#declare anglerot5 = 4*180/5*(cc-120)/(370-120);
#declare anglerot3 = 2*180/3*(cc-120)/(370-120);
#declare anglerot22 = 180*(cc-120)/(370-120);
#else
#declare anglerot5 = 4*180/5;
#declare anglerot3 = 2*180/3;
#declare anglerot22 = 180;
#end

// Premier rectangle
#declare A = <1,phi,0>;
#declare B = <-1,phi,0>;
#declare C = <-1,-phi,0>;
#declare D = <1,-phi,0>;

// Deuxième rectangle
#declare E = <0,1,phi>;
#declare F = <0,-1,phi>;
#declare G = <0,-1,-phi>;
#declare H = <0,1,-phi>;

// Troisième rectangle
#declare I = <phi,0,-1>;
#declare J = <phi,0,1>;
#declare K = <-phi,0,1>;
#declare L = <-phi,0,-1>;

union {
    sphere {A, rayonSphere texture {Silver_Metal} pigment {color White}}
    sphere {B, rayonSphere texture {Silver_Metal} pigment {color White}}
    sphere {C, rayonSphere texture {Silver_Metal} pigment {color White}}
    sphere {D, rayonSphere texture {Silver_Metal} pigment {color White}}
    sphere {E, rayonSphere texture {Silver_Metal} pigment {color White}}
    sphere {F, rayonSphere texture {Silver_Metal} pigment {color White}}
    sphere {G, rayonSphere texture {Silver_Metal} pigment {color White}}
    sphere {H, rayonSphere texture {Silver_Metal} pigment {color White}}
    sphere {I, rayonSphere texture {Silver_Metal} pigment {color White}}
    sphere {J, rayonSphere texture {Silver_Metal} pigment {color White}}
    sphere {K, rayonSphere texture {Silver_Metal} pigment {color White}}
    sphere {L, rayonSphere texture {Silver_Metal} pigment {color White}}
    
    //polygon {5, A,B,C,D,A texture {Silver_Metal} pigment {color Couleur1}}
    //polygon {5, E,F,G,H,E texture {Silver_Metal} pigment {color Couleur1}}
    //polygon {5, I,J,K,L,I texture {Silver_Metal} pigment {color Couleur1}}
    cylinder {A,B, rayonCyl texture {Silver_Metal} pigment {color Couleur1}}
    cylinder {C,D, rayonCyl texture {Silver_Metal} pigment {color Couleur1}}
    cylinder {E,F, rayonCyl texture {Silver_Metal} pigment {color Couleur1}}
    cylinder {G,H, rayonCyl texture {Silver_Metal} pigment {color Couleur1}}
    cylinder {I,J, rayonCyl texture {Silver_Metal} pigment {color Couleur1}}
    cylinder {K,L, rayonCyl texture {Silver_Metal} pigment {color Couleur1}}

    //polygon {5, A,E,C,G,A texture {Silver_Metal} pigment {color Couleur2}}
    //polygon {5, D,J,B,L,D texture {Silver_Metal} pigment {color Couleur2}}
    //polygon {5, F,K,H,I,F texture {Silver_Metal} pigment {color Couleur2}}
    cylinder {A,E, rayonCyl texture {Silver_Metal} pigment {color Couleur2}}
    cylinder {C,G, rayonCyl texture {Silver_Metal} pigment {color Couleur2}}
    cylinder {D,J, rayonCyl texture {Silver_Metal} pigment {color Couleur2}}
    cylinder {B,L, rayonCyl texture {Silver_Metal} pigment {color Couleur2}}
    cylinder {F,K, rayonCyl texture {Silver_Metal} pigment {color Couleur2}}
    cylinder {H,I, rayonCyl texture {Silver_Metal} pigment {color Couleur2}}
    
    //polygon {5, A,J,C,L,A texture {Silver_Metal} pigment {color Couleur3}}
    //polygon {5, E,K,G,I,E texture {Silver_Metal} pigment {color Couleur3}}
    //polygon {5, B,H,D,F,B texture {Silver_Metal} pigment {color Couleur3}}
    cylinder {A,J, rayonCyl texture {Silver_Metal} pigment {color Couleur3}}
    cylinder {C,L, rayonCyl texture {Silver_Metal} pigment {color Couleur3}}
    cylinder {E,K, rayonCyl texture {Silver_Metal} pigment {color Couleur3}}
    cylinder {G,I, rayonCyl texture {Silver_Metal} pigment {color Couleur3}}
    cylinder {B,H, rayonCyl texture {Silver_Metal} pigment {color Couleur3}}
    cylinder {D,F, rayonCyl texture {Silver_Metal} pigment {color Couleur3}}
    
    //polygon {5, A,I,C,K,A texture {Silver_Metal} pigment {color Couleur4}}
    //polygon {5, F,J,H,L,F texture {Silver_Metal} pigment {color Couleur4}}
    //polygon {5, B,E,D,G,B texture {Silver_Metal} pigment {color Couleur4}}
    cylinder {A,I, rayonCyl texture {Silver_Metal} pigment {color Couleur4}}
    cylinder {C,K, rayonCyl texture {Silver_Metal} pigment {color Couleur4}}
    cylinder {F,J, rayonCyl texture {Silver_Metal} pigment {color Couleur4}}
    cylinder {H,L, rayonCyl texture {Silver_Metal} pigment {color Couleur4}}
    cylinder {B,E, rayonCyl texture {Silver_Metal} pigment {color Couleur4}}
    cylinder {D,G, rayonCyl texture {Silver_Metal} pigment {color Couleur4}}

    //polygon {5, A,H,C,F,A texture {Silver_Metal} pigment {color Couleur5}}
    //polygon {5, G,L,E,J,G texture {Silver_Metal} pigment {color Couleur5}}
    //polygon {5, B,K,D,I,B texture {Silver_Metal} pigment {color Couleur5}}
    cylinder {A,H, rayonCyl texture {Silver_Metal} pigment {color Couleur5}}
    cylinder {C,F, rayonCyl texture {Silver_Metal} pigment {color Couleur5}}
    cylinder {G,L, rayonCyl texture {Silver_Metal} pigment {color Couleur5}}
    cylinder {E,J, rayonCyl texture {Silver_Metal} pigment {color Couleur5}}
    cylinder {B,K, rayonCyl texture {Silver_Metal} pigment {color Couleur5}}
    cylinder {D,I, rayonCyl texture {Silver_Metal} pigment {color Couleur5}}
    
    // Mettre en commentaire les rotations non désirées
    
    // Rotation d'axe (AC) correspondant à une permutation circulaire (a b c d e) des cinq couleurs.
    //rotate z*degrees(atan(1/phi))
    //rotate y*anglerot5
    //rotate -z*degrees(atan(1/phi))
    
    // Rotation d'axe (1,1,1) correspondant à une permutation circulaire (a b c) des trois couleurs.
    //rotate y*45
    //rotate z*degrees(atan(sqrt(2)))
    //rotate y*anglerot3
    //rotate -z*degrees(atan(sqrt(2)))    
    //rotate -y*45
    
    // Rotation d'axe (0,1,0) correspondant à une permutation (a b)(c d).
    rotate y*anglerot22
    
    
}    

// *********
// Lumière *
// *********

light_source { <10, 0, 0> color White shadowless}
light_source { <-10, 0, 0> color White shadowless}
light_source { <0, 10, 0> color White shadowless}
light_source { <0, -10, 0> color White shadowless}
light_source { <0, 0, 10> color White shadowless}
light_source { <0, 0, -10> color White shadowless}

