TeXgraph# {version 1.95} Cmd [Fenetre(-7+5.5*i,5.5-7*i,0.72+0.72*i), Marges(0,0,0,0), Border(0)]; [OriginalCoord(1),IdMatrix()]; [theta:=0.5236, phi:=1.0472, IdMatrix3D(), ModelView(central), DistCam(15)]; [GrayScale(0), ComptGraph:=5]; Var L = 6; Mac rotZ = [ {rotZ( tranche(1/2/3), sens(+/-1) )} $mat:=matrix3d( rot3d(M,[Origin,vecK],%2*pi/2)), stock:= if %1=1 then {tranche du bas} for $Z in stock by jump do $G:=isobar3d(Z), if Re(G[2])<-L/6 then Mtransform3D(Z, mat) else Z fi od elif %1=2 then {tranche du milieu} for $Z in stock by jump do $G:=isobar3d(Z), if abs(Re(G[2]))<1 then Mtransform3D(Z, mat) else Z fi od elif %1=3 then {tranche du haut} for $Z in stock by jump do $G:=isobar3d(Z), if Re(G[2])>L/6 then Mtransform3D(Z, mat) else Z fi od fi, $dessine:= if %3=Nil then 1 else %3 fi, if dessine then Insert(stock4, 2+%2*i*%1), ReCalc(dessin) fi ]; rotX = [ {rotX( tranche, sens [, dessiner])} $mat:=matrix3d( rot3d(M,[Origin,vecI],%2*pi/2)), stock:= if %1=1 then {tranche du bas} for $Z in stock by jump do $G:=isobar3d(Z), if Re(G[1])<-L/6 then Mtransform3D(Z, mat) else Z fi od elif %1=2 then {tranche du milieu} for $Z in stock by jump do $G:=isobar3d(Z), if abs(Re(G[1]))<1 then Mtransform3D(Z, mat) else Z fi od elif %1=3 then {tranche du haut} for $Z in stock by jump do $G:=isobar3d(Z), if Re(G[1])>L/6 then Mtransform3D(Z, mat) else Z fi od fi, $dessine:= if %3=Nil then 1 else %3 fi, if dessine then Insert(stock4, %2*i*%1), ReCalc(dessin) fi ]; rotY = [ {rotY( tranche, sens [, dessiner])} $mat:=matrix3d( rot3d(M,[Origin,vecJ],%2*pi/2)), stock:= if %1=1 then {tranche du bas} for $Z in stock by jump do $G:=isobar3d(Z), if Im(G[1])<-L/6 then Mtransform3D(Z, mat) else Z fi od elif %1=2 then {tranche du milieu} for $Z in stock by jump do $G:=isobar3d(Z), if abs(Im(G[1]))<1 then Mtransform3D(Z, mat) else Z fi od elif %1=3 then {tranche du haut} for $Z in stock by jump do $G:=isobar3d(Z), if Im(G[1])>L/6 then Mtransform3D(Z, mat) else Z fi od fi, $dessine:= if %3=Nil then 1 else %3 fi, if dessine then Insert(stock4, 1+%2*i*%1), ReCalc(dessin) fi ]; facette = [$A:=%1, $v1:=L*%2/3, $v2:=L*%3/3, A,A+v1,A+v1+v2,A+v2]; Init = [ $x:=RefPoint, Bouton(x, "Mélanger","melanger()","Permet de définir un cube initial"), Inc(x,DeltaB), NewText(x,"Tranche(1/2/3) Sens(+/-1)"),Inc(x,DeltaB/2), NewButton(NbBoutons,"Ox/1/+1",x,Re(tailleB/2)+Im(tailleB)*i,"rotX(1,1)", ""),Inc(NbBoutons,1), NewButton(NbBoutons,"Ox/1/-1",x+Re(tailleB/2),Re(tailleB/2)+Im(tailleB)*i,"rotX(1,-1)", ""), Inc(NbBoutons,1),Inc(x,DeltaB), NewButton(NbBoutons,"Ox/2/+1",x,Re(tailleB/2)+Im(tailleB)*i,"rotX(2,1)", ""),Inc(NbBoutons,1), NewButton(NbBoutons,"Ox/2/-1",x+Re(tailleB/2),Re(tailleB/2)+Im(tailleB)*i,"rotX(2,-1)", ""), Inc(NbBoutons,1),Inc(x,DeltaB), NewButton(NbBoutons,"Ox/3/+1",x,Re(tailleB/2)+Im(tailleB)*i,"rotX(3,1)", ""),Inc(NbBoutons,1), NewButton(NbBoutons,"Ox/3/-1",x+Re(tailleB/2),Re(tailleB/2)+Im(tailleB)*i,"rotX(3,-1)", ""), Inc(NbBoutons,1),Inc(x,1.5*DeltaB), NewButton(NbBoutons,"Oy/1/+1",x,Re(tailleB/2)+Im(tailleB)*i,"rotY(1,1)", ""),Inc(NbBoutons,1), NewButton(NbBoutons,"Oy/1/-1",x+Re(tailleB/2),Re(tailleB/2)+Im(tailleB)*i,"rotY(1,-1)", ""), Inc(NbBoutons,1),Inc(x,DeltaB), NewButton(NbBoutons,"Oy/2/+1",x,Re(tailleB/2)+Im(tailleB)*i,"rotY(2,1)", ""),Inc(NbBoutons,1), NewButton(NbBoutons,"Oy/2/-1",x+Re(tailleB/2),Re(tailleB/2)+Im(tailleB)*i,"rotY(2,-1)", ""), Inc(NbBoutons,1),Inc(x,DeltaB), NewButton(NbBoutons,"Oy/3/+1",x,Re(tailleB/2)+Im(tailleB)*i,"rotY(3,1)", ""),Inc(NbBoutons,1), NewButton(NbBoutons,"Oy/3/-1",x+Re(tailleB/2),Re(tailleB/2)+Im(tailleB)*i,"rotY(3,-1)", ""), Inc(NbBoutons,1),Inc(x,1.5*DeltaB), NewButton(NbBoutons,"Oz/1/+1",x,Re(tailleB/2)+Im(tailleB)*i,"rotZ(1,1)", ""),Inc(NbBoutons,1), NewButton(NbBoutons,"Oz/1/-1",x+Re(tailleB/2),Re(tailleB/2)+Im(tailleB)*i,"rotZ(1,-1)", ""), Inc(NbBoutons,1),Inc(x,DeltaB), NewButton(NbBoutons,"Oz/2/+1",x,Re(tailleB/2)+Im(tailleB)*i,"rotZ(2,1)", ""),Inc(NbBoutons,1), NewButton(NbBoutons,"Oz/2/-1",x+Re(tailleB/2),Re(tailleB/2)+Im(tailleB)*i,"rotZ(2,-1)", ""), Inc(NbBoutons,1),Inc(x,DeltaB), NewButton(NbBoutons,"Oz/3/+1",x,Re(tailleB/2)+Im(tailleB)*i,"rotZ(3,1)", ""),Inc(NbBoutons,1), NewButton(NbBoutons,"Oz/3/-1",x+Re(tailleB/2),Re(tailleB/2)+Im(tailleB)*i,"rotZ(3,-1)", ""), Inc(NbBoutons,1),Inc(x,1.5*DeltaB), Bouton(x, "Défaire","[defaire()]","Annuler le dernier coup"), Inc(x,DeltaB), Bouton(x, "Cube initial","[stock:=stock3, stock4:=Nil, ReCalc(dessin)]", "Revenir au cube initial"), Inc(x,DeltaB), stock1:=Nil, stock2:=Nil, stock3:=Nil, stock4:=Nil, PosInitiale() ]; PosInitiale = [ d:=L/3, O:=M(-L,-L,-L)/2, F1:=for j from 0 to 2 do for k from 0 to 2 do facette(O+M(0,j*d,k*d),vecK,vecJ),ColorJump(blue), od od, F2:=for j from 0 to 2 do for k from 0 to 2 do facette(O+M(L,j*d,k*d),vecJ,vecK),ColorJump(green), od od, F3:=for j from 0 to 2 do for k from 0 to 2 do facette(O+M(j*d,0,k*d),vecI,vecK),ColorJump(red), od od, F4:=for j from 0 to 2 do for k from 0 to 2 do facette(O+M(j*d,L,k*d),vecK,vecI),ColorJump(orange), od od, F5:=for j from 0 to 2 do for k from 0 to 2 do facette(O+M(j*d,k*d,0),vecJ,vecI),ColorJump(whitesmoke), od od, F6:=for j from 0 to 2 do for k from 0 to 2 do facette(O+M(k*d,j*d,L),vecI,vecJ),ColorJump(yellow), od od, stock:=[F1,F2,F3,F4,F5,F6], ReCalc(dessin) ]; melanger = [ PosInitiale(), $N:=1+Rand(100), {une transformation est un complexe: axe+/-i*tranche où axe=0/1/2 et tranche=1/2/3} stock1:=for k from 1 to N do Rand(3)+i*(2*Rand(2)-1)*(1+Rand(3)) od, stock2:=for $z in Reverse(stock1) do bar(z) od, {solutions} transformer(stock1), stock3:=stock, {sauvegarde du cube initial} stock4:=Nil, {pour stocker les opéraions utilisateurs} ReCalc(dessin) ]; transformer = [ {une transformation est symbolisée par un complexe: axe+/-i*tranche} for $z in %1 do $sens:=2*(Im(z)>0)-1, $tranche:=abs(Im(z)), $axe:=Re(z), if axe=0 then rotX(tranche,sens,0) elif axe=1 then rotY(tranche,sens,0) else rotZ(tranche,sens,0) fi od ]; defaire = if stock4<>Nil then $z:=stock4[-1], Del(stock4,-1,1), transformer(bar(z)), ReCalc(dessin) fi; Cmd [tMin:=-3,tMax:=3,DotScale:=1+i]; Graph fond = [ view(-7,5.5,-7,5.5), view3D(-5,5,-5,5,-5,5),Marges(0,0,0,0),size(9), background(full,dimgray) ]; Cmd [tMin:=-6,tMax:=6]; Graph dessin = [ stock:=SortFacet(stock), FillStyle:=full, Ligne3D(stock,1) ]; Cmd [tMin:=-7,tMax:=5.5]; Graph repere = [ LabelSize:=tiny, DotScale:=0.5, A:=ScreenPos(-5-5*i,0), Arrows:=1, Ligne3D([A,A+1.25*vecI,jump,A, A+1.25*vecJ,jump,A, A+1.25*vecK],0), Label(Proj3D(A+1.5*vecI),"x", Proj3D(A+1.5*vecJ),"y", Proj3D(A+1.5*vecK),"z"), LabelDot3D(A+vecI/3,"1","S",1,0.125),LabelDot3D(A+2*vecI/3,"2","S",1,0.125), LabelDot3D(A+vecI,"3","S",1,0.125), LabelDot3D(A+vecJ/3,"1","S",1,0.125),LabelDot3D(A+2*vecJ/3,"2","S",1,0.125), LabelDot3D(A+vecJ,"3","S",1,0.125), LabelDot3D(A+vecK/3,"1","O",1,0.125),LabelDot3D(A+2*vecK/3,"2","O",1,0.125), LabelDot3D(A+vecK,"3","O",1,0.125), B:=A+1.25*vecI, Arc3D(B+vecJ,B,B-vecJ,0.5,1,vecI), B:=A+1.25*vecJ, Arc3D(B-vecI,B,B+vecI,0.5,1,vecJ), B:=A+1.25*vecK, Arc3D(B+vecI,B,B-vecI,0.5,1,vecK), ];