Easy way to generate Rubik's cube diagrams

The name of the pictureThe name of the pictureThe name of the pictureClash 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



enter image description hereenter image description hereenter image description hereenter image description here



Using a solution from Playing around with a Rubik's Cube in TikZ, I was able to generate this diagram



enter image description here



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









share|improve this question









New contributor




Sam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • 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














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



enter image description hereenter image description hereenter image description hereenter image description here



Using a solution from Playing around with a Rubik's Cube in TikZ, I was able to generate this diagram



enter image description here



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









share|improve this question









New contributor




Sam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • 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












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



enter image description hereenter image description hereenter image description hereenter image description here



Using a solution from Playing around with a Rubik's Cube in TikZ, I was able to generate this diagram



enter image description here



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









share|improve this question









New contributor




Sam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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



enter image description hereenter image description hereenter image description hereenter image description here



Using a solution from Playing around with a Rubik's Cube in TikZ, I was able to generate this diagram



enter image description here



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






share|improve this question









New contributor




Sam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Sam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 3 hours ago





















New contributor




Sam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 3 hours ago









Sam

413




413




New contributor




Sam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Sam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Sam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











  • 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






  • 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










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


enter image description here



If you replace showcellnumbertrue by showcellnumberfalse, the numbers will be gone



enter image description here



EDIT: Illustrated the relation between array index and cell and adjusted the color (big thanks to @manooooh!).






share|improve this answer






















  • 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










Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "85"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);






Sam is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















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






























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


enter image description here



If you replace showcellnumbertrue by showcellnumberfalse, the numbers will be gone



enter image description here



EDIT: Illustrated the relation between array index and cell and adjusted the color (big thanks to @manooooh!).






share|improve this answer






















  • 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














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


enter image description here



If you replace showcellnumbertrue by showcellnumberfalse, the numbers will be gone



enter image description here



EDIT: Illustrated the relation between array index and cell and adjusted the color (big thanks to @manooooh!).






share|improve this answer






















  • 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












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


enter image description here



If you replace showcellnumbertrue by showcellnumberfalse, the numbers will be gone



enter image description here



EDIT: Illustrated the relation between array index and cell and adjusted the color (big thanks to @manooooh!).






share|improve this answer














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


enter image description here



If you replace showcellnumbertrue by showcellnumberfalse, the numbers will be gone



enter image description here



EDIT: Illustrated the relation between array index and cell and adjusted the color (big thanks to @manooooh!).







share|improve this answer














share|improve this answer



share|improve this answer








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
















  • 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










Sam is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















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.













 


draft saved


draft discarded














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













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?