0;$i--) { if ($s[$pathx[$i]][$pathy[$i]-1] == $i-1 && !$cellWallTop[$pathx[$i]][$pathy[$i]]) { $pathx[$i-1]=$pathx[$i]; $pathy[$i-1]=$pathy[$i]-1; } if ($s[$pathx[$i]+1][$pathy[$i]] == $i-1 && !$cellWallLeft[$pathx[$i]+1][$pathy[$i]]) { $pathx[$i-1]=$pathx[$i]+1; $pathy[$i-1]=$pathy[$i]; } if ($s[$pathx[$i]][$pathy[$i]+1] == $i-1 && !$cellWallTop[$pathx[$i]][$pathy[$i]+1]) { $pathx[$i-1]=$pathx[$i]; $pathy[$i-1]=$pathy[$i]+1; } if ($s[$pathx[$i]-1][$pathy[$i]] == $i-1 && !$cellWallLeft[$pathx[$i]][$pathy[$i]]) { $pathx[$i-1]=$pathx[$i]-1; $pathy[$i-1]=$pathy[$i]; } } } for ($y=1;$y<=$mazeHeight+1;$y++) { for ($x=1;$x<=$mazeWidth+1;$x++) { if ($cellWallTop[$x][$y]) line($x*$cellWidth,$y*$cellHeight,($x+1)*$cellWidth,$y*$cellHeight); if ($cellWallLeft[$x][$y]) line($x*$cellWidth,$y*$cellHeight,$x*$cellWidth,($y+1)*$cellHeight); //imagettftext($img,8,0,$x*$cellWidth+$cellWidth/2,$y*$cellHeight+8+$cellHeight/2,$fg,"sansation.ttf",$s[$x][$y]); } } if ($path) { for ($i=2,$len=count($pathx);$i<$len;$i++) line(($pathx[$i-1]+0.5)*$cellWidth,($pathy[$i-1]+0.5)*$cellHeight,($pathx[$i]+0.5)*$cellWidth,($pathy[$i]+0.5)*$cellHeight,true); line(1.5*$cellWidth,0.5*$cellHeight,1.5*$cellWidth,1.5*$cellHeight,true); line(($mazeWidth+0.5)*$cellWidth,($mazeHeight+0.5)*$cellHeight,($mazeWidth+0.5)*$cellWidth,($mazeHeight+1.5)*$cellHeight,true); } imagepng($img); imagedestroy($img); function line($x1,$y1,$x2,$y2,$path=false) { global $img,$fg,$pc; if ($path) return imageline($img,$x1,$y1,$x2,$y2,$pc); else return imageline($img,$x1,$y1,$x2,$y2,$fg); } ?>