Advertisement
mate2code

Tesseract cubes

Mar 11th, 2019
2,584
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // source of the 8 files in
  2. // https://commons.wikimedia.org/wiki/Category:Tesseract_Schlegel_shadow_with_alternating_vertex_colors;_cells
  3. // like
  4. // https://commons.wikimedia.org/wiki/File:Tesseract_cube_1.png
  5.  
  6. // console command:
  7. // for i in `seq 0 7`; do povray tesseract_cubes.pov +ua +fn +H4000 +W3800 -D -k$i -Ocube_$i; done
  8.  
  9. #version 3.6;
  10. global_settings { assumed_gamma 1.0 }
  11. #default{ finish{ ambient 0.1 diffuse 0.9 conserve_energy}}
  12.  
  13. #include "colors.inc"
  14.  
  15.  
  16. ////////////////////////////////////////////////////////////////////////
  17.  
  18. #declare Camera_Position = <4, 7, -30>;
  19. camera{
  20.     location Camera_Position
  21.     right    x*image_width/image_height
  22.     angle    11
  23.     look_at  <-.15, -.2, 0>
  24. }
  25.  
  26.  
  27. light_source{ <-400, 500, -300> color White*0.9 shadowless}
  28. light_source{ <400, 200, 100> color White*0.4 shadowless}
  29. light_source{ Camera_Position  color rgb<0.9,0.9,1>*0.2 shadowless}
  30. sky_sphere{ pigment{ White } }
  31.  
  32. ////////////////////////////////////////////////////////////////////////
  33.  
  34. #macro is_in(Element, Array)
  35.     #local Found = false;
  36.     #for(Index, 0, dimension_size(Array,1)-1)
  37.         #if(Array[Index] = Element)
  38.             #local Found = true;
  39.         #end
  40.     #end
  41.     Found
  42. #end
  43.  
  44. ////////////////////////////////////////////////////////////////////////
  45.  
  46. #declare RadEdge = .01;
  47. #declare RadVert = .05;
  48. #declare RadScale = .6;
  49.  
  50. #declare Transparency = .8;
  51.  
  52. #declare VertexRankParities = array[16]{ 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0 }
  53.  
  54. #declare Scale = .47;
  55. #declare P = array[16]{
  56.     <-1,-1,-1>, <-1,1,-1>, <-1,-1,1>, <-1,1,1>, <1,-1,-1>, <1,1,-1>, <1,-1,1>, <1,1,1>,
  57.     <-1,-1,-1>*Scale, <-1,1,-1>*Scale, <-1,-1,1>*Scale, <-1,1,1>*Scale, <1,-1,-1>*Scale, <1,1,-1>*Scale, <1,-1,1>*Scale, <1,1,1>*Scale
  58. };
  59.  
  60. #declare Edges = array[32]{ array[2]{0, 1}, array[2]{0, 2}, array[2]{1, 3}, array[2]{2, 3}, array[2]{0, 4}, array[2]{1, 5}, array[2]{4, 5}, array[2]{2, 6}, array[2]{4, 6}, array[2]{3, 7}, array[2]{5, 7}, array[2]{6, 7}, array[2]{0, 8}, array[2]{1, 9}, array[2]{8, 9}, array[2]{2, 10}, array[2]{8, 10}, array[2]{3, 11}, array[2]{9, 11}, array[2]{10, 11}, array[2]{4, 12}, array[2]{8, 12}, array[2]{5, 13}, array[2]{9, 13}, array[2]{12, 13}, array[2]{6, 14}, array[2]{10, 14}, array[2]{12, 14}, array[2]{7, 15}, array[2]{11, 15}, array[2]{13, 15}, array[2]{14, 15} };
  61.  
  62. #declare Faces = array[24]{ array[4]{0, 1, 2, 3}, array[4]{0, 1, 4, 5}, array[4]{0, 2, 4, 6}, array[4]{1, 3, 5, 7}, array[4]{2, 3, 6, 7}, array[4]{4, 5, 6, 7}, array[4]{0, 1, 8, 9}, array[4]{0, 2, 8, 10}, array[4]{1, 3, 9, 11}, array[4]{2, 3, 10, 11}, array[4]{8, 9, 10, 11}, array[4]{0, 4, 8, 12}, array[4]{1, 5, 9, 13}, array[4]{4, 5, 12, 13}, array[4]{8, 9, 12, 13}, array[4]{2, 6, 10, 14}, array[4]{4, 6, 12, 14}, array[4]{8, 10, 12, 14}, array[4]{3, 7, 11, 15}, array[4]{5, 7, 13, 15}, array[4]{9, 11, 13, 15}, array[4]{6, 7, 14, 15}, array[4]{10, 11, 14, 15}, array[4]{12, 13, 14, 15} };
  63.  
  64. #declare VerticesByCube = array[8]{ array[8]{0, 1, 2, 3, 4, 5, 6, 7}, array[8]{0, 1, 2, 3, 8, 9, 10, 11}, array[8]{0, 1, 4, 5, 8, 9, 12, 13}, array[8]{0, 2, 4, 6, 8, 10, 12, 14}, array[8]{1, 3, 5, 7, 9, 11, 13, 15}, array[8]{2, 3, 6, 7, 10, 11, 14, 15}, array[8]{4, 5, 6, 7, 12, 13, 14, 15}, array[8]{8, 9, 10, 11, 12, 13, 14, 15} }
  65.  
  66. #declare EdgesByCube = array[8]{ array[12]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, array[12]{0, 1, 2, 3, 12, 13, 14, 15, 16, 17, 18, 19}, array[12]{0, 4, 5, 6, 12, 13, 14, 20, 21, 22, 23, 24}, array[12]{1, 4, 7, 8, 12, 15, 16, 20, 21, 25, 26, 27}, array[12]{2, 5, 9, 10, 13, 17, 18, 22, 23, 28, 29, 30}, array[12]{3, 7, 9, 11, 15, 17, 19, 25, 26, 28, 29, 31}, array[12]{6, 8, 10, 11, 20, 22, 24, 25, 27, 28, 30, 31}, array[12]{14, 16, 18, 19, 21, 23, 24, 26, 27, 29, 30, 31} }
  67.  
  68. #declare FacesByCube = array[8]{ array[6]{0, 1, 2, 3, 4, 5}, array[6]{0, 6, 7, 8, 9, 10}, array[6]{1, 6, 11, 12, 13, 14}, array[6]{2, 7, 11, 15, 16, 17}, array[6]{3, 8, 12, 18, 19, 20}, array[6]{4, 9, 15, 18, 21, 22}, array[6]{5, 13, 16, 19, 21, 23}, array[6]{10, 14, 17, 20, 22, 23} }
  69.  
  70. #declare CubeIndex = clock;  // number between 0 and 7 one of the 8 cubic cells
  71. #declare VerticesForCube = VerticesByCube[CubeIndex];
  72. #declare EdgesForCube = EdgesByCube[CubeIndex];
  73. #declare FacesForCube = FacesByCube[CubeIndex];
  74.  
  75. ////////////////////////////////////////////////////////////////////////
  76.  
  77. union{
  78.  
  79.     // ALL VERTICES AND EDGES (LIGHT)
  80.     merge {
  81.  
  82.         // ALL VERTICES
  83.         union{
  84.             #for( Index, 0, 15 )
  85.                 #if(Index<8)   #local R = RadVert;   #else   #local R = RadVert*RadScale;   #end
  86.                 sphere{
  87.                     P[Index], R
  88.                     #if(VertexRankParities[Index])
  89.                         pigment{color rgbt<1, 0.8, 0.65, Transparency/.2> * .2}
  90.                     #else
  91.                         pigment{color rgbt<1, 0.8, 0.65, Transparency/.5> * .5}
  92.                     #end
  93.                 }
  94.             #end
  95.         }
  96.  
  97.         // ALL EDGES
  98.         union{
  99.             #for( Index, 0, 31 )
  100.                 #local EdgeArray = Edges[Index];
  101.                 #local A = EdgeArray[0];
  102.                 #local B = EdgeArray[1];
  103.                 #if(A<8)   #local RadA = RadEdge;   #else   #local RadA = RadEdge*RadScale;   #end
  104.                 #if(B<8)   #local RadB = RadEdge;   #else   #local RadB = RadEdge*RadScale;   #end
  105.                 cone{ P[A], RadA, P[B], RadB }
  106.             #end
  107.             pigment{color rgbt <.5, .5, .5, Transparency>}
  108.         }
  109.  
  110.     }
  111.  
  112.     // CUBE VERTICES
  113.     union{
  114.         #for( Index, 0, 7 )
  115.             #local IndexInThisCube = VerticesForCube[Index];
  116.             #if(IndexInThisCube<8)   #local R = RadVert+.0001;   #else   #local R = RadVert*RadScale+.0001;   #end
  117.             sphere{
  118.                 P[IndexInThisCube], R+.0001
  119.                 #if(VertexRankParities[IndexInThisCube])
  120.                     pigment{color rgb<1, 0.8, 0.65> * .2}
  121.                 #else
  122.                     pigment{color rgb<1, 0.8, 0.65> * .5}
  123.                 #end
  124.             }
  125.         #end
  126.     }
  127.  
  128.     // CUBE EDGES
  129.     union{
  130.         #for( Index, 0, 11 )
  131.             #local EdgeArray = Edges[EdgesForCube[Index]];
  132.             #local A = EdgeArray[0];
  133.             #local B = EdgeArray[1];
  134.             #if(A<8)   #local RadA = RadEdge+.0001;   #else   #local RadA = RadEdge*RadScale+.0001;   #end
  135.             #if(B<8)   #local RadB = RadEdge+.0001;   #else   #local RadB = RadEdge*RadScale+.0001;   #end
  136.             cone{ P[A], RadA, P[B], RadB }
  137.         #end
  138.         pigment{color rgb .5}
  139.     }
  140.  
  141.     // CUBE FACES
  142.     union{
  143.         #for( Index, 0, 5 )
  144.             #local FaceArray = Faces[FacesForCube[Index]];
  145.             polygon{ 5, P[FaceArray[0]], P[FaceArray[1]], P[FaceArray[3]], P[FaceArray[2]], P[FaceArray[0]] }
  146.         #end
  147.         pigment{color rgbt<0, 0, 1, .8>}
  148.     }
  149.  
  150.     // VERTEX LABELS
  151.     #for( Index, 0, 15 )
  152.         text { ttf "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf",  str(Index,2,0),  .03,  0
  153.  
  154.             #if(Index<8)   scale .11   #else   scale .085   #end    // labels for the inner cube are smaller
  155.  
  156.             translate P[Index]   // move label from center to vertex
  157.  
  158.             #if(Index<8)  // OUTSIDE
  159.  
  160.                 #if(mod(div(Index,4),2))  // RIGHT
  161.                     translate .1*x
  162.                 #else                     // LEFT
  163.                     translate -.1*x
  164.                 #end
  165.  
  166.                 #if(mod(Index, 2))  // TOP
  167.                     translate .068*y
  168.                 #else               // BOTTOM
  169.                     translate -.068*y
  170.                 #end
  171.  
  172.                 translate <-.063, -.035, 0>
  173.  
  174.             #else         // INSIDE
  175.  
  176.                 #if(mod(div(Index,4),2))  // RIGHT
  177.                     translate -.08*x
  178.                 #else                     // LEFT
  179.                     translate .08*x
  180.                 #end
  181.  
  182.                 #if(mod(Index, 2))  // TOP
  183.                     translate -.062*y
  184.                 #else               // BOTTOM
  185.                     translate .062*y
  186.                 #end
  187.  
  188.                 translate <-.05, -.032, 0>
  189.  
  190.             #end
  191.  
  192.             #if(!is_in(Index, VerticesForCube))
  193.                 pigment{ color rgbt .7 }
  194.             #end
  195.  
  196.         }
  197.     #end
  198.  
  199.     scale 2.25
  200.  
  201. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement