5
\documentclass[pstricks,border=10pt]{standalone}
\usepackage{pst-solides3d}
\usepackage{arrayjob}
\begin{document}

\newarray\colors
\readarray{colors}{red&red&red&red&red&red&red&red&yellow&yellow&yellow&yellow&yellow&yellow&yellow&yellow&yellow&orange&orange&orange&orange&orange&orange&orange&orange&orange&green&green&green&green&green&green&green&green&green&blue&blue&blue&blue&blue&blue&blue&blue&blue}

\edef\colorfaces{}%
\multido{\i=0+1}{57}{%
\checkcolors(\i)
\xdef\colorfaces{\colorfaces\i\space(\cachedata)\space}}
%
\def\figure#1#2{%
\psset{viewpoint=120 50 30 rtp2xyz,Decran=50}
\begin{pspicture}(-3,-3)(3,3)
\psSolid[a=8,object=cube,ngrid=3,%
fcol=\colorfaces%
,Rot#2=-#1\space]%
\end{pspicture}
}
\multido{\iA=0+10}{36}{\figure{\iA}{X}}
\multido{\iA=0+10}{36}{\figure{\iA}{Y}}
\multido{\iA=0+10}{36}{\figure{\iA}{Z}}
\end{document}

enter image description here

Question:

  1. Is there an another way without using the package arrayjob?

  2. How to get the random color for it?

Thanks.

3
  • 1
    As for 2.: you are already loading pgf, so you have already a built in way to get a random item. Just add \pgfmathdeclarerandomlist{colors}{{red}{red}{red}{red}{red}{red}{red}{red}{yellow}{yellow}{yellow}{yellow}{yellow}{yellow}{yellow}{yellow}{yellow}{orange}{orange}{orange}{orange}{orange}{orange}{orange}{orange}{orange}{green}{green}{green}{green}{green}{green}{green}{green}{green}{blue}{blue}{blue}{blue}{blue}{blue}{blue}{blue}{blue}} \pgfmathrandomitem{\c}{colors} \typeout{\c} to your code.
    – user121799
    Feb 21, 2019 at 14:51
  • It occurred to me that random colors may not be a good idea. There are six colors, eight corners and eight edges. Each edge has a unique combination of 2 colors, and each corner has a unique combination of 3 colors, of which each color is used in precisely 4 corners and 4 edges. And each of 6 centers has a different color. What you really need is a random sort of the different components. Feb 21, 2019 at 23:47
  • Because the colors are not freely randomized but they must follow some rules, I think I need to change the title to be more specific. Feb 22, 2019 at 3:13

1 Answer 1

5
\documentclass[pstricks,border=10pt]{standalone}
\usepackage{pst-solides3d}
\begin{document}

\psset{viewpoint=120 50 30 rtp2xyz,Decran=50}
\pstVerb{/Colors [(red)(yellow)(orange)(green)(blue)] def }
\def\figure#1#2{%
  \begin{pspicture}(-3,-3)(3,3)
        \psSolid[a=8,object=cube,ngrid=3,%
        fcol= 
           0 1 8 { Colors Rand 4.5 mul cvi get } for  
           9 1 17 { Colors Rand 4.5 mul cvi get } for  
           18 1 26 { Colors Rand 4.5 mul cvi get } for  
           27 1 35 { Colors Rand 4.5 mul cvi get } for  
           36 1 44 { Colors Rand 4.5 mul cvi get } for  
           45 1 53 { Colors Rand 4.5 mul cvi get } for,
        Rot#2=-#1\space]%
        \end{pspicture}
    }
    \multido{\iA=0+10}{36}{\figure{\iA}{X}}
    \multido{\iA=0+10}{36}{\figure{\iA}{Y}}
    \multido{\iA=0+10}{36}{\figure{\iA}{Z}}
\end{document}

enter image description here

 0 1 8 {      from 0 to 8 with step 1 do
            put the loop variable on the stack
 Colors.    Load Color array 
 Rand       get a random number between 0 and 1
 4.5 mul    between 0 and 4.5
 cvi        between 0 and 4
 get        load color with random number
 } for.     end of for loop

Every square has a corresponding number 0 .. 53 which can be used for color setting: 0 (red) 1 (green) ... and so on. see pages 38 ff of the documentation.

The same for complete faces:

\documentclass[pstricks,border=10pt]{standalone}

\usepackage{pst-solides3d}
\begin{document}

\psset{viewpoint=120 50 30 rtp2xyz,Decran=50}
\pstVerb{/Colors [(red)(yellow)(orange)(green)(blue)] def }
\def\figure#1#2{%
  \begin{pspicture}(-3,-3)(3,3)
        \psSolid[a=8,object=cube,ngrid=3,%
        fcol= 
           0 1 8 { (red) } for  
           9 1 17 { (green) } for  
           18 1 26 { (blue) } for  
           27 1 35 { (orange) } for  
           36 1 44 { (yellow) } for  
           45 1 53 { (cyan) } for,
        Rot#2=-#1\space]%
        \end{pspicture}
    }
    \multido{\iA=0+10}{36}{\figure{\iA}{X}}
    \multido{\iA=0+10}{36}{\figure{\iA}{Y}}
    \multido{\iA=0+10}{36}{\figure{\iA}{Z}}
\end{document}

enter image description here

9
  • Please to answer the first question. Your code(PostScript language) is new with me...
    – user173875
    Feb 21, 2019 at 16:36
  • see edited answer ...
    – user2478
    Feb 21, 2019 at 16:45
  • Oh, you misunderstood me. I mean that you can rewrite my code as the smart way.( my figure only 6 colors). The second question is not important. :-) And of course thanks for your expansion..
    – user173875
    Feb 21, 2019 at 16:54
  • And I just check pages 38 of the documentation BUT there is no anything as you can see. :-)
    – user173875
    Feb 21, 2019 at 17:02
  • I see only 5 colors. pages 38ff show anything about colors.
    – user2478
    Feb 21, 2019 at 17:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy