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

Set Cookie dan Remove Cookie dengan php vanilla.js

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