Easy way to generate Rubik's cube diagrams
Clash Royale CLAN TAG#URR8PPP
up vote
8
down vote
favorite
Taking inspiration from Playing around with a Rubik's Cube in TikZ, I want to generate diagrams of Rubik's cubes that look like this
Using a solution from Playing around with a Rubik's Cube in TikZ, I was able to generate this diagram
My question is what is the best way to modify the code so I can quickly generate the diagrams in the above graphic? Something like a command cube....
? But even I am not sure how you can specify the colour info in this manner. Use a symbol for each colour? G - green, B - blue etc. So there are 27 square faces in this diagram, so does that mean you need 27 arguments? And if you leave it blank then it will display a gray tile? I would appreciate any advice the best way to code this in LaTeX. My ultimate goal is to make over 100 diagrams like the ones above. So if it was possible to make a really efficient code to generate the diagrams that would be amazing.
MWE
documentclassarticle
usepackagetikz
usepackagetikz-3dplot
usetikzlibrary3d
begindocument
pgfmathsetmacroradius0.1
newcommandfrontcolorred
newcommandsidecolorblue
tdplotsetmaincoords55135
begintikzpicture
clip (-3,-2.5) rectangle (3,2.5);
beginscope[tdplot_main_coords]
filldraw [canvas is yz plane at x=1.5] (-1.5,-1.5) rectangle (1.5,1.5);
filldraw [canvas is xz plane at y=1.5] (-1.5,-1.5) rectangle (1.5,1.5);
filldraw [canvas is yx plane at z=1.5] (-1.5,-1.5) rectangle (1.5,1.5);
foreach X in -1.5,-0.5,0.5
foreach Y in -1.5,-0.5,0.5
draw [thick,canvas is yz plane at x=1.5,shift=(X,Y),fill=sidecolor] (0.5,0) -- (1-radius,0) arc (-90:0:radius) -- (1,1-radius) arc (0:90:radius) -- (radius,1) arc (90:180:radius) -- (0,radius) arc (180:270:radius) -- cycle;
draw [thick,canvas is xz plane at y=1.5,shift=(X,Y),fill=frontcolor] (0.5,0) -- (1-radius,0) arc (-90:0:radius) -- (1,1-radius) arc (0:90:radius) -- (radius,1) arc (90:180:radius) -- (0,radius) arc (180:270:radius) -- cycle;
draw [thick,canvas is yx plane at z=1.5,shift=(X,Y),fill=yellow] (0.5,0) -- (1-radius,0) arc (-90:0:radius) -- (1,1-radius) arc (0:90:radius) -- (radius,1) arc (90:180:radius) -- (0,radius) arc (180:270:radius) -- cycle;
endscope
endtikzpicture
enddocument
tikz-pgf
New contributor
add a comment |
up vote
8
down vote
favorite
Taking inspiration from Playing around with a Rubik's Cube in TikZ, I want to generate diagrams of Rubik's cubes that look like this
Using a solution from Playing around with a Rubik's Cube in TikZ, I was able to generate this diagram
My question is what is the best way to modify the code so I can quickly generate the diagrams in the above graphic? Something like a command cube....
? But even I am not sure how you can specify the colour info in this manner. Use a symbol for each colour? G - green, B - blue etc. So there are 27 square faces in this diagram, so does that mean you need 27 arguments? And if you leave it blank then it will display a gray tile? I would appreciate any advice the best way to code this in LaTeX. My ultimate goal is to make over 100 diagrams like the ones above. So if it was possible to make a really efficient code to generate the diagrams that would be amazing.
MWE
documentclassarticle
usepackagetikz
usepackagetikz-3dplot
usetikzlibrary3d
begindocument
pgfmathsetmacroradius0.1
newcommandfrontcolorred
newcommandsidecolorblue
tdplotsetmaincoords55135
begintikzpicture
clip (-3,-2.5) rectangle (3,2.5);
beginscope[tdplot_main_coords]
filldraw [canvas is yz plane at x=1.5] (-1.5,-1.5) rectangle (1.5,1.5);
filldraw [canvas is xz plane at y=1.5] (-1.5,-1.5) rectangle (1.5,1.5);
filldraw [canvas is yx plane at z=1.5] (-1.5,-1.5) rectangle (1.5,1.5);
foreach X in -1.5,-0.5,0.5
foreach Y in -1.5,-0.5,0.5
draw [thick,canvas is yz plane at x=1.5,shift=(X,Y),fill=sidecolor] (0.5,0) -- (1-radius,0) arc (-90:0:radius) -- (1,1-radius) arc (0:90:radius) -- (radius,1) arc (90:180:radius) -- (0,radius) arc (180:270:radius) -- cycle;
draw [thick,canvas is xz plane at y=1.5,shift=(X,Y),fill=frontcolor] (0.5,0) -- (1-radius,0) arc (-90:0:radius) -- (1,1-radius) arc (0:90:radius) -- (radius,1) arc (90:180:radius) -- (0,radius) arc (180:270:radius) -- cycle;
draw [thick,canvas is yx plane at z=1.5,shift=(X,Y),fill=yellow] (0.5,0) -- (1-radius,0) arc (-90:0:radius) -- (1,1-radius) arc (0:90:radius) -- (radius,1) arc (90:180:radius) -- (0,radius) arc (180:270:radius) -- cycle;
endscope
endtikzpicture
enddocument
tikz-pgf
New contributor
When you say strings do you mean the notation like R' U R2 U R'...? Sorry to confuse you but that's something different (a set of moves) and not related to the way the cube is coloured. I will update my question.
– Sam
3 hours ago
1
@marmot The only way I can see is you need to specify the individual colours of all 27 faces. Or alternatively, you start with a blank (gray) cube and you specify where to add colours, using a matrix-like notation? I am not sure what is the best format basically. And was asking here to see if anyone can suggest a nice way to code it.
– Sam
3 hours ago
add a comment |
up vote
8
down vote
favorite
up vote
8
down vote
favorite
Taking inspiration from Playing around with a Rubik's Cube in TikZ, I want to generate diagrams of Rubik's cubes that look like this
Using a solution from Playing around with a Rubik's Cube in TikZ, I was able to generate this diagram
My question is what is the best way to modify the code so I can quickly generate the diagrams in the above graphic? Something like a command cube....
? But even I am not sure how you can specify the colour info in this manner. Use a symbol for each colour? G - green, B - blue etc. So there are 27 square faces in this diagram, so does that mean you need 27 arguments? And if you leave it blank then it will display a gray tile? I would appreciate any advice the best way to code this in LaTeX. My ultimate goal is to make over 100 diagrams like the ones above. So if it was possible to make a really efficient code to generate the diagrams that would be amazing.
MWE
documentclassarticle
usepackagetikz
usepackagetikz-3dplot
usetikzlibrary3d
begindocument
pgfmathsetmacroradius0.1
newcommandfrontcolorred
newcommandsidecolorblue
tdplotsetmaincoords55135
begintikzpicture
clip (-3,-2.5) rectangle (3,2.5);
beginscope[tdplot_main_coords]
filldraw [canvas is yz plane at x=1.5] (-1.5,-1.5) rectangle (1.5,1.5);
filldraw [canvas is xz plane at y=1.5] (-1.5,-1.5) rectangle (1.5,1.5);
filldraw [canvas is yx plane at z=1.5] (-1.5,-1.5) rectangle (1.5,1.5);
foreach X in -1.5,-0.5,0.5
foreach Y in -1.5,-0.5,0.5
draw [thick,canvas is yz plane at x=1.5,shift=(X,Y),fill=sidecolor] (0.5,0) -- (1-radius,0) arc (-90:0:radius) -- (1,1-radius) arc (0:90:radius) -- (radius,1) arc (90:180:radius) -- (0,radius) arc (180:270:radius) -- cycle;
draw [thick,canvas is xz plane at y=1.5,shift=(X,Y),fill=frontcolor] (0.5,0) -- (1-radius,0) arc (-90:0:radius) -- (1,1-radius) arc (0:90:radius) -- (radius,1) arc (90:180:radius) -- (0,radius) arc (180:270:radius) -- cycle;
draw [thick,canvas is yx plane at z=1.5,shift=(X,Y),fill=yellow] (0.5,0) -- (1-radius,0) arc (-90:0:radius) -- (1,1-radius) arc (0:90:radius) -- (radius,1) arc (90:180:radius) -- (0,radius) arc (180:270:radius) -- cycle;
endscope
endtikzpicture
enddocument
tikz-pgf
New contributor
Taking inspiration from Playing around with a Rubik's Cube in TikZ, I want to generate diagrams of Rubik's cubes that look like this
Using a solution from Playing around with a Rubik's Cube in TikZ, I was able to generate this diagram
My question is what is the best way to modify the code so I can quickly generate the diagrams in the above graphic? Something like a command cube....
? But even I am not sure how you can specify the colour info in this manner. Use a symbol for each colour? G - green, B - blue etc. So there are 27 square faces in this diagram, so does that mean you need 27 arguments? And if you leave it blank then it will display a gray tile? I would appreciate any advice the best way to code this in LaTeX. My ultimate goal is to make over 100 diagrams like the ones above. So if it was possible to make a really efficient code to generate the diagrams that would be amazing.
MWE
documentclassarticle
usepackagetikz
usepackagetikz-3dplot
usetikzlibrary3d
begindocument
pgfmathsetmacroradius0.1
newcommandfrontcolorred
newcommandsidecolorblue
tdplotsetmaincoords55135
begintikzpicture
clip (-3,-2.5) rectangle (3,2.5);
beginscope[tdplot_main_coords]
filldraw [canvas is yz plane at x=1.5] (-1.5,-1.5) rectangle (1.5,1.5);
filldraw [canvas is xz plane at y=1.5] (-1.5,-1.5) rectangle (1.5,1.5);
filldraw [canvas is yx plane at z=1.5] (-1.5,-1.5) rectangle (1.5,1.5);
foreach X in -1.5,-0.5,0.5
foreach Y in -1.5,-0.5,0.5
draw [thick,canvas is yz plane at x=1.5,shift=(X,Y),fill=sidecolor] (0.5,0) -- (1-radius,0) arc (-90:0:radius) -- (1,1-radius) arc (0:90:radius) -- (radius,1) arc (90:180:radius) -- (0,radius) arc (180:270:radius) -- cycle;
draw [thick,canvas is xz plane at y=1.5,shift=(X,Y),fill=frontcolor] (0.5,0) -- (1-radius,0) arc (-90:0:radius) -- (1,1-radius) arc (0:90:radius) -- (radius,1) arc (90:180:radius) -- (0,radius) arc (180:270:radius) -- cycle;
draw [thick,canvas is yx plane at z=1.5,shift=(X,Y),fill=yellow] (0.5,0) -- (1-radius,0) arc (-90:0:radius) -- (1,1-radius) arc (0:90:radius) -- (radius,1) arc (90:180:radius) -- (0,radius) arc (180:270:radius) -- cycle;
endscope
endtikzpicture
enddocument
tikz-pgf
tikz-pgf
New contributor
New contributor
edited 3 hours ago
New contributor
asked 3 hours ago
Sam
413
413
New contributor
New contributor
When you say strings do you mean the notation like R' U R2 U R'...? Sorry to confuse you but that's something different (a set of moves) and not related to the way the cube is coloured. I will update my question.
– Sam
3 hours ago
1
@marmot The only way I can see is you need to specify the individual colours of all 27 faces. Or alternatively, you start with a blank (gray) cube and you specify where to add colours, using a matrix-like notation? I am not sure what is the best format basically. And was asking here to see if anyone can suggest a nice way to code it.
– Sam
3 hours ago
add a comment |
When you say strings do you mean the notation like R' U R2 U R'...? Sorry to confuse you but that's something different (a set of moves) and not related to the way the cube is coloured. I will update my question.
– Sam
3 hours ago
1
@marmot The only way I can see is you need to specify the individual colours of all 27 faces. Or alternatively, you start with a blank (gray) cube and you specify where to add colours, using a matrix-like notation? I am not sure what is the best format basically. And was asking here to see if anyone can suggest a nice way to code it.
– Sam
3 hours ago
When you say strings do you mean the notation like R' U R2 U R'...? Sorry to confuse you but that's something different (a set of moves) and not related to the way the cube is coloured. I will update my question.
– Sam
3 hours ago
When you say strings do you mean the notation like R' U R2 U R'...? Sorry to confuse you but that's something different (a set of moves) and not related to the way the cube is coloured. I will update my question.
– Sam
3 hours ago
1
1
@marmot The only way I can see is you need to specify the individual colours of all 27 faces. Or alternatively, you start with a blank (gray) cube and you specify where to add colours, using a matrix-like notation? I am not sure what is the best format basically. And was asking here to see if anyone can suggest a nice way to code it.
– Sam
3 hours ago
@marmot The only way I can see is you need to specify the individual colours of all 27 faces. Or alternatively, you start with a blank (gray) cube and you specify where to add colours, using a matrix-like notation? I am not sure what is the best format basically. And was asking here to see if anyone can suggest a nice way to code it.
– Sam
3 hours ago
add a comment |
1 Answer
1
active
oldest
votes
up vote
6
down vote
That's a neat question, and here is a proposal for an answer. The colors are stored in an array called myarray
, which determines the colors of the cells. The relation between entry (the index starts at 0) and cell is illustrated by this example
documentclassarticle
usepackagetikz
usepackagetikz-3dplot
usetikzlibrary3d
newififshowcellnumber
showcellnumbertrue
begindocument
definecolorRRGB202,65,55
definecolorGRGB151,216,56
definecolorBRGB51,72,237
%definecolorWRGB255,255,255
definecolorWRGB65,65,65
defmyarray"W","W","B","W","G","W","R","R","W","W","W","W","G","W","B","B","W","W","G","B","R","W","R","B","W","W","W"
pgfmathsetmacroradius0.1
newcommandfrontcolorred
newcommandsidecolorblue
tdplotsetmaincoords55135
begintikzpicture
clip (-3,-2.5) rectangle (3,2.5);
beginscope[tdplot_main_coords]
filldraw [canvas is yz plane at x=1.5] (-1.5,-1.5) rectangle (1.5,1.5);
filldraw [canvas is xz plane at y=1.5] (-1.5,-1.5) rectangle (1.5,1.5);
filldraw [canvas is yx plane at z=1.5] (-1.5,-1.5) rectangle (1.5,1.5);
foreach X [count=XX starting from 0] in -1.5,-0.5,0.5
foreach Y [count=YY starting from 0] in -1.5,-0.5,0.5
pgfmathtruncatemacroZXX+3*(2-YY)
pgfmathsetmacromycolormyarray[Z]
draw [thick,canvas is yz plane at
x=1.5,shift=(X,Y),fill=mycolor] (0.5,0) -- (1-radius,0) arc
(-90:0:radius) -- (1,1-radius) arc (0:90:radius) -- (radius,1) arc
(90:180:radius) -- (0,radius) arc (180:270:radius) -- cycle;
ifshowcellnumber
node[canvas is yz plane at x=1.5,shift=(X+0.5,Y+0.5)] Z;
fi
pgfmathtruncatemacroZ2-XX+3*(2-YY)+9
pgfmathsetmacromycolormyarray[Z]
draw [thick,canvas is xz plane at
y=1.5,shift=(X,Y),fill=mycolor] (0.5,0) -- (1-radius,0) arc
(-90:0:radius) -- (1,1-radius) arc (0:90:radius) -- (radius,1) arc
(90:180:radius) -- (0,radius) arc (180:270:radius) -- cycle;
ifshowcellnumber
node[canvas is xz plane at y=1.5,shift=(X+0.5,Y+0.5),xscale=-1] Z;
fi
pgfmathtruncatemacroZ2-YY+3*XX+18
pgfmathsetmacromycolormyarray[Z]
draw [thick,canvas is yx plane at
z=1.5,shift=(X,Y),fill=mycolor] (0.5,0) -- (1-radius,0) arc
(-90:0:radius) -- (1,1-radius) arc (0:90:radius) -- (radius,1) arc
(90:180:radius) -- (0,radius) arc (180:270:radius) -- cycle;
ifshowcellnumber
node[canvas is yx plane at z=1.5,shift=(X+0.5,Y+0.5),xscale=-1,rotate=-90] Z;
fi
endscope
endtikzpicture
enddocument
If you replace showcellnumbertrue
by showcellnumberfalse
, the numbers will be gone
EDIT: Illustrated the relation between array index and cell and adjusted the color (big thanks to @manooooh!).
According to the first image of OP the white cubes should be black.
– manooooh
2 hours ago
1
@manooooh You're right, thanks a lot!
– marmot
2 hours ago
Lovely, as always. Can we tweak the cube to add perspective? There's a question here somewhere about it.
– Loop Space
10 mins ago
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
6
down vote
That's a neat question, and here is a proposal for an answer. The colors are stored in an array called myarray
, which determines the colors of the cells. The relation between entry (the index starts at 0) and cell is illustrated by this example
documentclassarticle
usepackagetikz
usepackagetikz-3dplot
usetikzlibrary3d
newififshowcellnumber
showcellnumbertrue
begindocument
definecolorRRGB202,65,55
definecolorGRGB151,216,56
definecolorBRGB51,72,237
%definecolorWRGB255,255,255
definecolorWRGB65,65,65
defmyarray"W","W","B","W","G","W","R","R","W","W","W","W","G","W","B","B","W","W","G","B","R","W","R","B","W","W","W"
pgfmathsetmacroradius0.1
newcommandfrontcolorred
newcommandsidecolorblue
tdplotsetmaincoords55135
begintikzpicture
clip (-3,-2.5) rectangle (3,2.5);
beginscope[tdplot_main_coords]
filldraw [canvas is yz plane at x=1.5] (-1.5,-1.5) rectangle (1.5,1.5);
filldraw [canvas is xz plane at y=1.5] (-1.5,-1.5) rectangle (1.5,1.5);
filldraw [canvas is yx plane at z=1.5] (-1.5,-1.5) rectangle (1.5,1.5);
foreach X [count=XX starting from 0] in -1.5,-0.5,0.5
foreach Y [count=YY starting from 0] in -1.5,-0.5,0.5
pgfmathtruncatemacroZXX+3*(2-YY)
pgfmathsetmacromycolormyarray[Z]
draw [thick,canvas is yz plane at
x=1.5,shift=(X,Y),fill=mycolor] (0.5,0) -- (1-radius,0) arc
(-90:0:radius) -- (1,1-radius) arc (0:90:radius) -- (radius,1) arc
(90:180:radius) -- (0,radius) arc (180:270:radius) -- cycle;
ifshowcellnumber
node[canvas is yz plane at x=1.5,shift=(X+0.5,Y+0.5)] Z;
fi
pgfmathtruncatemacroZ2-XX+3*(2-YY)+9
pgfmathsetmacromycolormyarray[Z]
draw [thick,canvas is xz plane at
y=1.5,shift=(X,Y),fill=mycolor] (0.5,0) -- (1-radius,0) arc
(-90:0:radius) -- (1,1-radius) arc (0:90:radius) -- (radius,1) arc
(90:180:radius) -- (0,radius) arc (180:270:radius) -- cycle;
ifshowcellnumber
node[canvas is xz plane at y=1.5,shift=(X+0.5,Y+0.5),xscale=-1] Z;
fi
pgfmathtruncatemacroZ2-YY+3*XX+18
pgfmathsetmacromycolormyarray[Z]
draw [thick,canvas is yx plane at
z=1.5,shift=(X,Y),fill=mycolor] (0.5,0) -- (1-radius,0) arc
(-90:0:radius) -- (1,1-radius) arc (0:90:radius) -- (radius,1) arc
(90:180:radius) -- (0,radius) arc (180:270:radius) -- cycle;
ifshowcellnumber
node[canvas is yx plane at z=1.5,shift=(X+0.5,Y+0.5),xscale=-1,rotate=-90] Z;
fi
endscope
endtikzpicture
enddocument
If you replace showcellnumbertrue
by showcellnumberfalse
, the numbers will be gone
EDIT: Illustrated the relation between array index and cell and adjusted the color (big thanks to @manooooh!).
According to the first image of OP the white cubes should be black.
– manooooh
2 hours ago
1
@manooooh You're right, thanks a lot!
– marmot
2 hours ago
Lovely, as always. Can we tweak the cube to add perspective? There's a question here somewhere about it.
– Loop Space
10 mins ago
add a comment |
up vote
6
down vote
That's a neat question, and here is a proposal for an answer. The colors are stored in an array called myarray
, which determines the colors of the cells. The relation between entry (the index starts at 0) and cell is illustrated by this example
documentclassarticle
usepackagetikz
usepackagetikz-3dplot
usetikzlibrary3d
newififshowcellnumber
showcellnumbertrue
begindocument
definecolorRRGB202,65,55
definecolorGRGB151,216,56
definecolorBRGB51,72,237
%definecolorWRGB255,255,255
definecolorWRGB65,65,65
defmyarray"W","W","B","W","G","W","R","R","W","W","W","W","G","W","B","B","W","W","G","B","R","W","R","B","W","W","W"
pgfmathsetmacroradius0.1
newcommandfrontcolorred
newcommandsidecolorblue
tdplotsetmaincoords55135
begintikzpicture
clip (-3,-2.5) rectangle (3,2.5);
beginscope[tdplot_main_coords]
filldraw [canvas is yz plane at x=1.5] (-1.5,-1.5) rectangle (1.5,1.5);
filldraw [canvas is xz plane at y=1.5] (-1.5,-1.5) rectangle (1.5,1.5);
filldraw [canvas is yx plane at z=1.5] (-1.5,-1.5) rectangle (1.5,1.5);
foreach X [count=XX starting from 0] in -1.5,-0.5,0.5
foreach Y [count=YY starting from 0] in -1.5,-0.5,0.5
pgfmathtruncatemacroZXX+3*(2-YY)
pgfmathsetmacromycolormyarray[Z]
draw [thick,canvas is yz plane at
x=1.5,shift=(X,Y),fill=mycolor] (0.5,0) -- (1-radius,0) arc
(-90:0:radius) -- (1,1-radius) arc (0:90:radius) -- (radius,1) arc
(90:180:radius) -- (0,radius) arc (180:270:radius) -- cycle;
ifshowcellnumber
node[canvas is yz plane at x=1.5,shift=(X+0.5,Y+0.5)] Z;
fi
pgfmathtruncatemacroZ2-XX+3*(2-YY)+9
pgfmathsetmacromycolormyarray[Z]
draw [thick,canvas is xz plane at
y=1.5,shift=(X,Y),fill=mycolor] (0.5,0) -- (1-radius,0) arc
(-90:0:radius) -- (1,1-radius) arc (0:90:radius) -- (radius,1) arc
(90:180:radius) -- (0,radius) arc (180:270:radius) -- cycle;
ifshowcellnumber
node[canvas is xz plane at y=1.5,shift=(X+0.5,Y+0.5),xscale=-1] Z;
fi
pgfmathtruncatemacroZ2-YY+3*XX+18
pgfmathsetmacromycolormyarray[Z]
draw [thick,canvas is yx plane at
z=1.5,shift=(X,Y),fill=mycolor] (0.5,0) -- (1-radius,0) arc
(-90:0:radius) -- (1,1-radius) arc (0:90:radius) -- (radius,1) arc
(90:180:radius) -- (0,radius) arc (180:270:radius) -- cycle;
ifshowcellnumber
node[canvas is yx plane at z=1.5,shift=(X+0.5,Y+0.5),xscale=-1,rotate=-90] Z;
fi
endscope
endtikzpicture
enddocument
If you replace showcellnumbertrue
by showcellnumberfalse
, the numbers will be gone
EDIT: Illustrated the relation between array index and cell and adjusted the color (big thanks to @manooooh!).
According to the first image of OP the white cubes should be black.
– manooooh
2 hours ago
1
@manooooh You're right, thanks a lot!
– marmot
2 hours ago
Lovely, as always. Can we tweak the cube to add perspective? There's a question here somewhere about it.
– Loop Space
10 mins ago
add a comment |
up vote
6
down vote
up vote
6
down vote
That's a neat question, and here is a proposal for an answer. The colors are stored in an array called myarray
, which determines the colors of the cells. The relation between entry (the index starts at 0) and cell is illustrated by this example
documentclassarticle
usepackagetikz
usepackagetikz-3dplot
usetikzlibrary3d
newififshowcellnumber
showcellnumbertrue
begindocument
definecolorRRGB202,65,55
definecolorGRGB151,216,56
definecolorBRGB51,72,237
%definecolorWRGB255,255,255
definecolorWRGB65,65,65
defmyarray"W","W","B","W","G","W","R","R","W","W","W","W","G","W","B","B","W","W","G","B","R","W","R","B","W","W","W"
pgfmathsetmacroradius0.1
newcommandfrontcolorred
newcommandsidecolorblue
tdplotsetmaincoords55135
begintikzpicture
clip (-3,-2.5) rectangle (3,2.5);
beginscope[tdplot_main_coords]
filldraw [canvas is yz plane at x=1.5] (-1.5,-1.5) rectangle (1.5,1.5);
filldraw [canvas is xz plane at y=1.5] (-1.5,-1.5) rectangle (1.5,1.5);
filldraw [canvas is yx plane at z=1.5] (-1.5,-1.5) rectangle (1.5,1.5);
foreach X [count=XX starting from 0] in -1.5,-0.5,0.5
foreach Y [count=YY starting from 0] in -1.5,-0.5,0.5
pgfmathtruncatemacroZXX+3*(2-YY)
pgfmathsetmacromycolormyarray[Z]
draw [thick,canvas is yz plane at
x=1.5,shift=(X,Y),fill=mycolor] (0.5,0) -- (1-radius,0) arc
(-90:0:radius) -- (1,1-radius) arc (0:90:radius) -- (radius,1) arc
(90:180:radius) -- (0,radius) arc (180:270:radius) -- cycle;
ifshowcellnumber
node[canvas is yz plane at x=1.5,shift=(X+0.5,Y+0.5)] Z;
fi
pgfmathtruncatemacroZ2-XX+3*(2-YY)+9
pgfmathsetmacromycolormyarray[Z]
draw [thick,canvas is xz plane at
y=1.5,shift=(X,Y),fill=mycolor] (0.5,0) -- (1-radius,0) arc
(-90:0:radius) -- (1,1-radius) arc (0:90:radius) -- (radius,1) arc
(90:180:radius) -- (0,radius) arc (180:270:radius) -- cycle;
ifshowcellnumber
node[canvas is xz plane at y=1.5,shift=(X+0.5,Y+0.5),xscale=-1] Z;
fi
pgfmathtruncatemacroZ2-YY+3*XX+18
pgfmathsetmacromycolormyarray[Z]
draw [thick,canvas is yx plane at
z=1.5,shift=(X,Y),fill=mycolor] (0.5,0) -- (1-radius,0) arc
(-90:0:radius) -- (1,1-radius) arc (0:90:radius) -- (radius,1) arc
(90:180:radius) -- (0,radius) arc (180:270:radius) -- cycle;
ifshowcellnumber
node[canvas is yx plane at z=1.5,shift=(X+0.5,Y+0.5),xscale=-1,rotate=-90] Z;
fi
endscope
endtikzpicture
enddocument
If you replace showcellnumbertrue
by showcellnumberfalse
, the numbers will be gone
EDIT: Illustrated the relation between array index and cell and adjusted the color (big thanks to @manooooh!).
That's a neat question, and here is a proposal for an answer. The colors are stored in an array called myarray
, which determines the colors of the cells. The relation between entry (the index starts at 0) and cell is illustrated by this example
documentclassarticle
usepackagetikz
usepackagetikz-3dplot
usetikzlibrary3d
newififshowcellnumber
showcellnumbertrue
begindocument
definecolorRRGB202,65,55
definecolorGRGB151,216,56
definecolorBRGB51,72,237
%definecolorWRGB255,255,255
definecolorWRGB65,65,65
defmyarray"W","W","B","W","G","W","R","R","W","W","W","W","G","W","B","B","W","W","G","B","R","W","R","B","W","W","W"
pgfmathsetmacroradius0.1
newcommandfrontcolorred
newcommandsidecolorblue
tdplotsetmaincoords55135
begintikzpicture
clip (-3,-2.5) rectangle (3,2.5);
beginscope[tdplot_main_coords]
filldraw [canvas is yz plane at x=1.5] (-1.5,-1.5) rectangle (1.5,1.5);
filldraw [canvas is xz plane at y=1.5] (-1.5,-1.5) rectangle (1.5,1.5);
filldraw [canvas is yx plane at z=1.5] (-1.5,-1.5) rectangle (1.5,1.5);
foreach X [count=XX starting from 0] in -1.5,-0.5,0.5
foreach Y [count=YY starting from 0] in -1.5,-0.5,0.5
pgfmathtruncatemacroZXX+3*(2-YY)
pgfmathsetmacromycolormyarray[Z]
draw [thick,canvas is yz plane at
x=1.5,shift=(X,Y),fill=mycolor] (0.5,0) -- (1-radius,0) arc
(-90:0:radius) -- (1,1-radius) arc (0:90:radius) -- (radius,1) arc
(90:180:radius) -- (0,radius) arc (180:270:radius) -- cycle;
ifshowcellnumber
node[canvas is yz plane at x=1.5,shift=(X+0.5,Y+0.5)] Z;
fi
pgfmathtruncatemacroZ2-XX+3*(2-YY)+9
pgfmathsetmacromycolormyarray[Z]
draw [thick,canvas is xz plane at
y=1.5,shift=(X,Y),fill=mycolor] (0.5,0) -- (1-radius,0) arc
(-90:0:radius) -- (1,1-radius) arc (0:90:radius) -- (radius,1) arc
(90:180:radius) -- (0,radius) arc (180:270:radius) -- cycle;
ifshowcellnumber
node[canvas is xz plane at y=1.5,shift=(X+0.5,Y+0.5),xscale=-1] Z;
fi
pgfmathtruncatemacroZ2-YY+3*XX+18
pgfmathsetmacromycolormyarray[Z]
draw [thick,canvas is yx plane at
z=1.5,shift=(X,Y),fill=mycolor] (0.5,0) -- (1-radius,0) arc
(-90:0:radius) -- (1,1-radius) arc (0:90:radius) -- (radius,1) arc
(90:180:radius) -- (0,radius) arc (180:270:radius) -- cycle;
ifshowcellnumber
node[canvas is yx plane at z=1.5,shift=(X+0.5,Y+0.5),xscale=-1,rotate=-90] Z;
fi
endscope
endtikzpicture
enddocument
If you replace showcellnumbertrue
by showcellnumberfalse
, the numbers will be gone
EDIT: Illustrated the relation between array index and cell and adjusted the color (big thanks to @manooooh!).
edited 2 hours ago
answered 3 hours ago
marmot
73.4k478153
73.4k478153
According to the first image of OP the white cubes should be black.
– manooooh
2 hours ago
1
@manooooh You're right, thanks a lot!
– marmot
2 hours ago
Lovely, as always. Can we tweak the cube to add perspective? There's a question here somewhere about it.
– Loop Space
10 mins ago
add a comment |
According to the first image of OP the white cubes should be black.
– manooooh
2 hours ago
1
@manooooh You're right, thanks a lot!
– marmot
2 hours ago
Lovely, as always. Can we tweak the cube to add perspective? There's a question here somewhere about it.
– Loop Space
10 mins ago
According to the first image of OP the white cubes should be black.
– manooooh
2 hours ago
According to the first image of OP the white cubes should be black.
– manooooh
2 hours ago
1
1
@manooooh You're right, thanks a lot!
– marmot
2 hours ago
@manooooh You're right, thanks a lot!
– marmot
2 hours ago
Lovely, as always. Can we tweak the cube to add perspective? There's a question here somewhere about it.
– Loop Space
10 mins ago
Lovely, as always. Can we tweak the cube to add perspective? There's a question here somewhere about it.
– Loop Space
10 mins ago
add a comment |
Sam is a new contributor. Be nice, and check out our Code of Conduct.
Sam is a new contributor. Be nice, and check out our Code of Conduct.
Sam is a new contributor. Be nice, and check out our Code of Conduct.
Sam is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f459254%2feasy-way-to-generate-rubiks-cube-diagrams%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
When you say strings do you mean the notation like R' U R2 U R'...? Sorry to confuse you but that's something different (a set of moves) and not related to the way the cube is coloured. I will update my question.
– Sam
3 hours ago
1
@marmot The only way I can see is you need to specify the individual colours of all 27 faces. Or alternatively, you start with a blank (gray) cube and you specify where to add colours, using a matrix-like notation? I am not sure what is the best format basically. And was asking here to see if anyone can suggest a nice way to code it.
– Sam
3 hours ago