#!/usr/bin/perl

use CGI ':cgi-lib';
ReadParse(*input);

print "Content-type:text/html\n\n";

sub readDef{
    my($key,$def) = @_;
    if($input{$key} eq ""){
	return $def;
    } else {
	return $input{$key};
    }
}


$msg = readDef("msg","");
$worldsize = readDef("worldsize",40);
$historysize = readDef("historysize",32);
$zoom = readDef("zoom", 350);


$q = $ENV{"QUERY_STRING"};

$seed = "";

    for($y = 0; $y < 40; $y++){
    for($x = 0; $x < 40; $x++){
	$val  = $x."_".$y;
	$newval = "+".$x.",".$y;
	if($input{$val} ne ""){
	    $seed .= $newval;
	    $checked{$val}  = "checked";
	}
    }

}



$params = <<__EOQ__;
<param name="msg" value="$msg" />
<param name="worldsize" value="$worldsize" />
<param name="historysize" value="$historysize" />
<param name="zoomout" value="$zoom" />
<param name="seed" value="$seed" />
__EOQ__


print<<__EOQ__;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>
	        <!-- charset must remain utf-8 to be handled properly by Processing -->
		<meta http-equiv="content-type" content="text/html; charset=utf-8" />
		
		<title>conwayice : Built with Processing</title>
		
		<style type="text/css">
		/* <![CDATA[ */
	
		body {
  		  margin: 60px 0px 0px 55px;
		  font-family: verdana, geneva, arial, helvetica, sans-serif; 
		  font-size: 11px; 
		  background-color: #ddddcc; 
		  text-decoration: none; 
		  font-weight: normal; 
		  line-height: normal; 
		}
		 
		a          { color: #3399cc; }
		a:link     { color: #3399cc; text-decoration: underline; }
		a:visited  { color: #3399cc; text-decoration: underline; }
		a:active   { color: #3399cc; text-decoration: underline; }
		a:hover    { color: #3399cc; text-decoration: underline; }
	
		/* ]]> */
		</style>
	 
	</head>
	<body>

<table border=0>
<tr><td valign="top">

		<div id="content">
			<div id="conwayice_container">
			
			<!--[if !IE]> -->
				<object classid="java:conwayice2.class" 
            			type="application/x-java-applet"
            			archive="conwayice2.jar"
            			width="800" height="800"
            			standby="Loading Processing software..." >

					<param name="archive" value="conwayice2.jar" />
				
					<param name="mayscript" value="true" />
					<param name="scriptable" value="true" />
				
					<param name="image" value="loading.gif" />
					<param name="boxmessage" value="Loading Processing software..." />
					<param name="boxbgcolor" value="#FFFFFF" />
				
					<param name="test_string" value="outer" />


$params


	
			<!--<![endif]-->
				
				<object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" 
						codebase="http://java.sun.com/update/1.4.2/jinstall-1_4_2_12-windows-i586.cab"
						width="800" height="800"
						standby="Loading Processing software..."  >

$params

						
					<param name="code" value="conwayice2" />
					<param name="archive" value="conwayice2.jar" />
					
					<param name="mayscript" value="true" />
					<param name="scriptable" value="true" />
					
					<param name="image" value="loading.gif" />
					<param name="boxmessage" value="Loading Processing software..." />
					<param name="boxbgcolor" value="#FFFFFF" />
					
					<param name="test_string" value="inner" />
					


					<p>
						<strong>
							This browser does not have a Java Plug-in.
							<br />
							<a href="http://java.sun.com/products/plugin/downloads/index.html" title="Download Java Plug-in">
								Get the latest Java Plug-in here.
							</a>
						</strong>
					</p>
				
				</object>
				
			<!--[if !IE]> -->
				</object>
			<!--<![endif]-->
			
			</div>

__EOQ__
			if($seed ne ""){
			    print<<__EOQ__;
<form action="save.cgi">

<p>
save name: <input name="savename">
your name: <input name="yourname">
<input type="hidden" name="q" value="$q">
&nbsp;&nbsp;&nbsp;&nbsp;
<input type="submit" value="save it">
</p>

</form>
__EOQ__
}
print<<__EOQ__;
<p>
<form>

gridsize:<input name="worldsize" value="$worldsize" size=4>
generations to plot: <input name="historysize" value="$historysize" size=4>
start zoom: <input name="zoom" value="$zoom" size=4>
&nbsp;&nbsp;&nbsp;&nbsp;
<input type="submit" value="start with pattern below">
</p>
<br>
<nobr>
__EOQ__
    for($y = 0; $y < 40; $y++){
    for($x = 0; $x < 40; $x++){
	$val  = $x."_".$y;
	$c = $checked{$val};
	print qq(<input type="checkbox" name="$val" style="width:12px;height:12px" $c>);
    }
    print "<br>\n\n";
}
    print<<__EOQ__;
</nobr>
</form>


</td>
<td valign="top">
<p>
<b>conwayice2</b>
/ <a href="conwayice2.pde">source</a> 
/			built with <a href="http://processing.org" title="Processing.org">processing</a>
			</p>
<table width=300><tr><td>
a bigger and more technical version of <a href="/2007/10/21">conwayice</a>
<br><br>
mouse button zooms, rather than resetting the pattern. also, borders are dead zones without 
wraparound.
below the display, you can change starting parameters and even put in your 
own initial pattern. once you make your own pattern you can bookmark the page.
you will also be given the option of saving it in the following list!
</td></tr></table>
<table><tr><td>
<br>
<b>previous saves:</b><br>
__EOQ__

open(READ,"< saves.txt");
while(defined($next=<READ>)){
($t,$n,$q)= split(/\t/,$next);
print qq(<a href="index.cgi?$q">$t</a> by $n<br>);
}
close READ;

print<<__EOQ__;
</td></tr></table>


</td></tr>
</table>



	</body>
</html>
__EOQ__

