// Persistence of Vision Ray Tracer version 3.5 Include File // File: puzzle10.inc // Author: JWV // Last updated: 2004.8.21 // Description: This file creates a (CSG) jigsaw puzzle #ifndef(PUZZLE_INC_TEMP) #declare PUZZLE_INC_TEMP = version; #version 3.5; #ifdef(View_POV_Include_Stack) #debug "including puzzle10.inc\n" #end #include "colors.inc" #include "rand.inc" //setting parameters #declare Variation=0.0; #declare fast=off; #declare party=off; #declare textu=off; #declare texturand=off; #declare TP=texture{pigment{Green}}; //setting parameters #macro make_puzzle(Rows,Cols,R,D) #declare S=seed(0); #declare Base=union{ #if(fast) box{0,1 scale D*y} #else box{, <1-R,D-R,1>} box{<0,0,R>, <1,D-R,1-R>} cylinder{,,R} cylinder{<1-R,0,R>,<1-R,D-R,R>,R} cylinder{<1-R,0,1-R>,<1-R,D-R,1-R>,R} cylinder{,,R} box{, <1-R,D,1-R>} sphere{,R} sphere{<1-R,D-R,R>,R} sphere{<1-R,D-R,1-R>,R} sphere{,R} cylinder{,,R} cylinder{,<1-R,D-R,1-R>,R} cylinder{<1-R,D-R,1-R>,<1-R,D-R,R>,R} cylinder{<1-R,D-R,R>,,R} #end } //END OF BASE #declare LOB=#union{ #if (fast) cylinder{<0,0,0.2>,<0,D,0.2>,0.15} box{<-0.1,0,-0.05>, <0.1,D,0.2>}#else cylinder{<0,0,0.2>,<0,D-R,0.2>,0.15} torus{0.15-R,R translate <0,D-R,0.2>} cylinder{<0,0,0.2>,<0,D,0.2>,0.15-R} box{<-0.1,0,-0.05>, <0.1,D-R,0.2>} box{<-0.1+R,0,-0.05>, <0.1-R,D,0.2>} cylinder{<-0.1+R,D-R,-0.05><-0.1+R,D-R,0.2>,R} cylinder{<0.1-R,D-R,-0.05><0.1-R,D-R,0.2>,R} #end }//end of LOB #declare LOB_=#union{//cutting lob #if(fast) cylinder{<0,-0.01,0.2>,<0,D+.01,0.2>,0.15} box{<-0.1,-0.01,-0.05>, <0.1,D+.01,0.2>}#else cylinder{<0,-0.01,0.2>,<0,D+.01,0.2>,0.15} box{<-0.1,-0.01,-0.05>, <0.1,D+.01,0.2>} #difference{ cylinder{<0,-0.01,0.2>,<0,D+.01,0.2>,0.15+R} torus{0.15+R,R translate <0,0,0.2>} translate (D-R)*y} #end } //end og LOB_ //START OF LOB2-------------------------------------------------------------------------------- #declare LOB2=#union{ #if (fast) cylinder{<0,0,0>,<0,D,0>,0.15} #else cylinder{<0,0,0>,<0,D-R,0>,0.15} torus{0.15-R,R translate <0,D-R,0>} cylinder{<0,0,0>,<0,D,0>,0.15-R} #end }//end of LOB #declare LOB2_=#union{//cutting lob #if(fast) cylinder{<0,-0.01,0>,<0,D+.01,0>,0.15} #else cylinder{<0,-0.01,0>,<0,D+.01,0>,0.15} #difference{ cylinder{<0,-0.01,0>,<0,D+.01,0>,0.15+R} torus{0.15+R,R translate <0,0,0>} translate (D-R)*y} #end } //end og LOB_ //END OF LOB2-------------------------------------------------------------------------------- #declare lobsH=array[Rows][Cols]; #declare lobsV=array[Rows][Cols]; #local i=0; #while (i; #declare lobsV[i][j]=<0,0>; #local j=j+1; #end #local i=i+1; #end #declare pieces=array[Rows][Cols]; #local i=0; #while (iVariation) #declare L=1;#else #declare L=0;#end #if(R>0.5) #declare lobsV[i][j]=<1,L>; #else #declare lobsV[i][j]=<-1,L>; #end #local j=j+1; #end #local i=i+1; #end #local i=0; #while (iVariation) #declare L=1;#else #declare L=0;#end #if(R>0.5) #declare lobsH[i][j]=<1,L>; #else #declare lobsH[i][j]=<-1,L>; #end #local j=j+1; #end #local i=i+1; #end //START PART 1--------------------------------------------------------------------------------------- #local i=0; #while (i translate<1,0,0.5>}#else object{LOB2_ rotate -90*y scale <1,1,-1> translate<1,0,0.5>}#end #end #if(lobsH[i][j].u=1) #if(lobsH[i][j].v=1) object{LOB_ scale <1,1,-1> translate<0.5,0,1>}#else object{LOB2_ scale <1,1,-1> translate<0.5,0,1>}#end #end } //end of difference #if(lobsH[i][j].u=-1) #if(lobsH[i][j].v=1) object{LOB scale <1,1,1> translate<0.5,0,1>}#else object{LOB2 scale <1,1,1> translate<0.5,0,1>}#end #end #if(lobsV[i][j].u=-1) #if(lobsV[i][j].v=1) object{LOB rotate -90*y scale <-1,1,1> translate<1,0,.5>}#else object{LOB2 rotate -90*y scale <-1,1,1> translate<1,0,.5>}#end #end }//end of union } #local j=j+1; #end #local i=i+1; #end //END PART 1--------------------------------------------------------------------------------------- //START PART 2.1--------------------------------------------------------------------------------------- #local i=0; #while (i translate<0.5,0,0>}#else object{LOB2_ scale <1,1,1> translate<0.5,0,0>}#end #end } #if(lobsH[i][j-1].u=1) #if(lobsH[i][j-1].v=1) object{LOB scale <1,1,-1> translate<0.5,0,0>}#else object{LOB2 scale <1,1,-1> translate<0.5,0,0>}#end #end } } #local j=j+1; #end #local i=i+1; #end //END PART 2.1--------------------------------------------------------------------------------------- //START PART 2.2--------------------------------------------------------------------------------------- #local i=1; #while (i translate<0,0,.5>}#else object{LOB2_ rotate -90*y scale <-1,1,1> translate<0,0,.5>}#end #end } #if(lobsV[i-1][j].u=1) #if(lobsV[i-1][j].v=1) object{LOB rotate -90*y scale <1,1,-1> translate<0,0,0.5>}#else object{LOB2 rotate -90*y scale <1,1,-1> translate<0,0,0.5>}#end #end } } #local j=j+1; #end #local i=i+1; #end //END PART 2.2--------------------------------------------------------------------------------------- //PLACING OF THE PIECES ----------------------------------------------------------------------------- #local i=0; #while (i} #end #if(textu) #declare Q=0; #if(texturand) #declare S=RRand(0,1,S); #declare Q=0; #if(S>0.5) #declare Q=90; #end #end texture{TP rotate Q} #end translate } #local j=j+1; #end #local i=i+1; #end //PLACING OF THE PIECES ----------------------------------------------------------------------------- #end //einde macro #version PUZZLE_INC_TEMP; #end//puzzle10.inc