mate2code

Tesseract squares

Mar 11th, 2019
667
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;_faces
  3. // like
  4. // https://commons.wikimedia.org/wiki/File:Tesseract_square_14.png
  5.  
  6. // console command:
  7. // for i in `seq 0 23`; do povray tesseract_squares.pov +ua +fn +H4000 +W3800 -D -k$i -Osquare_$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 VerticesBySquare = 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} }
  65.  
  66. #declare EdgesBySquare = array[24]{ array[4]{0, 1, 2, 3}, array[4]{0, 4, 5, 6}, array[4]{1, 4, 7, 8}, array[4]{2, 5, 9, 10}, array[4]{3, 7, 9, 11}, array[4]{6, 8, 10, 11}, array[4]{0, 12, 13, 14}, array[4]{1, 12, 15, 16}, array[4]{2, 13, 17, 18}, array[4]{3, 15, 17, 19}, array[4]{14, 16, 18, 19}, array[4]{4, 12, 20, 21}, array[4]{5, 13, 22, 23}, array[4]{6, 20, 22, 24}, array[4]{14, 21, 23, 24}, array[4]{7, 15, 25, 26}, array[4]{8, 20, 25, 27}, array[4]{16, 21, 26, 27}, array[4]{9, 17, 28, 29}, array[4]{10, 22, 28, 30}, array[4]{18, 23, 29, 30}, array[4]{11, 25, 28, 31}, array[4]{19, 26, 29, 31}, array[4]{24, 27, 30, 31} }
  67.  
  68. #declare SquareIndex = clock;  // number between 0 and 23 for one of the 24 square faces
  69. #declare VerticesForSquare = VerticesBySquare[SquareIndex];
  70. #declare EdgesForSquare = EdgesBySquare[SquareIndex];
  71.  
  72. ////////////////////////////////////////////////////////////////////////
  73.  
  74. union{
  75.  
  76.     // ALL VERTICES AND EDGES (LIGHT)
  77.     merge {
  78.  
  79.         // ALL VERTICES
  80.         union{
  81.             #for( Index, 0, 15 )
  82.                 #if(Index<8)   #local R = RadVert;   #else   #local R = RadVert*RadScale;   #end
  83.                 sphere{
  84.                     P[Index], R
  85.                     #if(VertexRankParities[Index])
  86.                         pigment{color rgbt<1, 0.8, 0.65, Transparency/.2> * .2}
  87.                     #else
  88.                         pigment{color rgbt<1, 0.8, 0.65, Transparency/.5> * .5}
  89.                     #end
  90.                 }
  91.             #end
  92.         }
  93.  
  94.         // ALL EDGES
  95.         union{
  96.             #for( Index, 0, 31 )
  97.                 #local EdgeArray = Edges[Index];
  98.                 #local A = EdgeArray[0];
  99.                 #local B = EdgeArray[1];
  100.                 #if(A<8)   #local RadA = RadEdge;   #else   #local RadA = RadEdge*RadScale;   #end
  101.                 #if(B<8)   #local RadB = RadEdge;   #else   #local RadB = RadEdge*RadScale;   #end
  102.                 cone{ P[A], RadA, P[B], RadB }
  103.             #end
  104.             pigment{color rgbt <.5, .5, .5, Transparency>}
  105.         }
  106.  
  107.     }
  108.  
  109.     // SQUARE VERTICES
  110.     union{
  111.         #for( Index, 0, 3 )
  112.             #local IndexInThisSquare = VerticesForSquare[Index];
  113.             #if(IndexInThisSquare<8)   #local R = RadVert+.0001;   #else   #local R = RadVert*RadScale+.0001;   #end
  114.             sphere{
  115.                 P[IndexInThisSquare], R+.0001
  116.                 #if(VertexRankParities[IndexInThisSquare])
  117.                     pigment{color rgb<1, 0.8, 0.65> * .2}
  118.                 #else
  119.                     pigment{color rgb<1, 0.8, 0.65> * .5}
  120.                 #end
  121.             }
  122.         #end
  123.     }
  124.  
  125.     // SQUARE EDGES
  126.     union{
  127.         #for( Index, 0, 3 )
  128.             #local EdgeArray = Edges[EdgesForSquare[Index]];
  129.             #local A = EdgeArray[0];
  130.             #local B = EdgeArray[1];
  131.             #if(A<8)   #local RadA = RadEdge+.0001;   #else   #local RadA = RadEdge*RadScale+.0001;   #end
  132.             #if(B<8)   #local RadB = RadEdge+.0001;   #else   #local RadB = RadEdge*RadScale+.0001;   #end
  133.             cone{ P[A], RadA, P[B], RadB }
  134.         #end
  135.         pigment{color rgb .5}
  136.     }
  137.  
  138.     // SQUARE FACE
  139.     #local FaceArray = Faces[SquareIndex];
  140.     polygon{
  141.         5, P[FaceArray[0]], P[FaceArray[1]], P[FaceArray[3]], P[FaceArray[2]], P[FaceArray[0]]
  142.         pigment{color rgbt<0, 0, 1, .8>}
  143.     }
  144.  
  145.     // VERTEX LABELS
  146.     #for( Index, 0, 15 )
  147.         text { ttf "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf",  str(Index,2,0),  .03,  0
  148.  
  149.             #if(Index<8)   scale .11   #else   scale .085   #end    // labels for the inner cube are smaller
  150.  
  151.             translate P[Index]   // move label from center to vertex
  152.  
  153.             #if(Index<8)  // OUTSIDE
  154.  
  155.                 #if(mod(div(Index,4),2))  // RIGHT
  156.                     translate .1*x
  157.                 #else                     // LEFT
  158.                     translate -.1*x
  159.                 #end
  160.  
  161.                 #if(mod(Index, 2))  // TOP
  162.                     translate .068*y
  163.                 #else               // BOTTOM
  164.                     translate -.068*y
  165.                 #end
  166.  
  167.                 translate <-.063, -.035, 0>
  168.  
  169.             #else         // INSIDE
  170.  
  171.                 #if(mod(div(Index,4),2))  // RIGHT
  172.                     translate -.08*x
  173.                 #else                     // LEFT
  174.                     translate .08*x
  175.                 #end
  176.  
  177.                 #if(mod(Index, 2))  // TOP
  178.                     translate -.062*y
  179.                 #else               // BOTTOM
  180.                     translate .062*y
  181.                 #end
  182.  
  183.                 translate <-.05, -.032, 0>
  184.  
  185.             #end
  186.  
  187.             #if(!is_in(Index, VerticesForSquare))
  188.                 pigment{ color rgbt .7 }
  189.             #end
  190.  
  191.         }
  192.     #end
  193.  
  194.     scale 2.25
  195.  
  196. }
RAW Paste Data