Python NumPy, 165 bytes
def f(p):
s=r_[:4];y=x=len(p);o=pad([[s]],y)[...,y+1:-y]
for c in p:s=s[2*c];_,j,k,l=c;y+=j+k-3;x+=(k+l)%4-1;o[y,x]=s[argmin(s):][1:4]
return o
from numpy import*
Attempt This Online!
Takes a list of lists as input S=[2,3,1,0],N=[3,2,0,1],W=[2,0,3,1],E=[1,3,0,2]
and returns an NxNx3 array of RGB values.
How?
Represents cube orientations (and 90 degree rotations) as permutations of its four long diagonals.
Each diagonal connects two opposite corners of the cube:
3----------2
/|\ /|
/ | \ / |
0----------1 |
| | \ | |
| 1----\--|--0
| / \ | /
|/ \|/
2----------3
This wireframe shows the outline of a cube and one of the diagonals (diagonal 3). All eight corners are labelled by the diagonal (0,1,2,3) they belong to.
As the rotations we are interested in are fully characterised by the permutation they induce on the corners and as they preserve oppositeness of corners
it may look like a good idea to encode such rotations as permutations of the four diagonals. And it is.
Now, we can see that the (orthogonal) orientations of the cube map 1:1 to permutations of 0,1,2,3.
Let us against normal convention write permutation abcd
as
ba
cd
and think of corners of the bottom face like in the picture (in the picture a,b,c,d = 0,1,2,3)
Now for example rolling the cube repeatedly over the (bottom) back edge will map:
10 -> 32 -> 01 -> 23 -> 10
23 10 32 01 32
(Always the bottom face is shown.)
For the (bottom) right edge it would be
10 -> 02 -> 23 -> 31 -> 10
23 31 10 02 23
Note that every orientation maps to a unique permutation and, conversely, each permutation actually represents an orientation (not in the examples but over all possible orientations)
Further note that by singling out a "null" orientation O_n 0123
each orientation o doubles as a rotation r, viz. the r that takes O_n to o. Also, te effect of two consecutive rotations is the product of the corresponding permutations.
Finally, note the identity of the bottom face and therefore the colour applied is easily read off the permutation representation of the orientation: the total of 24 orientations / permutations splits into six groups of four which differ by quarter turns:
10 ~~ 03 ~~ 32 ~~ 21
23 12 01 30
In practical terms, we can given an orientation; find the position of zero and then read ccw. This yields one of the six permutations of 1,2,3; a different one depending on which of the six faces of the cube is facing down.