int S=95,x=1,l=#0061BA,d=#00AE60,e=#C41E2A,s,k[]={76,82,88,85,68,89,66,70,90},q[]={},W=255,i=#FF5801,j=i/4,f[][]={{e,W,d},{e,j,d},{e,W,l},{e,j,l},{i,W,d},{i,j,d},{i,W,l},{i,j,l}},a,b,t,o,u[];void setup(){size(510,510,P3D);}void draw(){background(W);translate(W,W);rotateX(5.7);rotateY(5.5);if(s<1&&q.length>0){s=millis();x=q[0];l=q[1];d=q[2];q=subset(q,3);}e=millis()-s;o=s>0?W-e:0;if(o<0){if(l>1){s=(x&2)-1;c(0,s*=d);c(1,-s);}else{c(l,d);}s=0;}for(i=0;i<8;i++){pushMatrix();u=f[i];t=u[a=x/2&2];if((i/x&1)==l||l>1){if(o<0){u[a]=u[b=x>1?1:2];u[b]=t;}if(s>0)rotate((l<1||l>1&&x==2?-d:d)*PI/2*sq(sin(1.6*e/W)),x&1,x&2,x&4);}translate(i%2*S,(i/2&1)*S,(i>>2)*S);for(j=0;j<6;j++){fill((i>>(j/2+2)%3&1)!=j%2?u[t=j/2|0]:0);rect(0,0,-S,-S);translate(0,0,(j-7)%2*S);rotate(j%2*PI/2,-t,j%3,0);}popMatrix();}}void c(int s,int d){u=f[t=s*x];for(i=1;i<4;i++){j=(x/2&1)!=s^d<0?4-i:i;a=j/2|0;b=a^j%2;f[t]=f[t=s*x+a*(x>3?2:4)+b*x%2+b];}f[t]=u;}void keyPressed(){for(i=0;i<9;i++)if(k[i]==(key&S))q=concat(q,new int[]{1<<i/3,i%3,key>S?1:-1});}