"you are here" in favicon (idea from Yves)

This commit is contained in:
2023-10-11 20:44:26 +02:00
parent 938160f053
commit 738e92c16b
4 changed files with 14 additions and 36 deletions

View File

@ -2,43 +2,15 @@
header('Content-Type: image/x-icon');
const SIZE = 16;
const WALL = 1;
const GROUND = 0;
$favicon = imagecreatetruecolor(SIZE, SIZE);
$wallColor = imagecolorallocate($favicon, 165, 80, 30);
$groundColor = imagecolorallocate($favicon, 203, 162, 133);
$x = filter_input(INPUT_GET, "x", FILTER_SANITIZE_NUMBER_INT);
$y = filter_input(INPUT_GET, "y", FILTER_SANITIZE_NUMBER_INT);
imagefill($favicon, 0, 0, $wallColor);
$favicon = imagecreatefrombmp("favicon.ico");
$maze = array();
for ($y = 0; $y < SIZE; $y++) {
$maze[$y] = array();
for ($x = 0; $x < SIZE; $x++) {
$maze[$y][$x] = WALL;
}
}
$red = imagecolorallocate($favicon, 255, 0, 0);
imagesetpixel($favicon, $x, $y, $red);
function dig($position) {
global $maze;
global $favicon;
global $groundColor;
$directions = [[0, 1], [0, -1], [1, 0], [-1, 0]];
shuffle($directions);
foreach ($directions as $direction) {
$step1 = [$position[0] + $direction[0], $position[1] + $direction[1]];
$step2 = [$step1[0] + $direction[0], $step1[1] + $direction[1]];
if (0 <= $step2[1] and $step2[1] < SIZE and 0 <= $step2[0] and $step2[0] < SIZE and $maze[$step2[1]][$step2[0]] == WALL) {
$maze[$step1[1]][$step1[0]] = GROUND;
imagesetpixel($favicon, $step1[0], $step1[1], $groundColor);
$maze[$step2[1]][$step2[0]] = GROUND;
imagesetpixel($favicon, $step2[0], $step2[1], $groundColor);
dig($step2);
}
}
}
dig([1, 1]);
imagebmp($favicon);
imagedestroy($favicon);
?>