Tedd's code for Drawing Complex Functions

Complex Graph1 Complex Graph2

CODE FOLLOWS

<?php
include('includes/header.php');
error_reporting(E_ALL);

// --- Create first complex graph in memory ---
$image1 imagecreate(200200);
$white imagecolorallocate($image1255255255);
imagefilledrectangle($image100200200$white);

$blue imagecolorallocate($image100255);
$center 100;
$PI pi();
$a 1$b 1$m 12$n1 5$n2 6$n3 48;

for(
$f 0$f <= $PI$f += 0.0001) {
    
$r pow((pow(abs(cos($m*$f/4)/$a), $n2) + pow(abs(sin($m*$f/4)/$b), $n3)), -(1/$n1));
    
$x $center $r cos($f) * 35;
    
$y $center $r sin($f) * 35;
    
imagesetpixel($image1$x$y$blue);
}

$red imagecolorallocate($image125500);
$a 1$b 1$m 8$n1 5$n2 6$n3 24;

for(
$f 0$f <= $PI$f += 0.0001) {
    
$r pow((pow(abs(cos($m*$f/4)/$a), $n2) + pow(abs(sin($m*$f/4)/$b), $n3)), -(1/$n1));
    
$x $center $r cos($f) * 35;
    
$y $center $r sin($f) * 35;
    
imagesetpixel($image1$x$y$red);
}

// Convert first image to base64
ob_start();
imagepng($image1);
$data1 ob_get_clean();
$image1_base64 'data:image/png;base64,' base64_encode($data1);
imagedestroy($image1);

// --- Create second fractal graph in memory ---
$image2 imagecreate(200200);
$white2 imagecolorallocate($image2255255255);
imagefilledrectangle($image200200200$white2);

$red2 imagecolorallocate($image225500);
$x 200$y 200;
$corners = [
    [
'x'=>100,'y'=>10],
    [
'x'=>0,'y'=>190],
    [
'x'=>200,'y'=>190]
];

for (
$i 0$i 100000$i++) {
    
imagesetpixel($image2round($x), round($y), $red2);
    
$a rand(0,2);
    
$x = ($x $corners[$a]['x']) / 2;
    
$y = ($y $corners[$a]['y']) / 2;
}

// Convert second image to base64
ob_start();
imagepng($image2);
$data2 ob_get_clean();
$image2_base64 'data:image/png;base64,' base64_encode($data2);
imagedestroy($image2);
?>

<h1>Tedd's code for Drawing Complex Functions</h1>

<img src="<?php echo $image1_base64?>" alt="Complex Graph1">
<img src="<?php echo $image2_base64?>" alt="Complex Graph2">

<hr><br>CODE FOLLOWS<br><br>
<?php highlight_file(__FILE__); ?>

<?php include('includes/footer.php'); ?>