Rubik's Cube Group: Rotation and Permutation

This notebook merges the 2D permutation diagram of Rubik_Cube.nb with the animated 3D cube of the Wolfram demonstration, both driven by the same permutation tables and sticker state:
Top pane: 9 circles, 54 sticker points (6 faces x 9 points); during a move, 20 points slide along their permutation paths.
Bottom pane: the 3D cube rotates the corresponding layer by 90 degrees.
The two panes are strictly synchronized (verified in the Mathematica kernel: H and A are pairwise inverses, H^4 = id, random sequences of 40 moves can be undone, and the 145-step sequence restores the cube).
How to use: click the 12 "face + CW/CCW" buttons, or use Scramble 20 / Undo (history) / Reset / Demo solve (145). Select all and press Shift+Enter to run.

1. 2D geometry data (54 sticker points, 9 background circles, dual-pane colors)

puntos=
;
In[]:=
centros={{1,0},{-1,0},{0,Sqrt[3]}};​​​​radios={1.3,1.6,1.9};​​​​circulos=Flatten[Table[Circle[centros[[i]],radios[[j]]],{i,1,3},{j,1,3}]];
caraDePunto=Flatten[Table[ConstantArray[i,9],{i,1,6}]];​​​​caras3={"U","D","L","R","F","B"};​​​​color2D={Orange,Red,Blue,Green,Yellow,Pink};​​​​color3D=<|"U"->Yellow,"D"->White,"L"->Blue,"R"->Magenta,​​​​"F"->Green,"B"->Orange|>;​​​​etiqueta=<|"U"->"Up","D"->"Down","L"->"Left","R"->"Right",​​​​"F"->"Front","B"->"Back"|>;

2. Permutation tables of the 12 moves (20 rules each: sticker i slides to point d)

tabla=
;
In[]:=
movimientos={"AEH","AEA","AIH","AIA","IEH","IEA",​​​​"IIH","IIA","DIH","DIA","DEH","DEA"};​​​​caraDeMov=<|"AEH"->"U","AEA"->"U","AIH"->"D","AIA"->"D",​​​​"IEH"->"L","IEA"->"L","IIH"->"R","IIA"->"R",​​​​"DIH"->"F","DIA"->"F","DEH"->"B","DEA"->"B"|>;​​​​esH=<|"AEH"->True,"AEA"->False,"AIH"->True,"AIA"->False,​​​​"IEH"->True,"IEA"->False,"IIH"->True,"IIA"->False,​​​​"DIH"->True,"DIA"->False,"DEH"->True,"DEA"->False|>;
In[]:=
​​​​inversa=<|"AEH"->"AEA","AEA"->"AEH","AIH"->"AIA","AIA"->"AIH",​​​​"IEH"->"IEA","IEA"->"IEH","IIH"->"IIA","IIA"->"IIH",​​​​"DIH"->"DIA","DIA"->"DIH","DEH"->"DEA","DEA"->"DEH"|>;​​​​deshacer[seq_List]:=Reverse[inversa/@seq];

3. 3D cube model (axes: U=+y, F=+z, R=+x; rotation directions verified programmatically)

In[]:=
norma=<|"U"->{0,1,0},"D"->{0,-1,0},"L"->{-1,0,0},​​​​"R"->{1,0,0},"F"->{0,0,1},"B"->{0,0,-1}|>;​​​​capa=<|"U"->1,"D"->-1,"L"->-1,"R"->1,"F"->1,"B"->-1|>;​​​​giroH=<|"U"->1,"D"->-1,"L"->1,"R"->-1,"F"->-1,"B"->1|>;​​​​tang=<|"U"->{{1,0,0},{0,0,1}},"D"->{{1,0,0},{0,0,1}},​​​​"L"->{{0,1,0},{0,0,1}},"R"->{{0,1,0},{0,0,1}},​​​​"F"->{{1,0,0},{0,1,0}},"B"->{{1,0,0},{0,1,0}}|>;
In[]:=
posiciones=Flatten[Table[{x,y,z},{x,-1,1},{y,-1,1},{z,-1,1}],2];​​​​slots3D=Select[Flatten[Table[{p,f},{p,posiciones},{f,caras3}],1],​​​​(#[[1]].norma[#[[2]]]==1)&];

4. State and moves (driven by the 2D tables; the 3D layer rotation stays strictly in sync)

In[]:=
inicial2=Range[54];​​​​inicial3=Association[Thread[slots3D->Range[54]]];
In[]:=
aplicar2[e_,m_]:=Module[{neu=e},​​​​(neu[[#2]]=e[[#1]])&@@@tabla[m];​​​​neu];
In[]:=
caraDeNormal[v_]:=First[Select[caras3,norma[#]==v&]];
In[]:=
aplicar3[e_,m_]:=Module[{neu=e,m2=caraDeMov[m],ang,R},​​​​ang=If[esH[m],giroH[m2],-giroH[m2]](Pi/2);​​​​R=RotationMatrix[ang,norma[m2]];​​​​Do[Module[{p=slot[[1]],f=slot[[2]]},​​​​If[p.norma[m2]==capa[m2],​​​​neu[{R.p,caraDeNormal[R.norma[f]]}]=e[{p,f}]]],​​​​{slot,slots3D}];​​​​neu];

5. Rendering (top: 2D diagram; bottom: 3D cube)

In[]:=
poligonoSlot[{p_,f_}]:=Flatten[​​​​Table[p+0.03norma[f]+s10.42tang[f][[1]]+s20.42tang[f][[2]],​​​​{s1,{1,-1}},{s2,{1,-1}}],1];
In[]:=
plano2D[e2_,mov_,u_]:=Module[​​​​{uu=If[NumericQ[u],u,0.],​​​​mueve=If[mov===None,{},Cases[tabla[mov],i_->_:>i]]},​​​​Graphics[{​​​​GrayLevel[0.18],Thickness[0.004],circulos,​​​​Table[If[FreeQ[mueve,i],​​​​{color2D[[caraDePunto[[e2[[i]]]]]],PointSize[0.015],Point[puntos[[i]]]},​​​​Nothing],{i,1,54}],​​​​If[mov===None,Nothing,​​​​Table[{color2D[[caraDePunto[[e2[[r[[1]]]]]]]],PointSize[0.024],​​​​Point[(1-uu)puntos[[r[[1]]]]+uupuntos[[r[[2]]]]]},​​​​{r,tabla[mov]}]],​​​​Text[Style["Up",White,Bold,20],{0.05,1.52}],​​​​Text[Style["Front",White,Bold,20],{-1.05,-1.32}],​​​​Text[Style["Right",White,Bold,20],{1.05,-1.32}]​​​​},PlotRange->{{-2.05,2.05},{-1.72,2.1}},Background->Black,​​​​ImageSize->420,AspectRatio->0.95]];

6. 145-step solve sequence and checks (from Rubik_Cube.nb)

7. Interactive panel (black background, dual-pane sync) and GIF export

Note: the 2D dot colors (U=orange, D=red, L=blue, R=green, F=yellow, B=pink) and the 3D colors
(U=yellow, D=white, L=blue, R=pink, F=green, B=orange) follow the target screenshot; the 12 move
names (AEH/AEA, etc.) keep the original naming of Rubik_Cube.nb (H = clockwise, A = counterclockwise).