camera{ up y right x location <0,1,-2> look_at <0,0,0> }
light_source { <0,100,-100> colour rgb <1,1,1> }
#background { rgb <1,1,1> }

#macro r(c) 
  pigment { rgb c } 
  finish { phong 1.0 ambient 0.5 diffuse 0.5 }
#end

#declare n=30;

#macro colorsquare(P,Q,R,S)
  #declare i=0; 
  #while (i<n)
    #declare j=0; 
    #while (j<n)
      #declare A=P+i*(Q-P)/n+j*(S-P)/n; 
      #declare B=P+(i+1)*(Q-P)/n+j*(S-P)/n; 
      #declare C=P+(i+1)*(Q-P)/n+(j+1)*(S-P)/n; 
      #declare D=P+i*(Q-P)/n+(j+1)*(S-P)/n; 
      polygon {5,A,B,C,D,A r(A) }
      #declare j=j+1; 
    #end
    #declare i=i+1;
  #end 
#end

#declare colorcube=union {
  #colorsquare(<0,0,0>,<1,0,0>,<1,1,0>,<0,1,0>)
  #colorsquare(<0,0,1>,<1,0,1>,<1,1,1>,<0,1,1>)
  #colorsquare(<0,0,0>,<0,0,1>,<1,0,1>,<1,0,0>)
  #colorsquare(<0,1,0>,<0,1,1>,<1,1,1>,<1,1,0>)
  #colorsquare(<0,0,0>,<0,1,0>,<0,1,1>,<0,0,1>)
  #colorsquare(<1,0,0>,<1,1,0>,<1,1,1>,<1,0,1>)
}

object{ colorcube translate <-1/2,-1/2,-1/2> rotate <-20,20,10> rotate z*clock*270 }

