| 1 |
function SetUpServer() { |
| 2 |
TopHeader = "<HTML><title>Walk through a maze</title>" |
| 3 |
TopDoc = "\ |
| 4 |
<h2>Please choose one of the following actions:</h2>\ |
| 5 |
<UL>\ |
| 6 |
<LI><A HREF=" MyPrefix "/AboutServer>About this server</A>\ |
| 7 |
<LI><A HREF=" MyPrefix "/VRMLtest>Watch a simple VRML scene</A>\ |
| 8 |
</UL>" |
| 9 |
TopFooter = "</HTML>" |
| 10 |
srand() |
| 11 |
} |
| 12 |
function HandleGET() { |
| 13 |
if (MENU[2] == "AboutServer") { |
| 14 |
Document = "If your browser has a VRML 2 plugin,\ |
| 15 |
this server shows you a simple VRML scene." |
| 16 |
} else if (MENU[2] == "VRMLtest") { |
| 17 |
XSIZE = YSIZE = 11 # initially, everything is wall |
| 18 |
for (y = 0; y < YSIZE; y++) |
| 19 |
for (x = 0; x < XSIZE; x++) |
| 20 |
Maze[x, y] = "#" |
| 21 |
delete Maze[0, 1] # entry is not wall |
| 22 |
delete Maze[XSIZE-1, YSIZE-2] # exit is not wall |
| 23 |
MakeMaze(1, 1) |
| 24 |
Document = "\ |
| 25 |
#VRML V2.0 utf8\n\ |
| 26 |
Group {\n\ |
| 27 |
children [\n\ |
| 28 |
PointLight {\n\ |
| 29 |
ambientIntensity 0.2\n\ |
| 30 |
color 0.7 0.7 0.7\n\ |
| 31 |
location 0.0 8.0 10.0\n\ |
| 32 |
}\n\ |
| 33 |
DEF B1 Background {\n\ |
| 34 |
skyColor [0 0 0, 1.0 1.0 1.0 ]\n\ |
| 35 |
skyAngle 1.6\n\ |
| 36 |
groundColor [1 1 1, 0.8 0.8 0.8, 0.2 0.2 0.2 ]\n\ |
| 37 |
groundAngle [ 1.2 1.57 ]\n\ |
| 38 |
}\n\ |
| 39 |
DEF Wall Shape {\n\ |
| 40 |
geometry Box {size 1 1 1}\n\ |
| 41 |
appearance Appearance { material Material { diffuseColor 0 0 1 } }\n\ |
| 42 |
}\n\ |
| 43 |
DEF Entry Viewpoint {\n\ |
| 44 |
position 0.5 1.0 5.0\n\ |
| 45 |
orientation 0.0 0.0 -1.0 0.52\n\ |
| 46 |
}\n" |
| 47 |
for (i in Maze) { |
| 48 |
split(i, t, SUBSEP) |
| 49 |
Document = Document " Transform { translation " |
| 50 |
Document = Document t[1] " 0 -" t[2] " children USE Wall }\n" |
| 51 |
} |
| 52 |
Document = Document " ] # end of group for world\n}" |
| 53 |
Reason = "OK" ORS "Content-type: model/vrml" |
| 54 |
Header = Footer = "" |
| 55 |
} |
| 56 |
} |
| 57 |
function MakeMaze(x, y) { |
| 58 |
delete Maze[x, y] # here we are, we have no wall here |
| 59 |
p = 0 # count unvisited fields in all directions |
| 60 |
if (x-2 SUBSEP y in Maze) d[p++] = "-x" |
| 61 |
if (x SUBSEP y-2 in Maze) d[p++] = "-y" |
| 62 |
if (x+2 SUBSEP y in Maze) d[p++] = "+x" |
| 63 |
if (x SUBSEP y+2 in Maze) d[p++] = "+y" |
| 64 |
if (p>0) { # if there are unvisited fields, go there |
| 65 |
p = int(p*rand()) # choose one unvisited field at random |
| 66 |
if (d[p] == "-x") { delete Maze[x - 1, y]; MakeMaze(x - 2, y) |
| 67 |
} else if (d[p] == "-y") { delete Maze[x, y - 1]; MakeMaze(x, y - 2) |
| 68 |
} else if (d[p] == "+x") { delete Maze[x + 1, y]; MakeMaze(x + 2, y) |
| 69 |
} else if (d[p] == "+y") { delete Maze[x, y + 1]; MakeMaze(x, y + 2) |
| 70 |
} # we are back from recursion |
| 71 |
MakeMaze(x, y); # try again while there are unvisited fields |
| 72 |
} |
| 73 |
} |