mate2code

Tesseract with Gray code path

Apr 20th, 2019
702
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // https://commons.wikimedia.org/wiki/File:Tesseract_Schlegel_Gray.png
  2. // height/width=20/19, e.g. +H4000 +W3800
  3.  
  4. #version 3.6;
  5. global_settings { assumed_gamma 1.0 }
  6. #default{ finish{ ambient 0.1 diffuse 0.9 conserve_energy}}
  7.  
  8. #include "colors.inc"
  9.  
  10. ////////////////////////////////////////////////////////////////////////
  11.  
  12. #declare Camera_Position = <4, 7, -30>;
  13. camera{
  14.     location Camera_Position
  15.     right    x*image_width/image_height
  16.     angle    11
  17.     look_at  <-.15, -.2, 0>
  18. }
  19.  
  20.  
  21. light_source{ <-400, 500, -300> color White*0.9 shadowless}
  22. light_source{ <400, 200, 100> color White*0.4 shadowless}
  23. light_source{ Camera_Position  color rgb<0.9,0.9,1>*0.2 shadowless}
  24. sky_sphere{ pigment{ White } }
  25.  
  26.  
  27. ////////////////////////////////////////////////////////////////////////
  28.  
  29. #macro is_in(Element, Array)
  30.     #local Found = false;
  31.     #for(Index, 0, dimension_size(Array,1)-1)
  32.         #if(Array[Index] = Element)
  33.             #local Found = true;
  34.         #end
  35.     #end
  36.     Found
  37. #end
  38.  
  39. ////////////////////////////////////////////////////////////////////////
  40.  
  41. #declare RadEdge = .01;
  42. #declare RadVert = .05;
  43. #declare RadScale = .6;
  44.  
  45. #declare VertexRankParities = array[16]{ 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0 }
  46.  
  47. #declare Scale = .47;
  48. #declare P = array[16]{
  49.     <-1,-1,-1>, <-1,1,-1>, <-1,-1,1>, <-1,1,1>, <1,-1,-1>, <1,1,-1>, <1,-1,1>, <1,1,1>,
  50.     <-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
  51. };
  52.  
  53. #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} };
  54.  
  55. #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} };
  56.  
  57. #declare RedEdges = array[14]{0, 2, 3, 7, 11, 10, 6, 24, 30, 31, 26, 19, 18, 14};
  58. #declare OrangeEdges = array[2]{20, 12};
  59.  
  60. ////////////////////////////////////////////////////////////////////////
  61.  
  62. union{
  63.  
  64.     // VERTICES
  65.     union{
  66.         #for( Index, 0, 15 )
  67.             #if(Index<8)   #local R = RadVert;   #else   #local R = RadVert*RadScale;   #end
  68.             sphere{
  69.                 P[Index], R
  70.                 #if(VertexRankParities[Index])
  71.                     pigment{color rgb<1,0.8,0.65>*.2}
  72.                 #else
  73.                     pigment{color rgb<1,0.8,0.65>*.5}
  74.                 #end
  75.             }
  76.         #end
  77.     }
  78.  
  79.     // EDGES
  80.     #for( Index, 0, 31 )
  81.         #local EdgeArray = Edges[Index];
  82.         #local A = EdgeArray[0];
  83.         #local B = EdgeArray[1];
  84.         #if(A<8)   #local RadA = RadEdge;   #else   #local RadA = RadEdge*RadScale;   #end
  85.         #if(B<8)   #local RadB = RadEdge;   #else   #local RadB = RadEdge*RadScale;   #end
  86.         cone{ P[A], RadA, P[B], RadB
  87.             #if(is_in(Index, RedEdges))
  88.                 pigment{color Red}
  89.             #end
  90.             #if(is_in(Index, OrangeEdges))
  91.                 pigment{color srgb<1,.55,0>}
  92.             #end
  93.             #if(!is_in(Index, RedEdges) & !is_in(Index, OrangeEdges))
  94.                 pigment{color rgb .5}
  95.             #end
  96.         }
  97.     #end
  98.  
  99.     // FACES
  100.     union{
  101.         #for( Index, 0, 23 )
  102.             #local FaceArray = Faces[Index];
  103.             polygon{ 5, P[FaceArray[0]], P[FaceArray[1]], P[FaceArray[3]], P[FaceArray[2]], P[FaceArray[0]] }
  104.         #end
  105.         pigment{color rgbt<0, 0, 1, .8>}
  106.     }
  107.  
  108.     // VERTEX LABELS
  109.     #for( Index, 0, 15 )
  110.         text { ttf "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf",  str(Index,2,0),  .03,  0
  111.  
  112.             #if(Index<8)   scale .11   #else   scale .085   #end    // labels for the inner cube are smaller
  113.  
  114.             translate P[Index]   // move label from center to vertex
  115.  
  116.             #if(Index<8)  // OUTSIDE
  117.  
  118.                 #if(mod(div(Index,4),2))  // RIGHT
  119.                     translate .1*x
  120.                 #else                     // LEFT
  121.                     translate -.1*x
  122.                 #end
  123.  
  124.                 #if(mod(Index, 2))  // TOP
  125.                     translate .068*y
  126.                 #else               // BOTTOM
  127.                     translate -.068*y
  128.                 #end
  129.  
  130.                 translate <-.063, -.035, 0>
  131.  
  132.             #else         // INSIDE
  133.  
  134.                 #if(mod(div(Index,4),2))  // RIGHT
  135.                     translate -.08*x
  136.                 #else                     // LEFT
  137.                     translate .08*x
  138.                 #end
  139.  
  140.                 #if(mod(Index, 2))  // TOP
  141.                     translate -.062*y
  142.                 #else               // BOTTOM
  143.                     translate .062*y
  144.                 #end
  145.  
  146.                 translate <-.05, -.032, 0>
  147.  
  148.             #end
  149.  
  150.         }
  151.     #end
  152.  
  153.     scale 2.25
  154.  
  155. }
RAW Paste Data