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);
?>

No comments:

Post a Comment

Menjadi Programmer Bukan Hanya Tentang Coding, Tapi Tentang Mempermudah Kehidupan

Semenjak menjadi seorang programmer, ada satu cara pandang yang perlahan berubah dalam diri saya. Saya mulai berpikir bahwa ilmu pemrograman...