#!/usr/local/bin/perl # add a new randomly translated text node # limit number to N messages (count messages) # # Uses Steven E. Brenner's "cgi-lib.pl" # available from http://cgi-lib.stanford.edu/cgi-lib/ # require("cgi-lib.pl"); # use the library &ReadParse; # parse the form's fields into "in" array # collect the form data into easy to use variable names $message = $in{'message'}; # read in the old wrl open(WRL, "graf.wrl"); @lines = ; close(WRL); # reopen file to write out the new version open(WRL, ">graf.wrl"); $numMessages = 0; foreach $line (@lines) { # look at line # if it is place for new message, write out the new message, # and a new place marker if($line =~ /NEXT MESSAGE GOES HERE/) { $x = (int((rand(10)-5)*10)/10); $y = (int((rand(10)-5)*10)/10); $z = (int((rand(10)-5)*10)/10); $t = $x." ".$y." ".$z; $rx = (int(rand()*100)/100); $ry = (int(rand()*100)/100); $rz = (int(rand()*100)/100); $a = (int(rand(6.28)*10)/10); $r = $rx." ".$ry." ".$rz." ".$a; print WRL "\# NEXT MESSAGE GOES HERE\n"; print WRL "Message { t $t r $r string \"$message\" }\n\n"; } # otherwise just reprint the line else { # if it's a message line, only print a limited number if($line =~ /^Message/) { $numMessages += 1; if($numMessages < 20) { print WRL $line; } } # print all other lines else { print WRL $line; } } } close(WRL); # reopen and reread the new file open(WRL, "graf.wrl"); @lines = ; close(WRL); # send the file type to the browser print "Content-type: model/vrml\n\n"; # note! must have both \n # send the new file foreach $line (@lines) { print $line; }