// LABY.POV by David GEMELLI 16/10/98 // mail: gemelli@imerir.asso.fr // A recursive try to find the exit of a maze with POVRAY 3.1 // The display is the labyrinthe with different information: // -in grey, walls // -in blue, the corridors that have not been visited // -in red, the corridors that have been visited // -in yellow, the solution of the maze // -two arrows to indicate the entrance and the exit // I tried to comment as clearly as possible but my english may have some // mistakes. // Read the LABY.INC to have some other details. // Modify as you want (send me a version so I can learn new things) #include "colors.inc" #if (file_exists("maze.inc")) #include "maze.inc" #else #error "FICHIER MAZE.INC ABSENT" #end #declare CAMFACTOR = max(NbColonnes,NbLignes)/7; camera { location look_at <0,0,0> rotate <0,clock*360,0> translate <(NbColonnes/2)-.5,0,(NbLignes/2)-.5> } light_source {<160,320,40> color White rotate <0,clock*360,0>} // a wall #declare Mur = box {<-0.5,0,-0.5> <0.5,0.7,0.5> texture { pigment{granite color_map{[0.0 Black][1.0 White]} scale 0.24} finish {ambient 0.2}}} // the basic corridor #declare Sol = box {<-0.5,0,-0.5> <0.5,0.1,0.5> texture {pigment {color Blue} finish {ambient 0.2}}} // to know where the maze has been visited #declare Traverse = box {<-0.5,0,-0.5> <0.5,0.1,0.5> texture {pigment {color Red} finish {ambient 0.2}}} // the exit way #declare Chemin = box {<-0.5,0,-0.5> <0.5,0.1,0.5> texture {pigment {color Yellow} finish {ambient 0.2}}} #declare Fleche = union { difference { box {<0,0,0> <3,3,1> translate <-1.5,-2,-.5>} box {<-2,0,-.6> <0,4,.6> rotate<0,0,-20> translate<-1.5,-2,0>} box {<0,0,-.6> <2,4,.6> rotate<0,0,20> translate<1.5,-2,0>} } difference { box {<0,0,0> <3,2,1> translate <-1.5,1,-.5>} box {<-2,0,-.6> <0,3,.6> rotate<0,0,-45> translate<-1.5,1,0>} box {<0,0,-.6> <2,3,.6> rotate<0,0,45> translate<1.5,1,0>} } translate <0,-.5,0> scale <.4,.6,.2> rotate <0,90,0> } // the recursive macro // px,py: position // lab: the labyrinth ! // r: the "returned" value to test if the exit was found // I don't know if the "#local" declarations are necessary where I used them #macro chercher (px,py,lab,r) #local r1 = 0; #local r2 = 0; #local r3 = 0; #local r4 = 0; // exit #if (lab[px][py] = 2) #declare r = 1; #end // (wall) or (been before) #if ((lab[px][py] = 1)|(lab[px][py] = 3)) #declare r = 0; #end // a corridor #if (lab[px][py] = 0) // to mark where we've been #declare lab[px][py] = 3; #local px2 = px + 1; #local px3 = px - 1; #local py2 = py + 1; #local py3 = py - 1; // the different calls // I used "&" operator instead of "#else"s to eliminate nested // conditions and allow more possible recursions. // try to the right chercher(px2,py,lab,r1) #if (!r1) // try to the left chercher(px3,py,lab,r2) #end #if ((!r1)&(!r2)) // try to the bottom chercher(px,py2,lab,r3) #end #if ((!r1)&(!r2)&(!r3)) // try to the top chercher(px,py3,lab,r4) #end // if exit was found #declare r = ((r1)|(r2)|(r3)|(r4)); #if (r = 1) // the exit way #declare lab[px][py] = 4; #end #end #end // go ! chercher(DebutY,DebutX,GrilleLaby,0) // the display part #declare Ligne = 0; #while (Ligne < NbLignes) #declare Colonne = 0; #while (Colonne < NbColonnes) // an arrow above the exit #if (GrilleLaby[Ligne][Colonne] = 2) object { Fleche texture {pigment{color Orange} finish{ambient 0.6}} translate } #end object { // a wall #if (GrilleLaby[Ligne][Colonne] = 1) Mur #else // the default corridor #if (GrilleLaby[Ligne][Colonne] = 0) Sol #else // the explored corridor #if (GrilleLaby[Ligne][Colonne] = 3) Traverse // the exit #else Chemin #end #end #end translate } #declare Colonne = Colonne + 1; #end #declare Ligne = Ligne + 1; #end // an arrow above the entrance object { Fleche texture {pigment{color Magenta} finish{ambient 0.2}} rotate <0,0,180> translate } // END