0 1 2 3 4 5 6 7 8 9 0| - - - - - - - - | 1| | 2| | 3| | 4| | 5| | 6| | 7| | 8| | 9| - - - - - - - - | y END OF DOCUMENTATION */ /*-------------------*\ | Get start values | \*-------------------*/ //GET showhint boolean from addressbar (everthing but "" means true) $showhint = ($_GET["showhint"] != ""); //GET values from addressbar $polarium_line1 = $_GET["line1"]; $polarium_line2 = $_GET["line2"]; $polarium_line3 = $_GET["line3"]; //Also able to recieve variables through POSTDATA if($_POST["submit"]) { $polarium_line1 = $_POST["line1"]; $polarium_line2 = $_POST["line2"]; $polarium_line3 = $_POST["line3"]; } /*-------------------------*\ | decode the values | \*-------------------------*/ //Reverse the linevalues and convert them to integers by multiplying it with 1 $line1 = strrev($polarium_line1)*1; $line2 = strrev($polarium_line2)*1; $line3 = strrev($polarium_line3)*1; //Convert lines to binary values $binary_line1 = decbin($line1); $binary_line2 = decbin($line2); $binary_line3 = decbin($line3); //Force all values to have 32 characters (by adding zeros to the front) $binary_line1 = str_pad($binary_line1, 32, "0", STR_PAD_LEFT); $binary_line2 = str_pad($binary_line2, 32, "0", STR_PAD_LEFT); $binary_line3 = str_pad($binary_line3, 32, "0", STR_PAD_LEFT); //Reverse bitstring from line1 and line2 $binary_line1 = strrev($binary_line1); $binary_line2 = strrev($binary_line2); //Final grid information with all puzzlelines $grid = $binary_line1 . $binary_line2; /*-----------------*\ | Third line | \*-----------------*/ //Get all secondary information from the third line //Yeah, I should be all bitshifting and stuff but I'm lazy and keep it to substringing it :) //$hash1 = bindec(substr($binary_line3, 0, 4)); //$hash2 = bindec(substr($binary_line3, 4, 4)); $height = bindec(substr($binary_line3, 8, 4)); $width = bindec(substr($binary_line3, 12, 4)); $endY = bindec(substr($binary_line3, 16, 4)); $endX = bindec(substr($binary_line3, 20, 4)); $startY = bindec(substr($binary_line3, 24, 4)); $startX = bindec(substr($binary_line3, 28, 4)); /*-----------------*\ | Image preparing | \*-----------------*/ header ("Content-type: image/png"); //For the people who want to include custom tiles with other dimensions $tileheight = 15; $tilewidth = 15; //Calculate image dimensions including the border $imageheight = ($height * $tileheight) + ($tileheight * 2); $imagewidth = ($width * $tilewidth) + ($tilewidth * 2); $image = @imagecreatetruecolor($imagewidth, $imageheight) or die("Server doesn't support image functions"); /*---------------*\ | Load images | \*---------------*/ $blacktile = @imagecreatefrompng("blacktile.png") or die("Can't find blacktile.png"); $whitetile = @imagecreatefrompng("whitetile.png") or die("Can't find whitetile.png"); $bordertile = @imagecreatefrompng("bordertile.png") or die("Can't find bordertile.png"); /*------------------*\ | Print bordertiles | \*------------------*/ for($linecount = 0; $linecount <= $height+1; $linecount++) { for($tilecount = 0; $tilecount <= $width+1; $tilecount++) { //If it is the most left or right tile OR if it's the top or bottom line a tile can be printed if(($tilecount == 0 || $tilecount == $width+1) || ($linecount == 0 || $linecount == $height+1)) { $bordertileX = $tilecount * $tilewidth; $bordertileY = $linecount * $tileheight; imagecopy ($image, $bordertile, $bordertileX, $bordertileY, 0, 0, $tilewidth, $tileheight); } } } /*----------------------------*\ | Print black and white tiles | \*----------------------------*/ //Each line for($line = 0; $line < $height; $line++) { //Each tile for($tile = 0; $tile < $width; $tile++) { //Get number out of grid (0 for white and 1 for black) $char = ($line * 8) + $tile; $number = $grid{$char}; //Check for tile and make a reference to the correct color if($number == "0") { $tileimage = $whitetile; } else { $tileimage = $blacktile; } //Make sure that our wee little tile gets placed in the right spot $x = ($tile * $tilewidth) + $tilewidth; $y = ($line * $tileheight) + $tileheight; //Copy the tile into the real thing imagecopy ($image, $tileimage, $x, $y, 0, 0, $tilewidth, $tileheight); } } /*---------------------*\ | Start and end hints | \*---------------------*/ if($showhint) { $startendtile = @imagecreatefrompng("startendtile.png") or die("Can't find startendtile.png"); imagecopy ($image, $startendtile, $startX * $tilewidth, $startY * $tileheight, 0, 0, $tilewidth, $tileheight); imagecopy ($image, $startendtile, $endX * $tilewidth, $endY * $tileheight, 0, 0, $tilewidth, $tileheight); } /*--------------*\ | Image output | \*--------------*/ imagepng($image); imagedestroy($image); ?>