Thursday, April 23, 2026

Chaos Game dan Fraktal dengan PHP

 <?php


$width = 500;
$height = 500;
$image = imagecreatetruecolor($width, $height);

$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);

imagefill($image, 0, 0, $white);

$points = [
    [250, 20],   // atas
    [20, 480],   // kiri bawah
    [480, 480]   // kanan bawah
];

$x = rand(0, $width);
$y = rand(0, $height);

for ($i = 0; $i < 50000; $i++) {

    $randIndex = rand(0, 2);
    $target = $points[$randIndex];

    $x = ($x + $target[0]) / 2;
    $y = ($y + $target[1]) / 2;

    imagesetpixel($image, $x, $y, $black);
}

header("Content-Type: image/png");
imagepng($image);
imagedestroy($image);
?>

Thursday, April 16, 2026

OJO TILE Untuk Mencari Jalan Terpendek (Maps Google Simple cash)

<?php

$grid = [
    ['S', '.', '.', '#', '.'],
    ['#', '#', '.', '#', '.'],
    ['.', '.', '.', '.', '.'],
    ['.', '#', '#', '#', '.'],
    ['.', '.', '.', 'G', '.'],
];

$rows = count($grid);
$cols = count($grid[0]);

$start = [0,0];
$goal = [4,3];

$directions = [
    [1,0], [-1,0], [0,1], [0,-1]
];

// queue untuk BFS
$queue = [];
$queue[] = [$start[0], $start[1], 0]; // row, col, langkah

$visited = [];
$visited[$start[0]][$start[1]] = true;

while (!empty($queue)) {
    [$r, $c, $dist] = array_shift($queue);

    if ($r == $goal[0] && $c == $goal[1]) {
        echo "Jarak terpendek: $dist\n";
        break;
    }

    foreach ($directions as $d) {
        $nr = $r + $d[0];
        $nc = $c + $d[1];

        if ($nr >= 0 && $nr < $rows && $nc >= 0 && $nc < $cols) {
            if (!isset($visited[$nr][$nc]) && $grid[$nr][$nc] != '#') {
                $visited[$nr][$nc] = true;
                $queue[] = [$nr, $nc, $dist + 1];
            }
        }
    }
}

?> 

Set Cookie dan Remove Cookie dengan php vanilla.js

< html lang = "en" > < head >     < meta charset = "UTF-8" >     < meta name = "viewport...