Ernest's code for Drawing Complex Functions

Complex Graph 1 Complex Graph 2

FIRST SLAVE CODE FOLLOWS

<?php    // PHP slave script drawing complex functions

// create a blank image 200x200
$image imagecreate(200200);

// background color white
$white imagecolorallocate($image255255255);
imagefilledrectangle($image00200200$white);

// --- FIRST FUNCTION (blue starburst) ---

$blue imagecolorallocate($image00255);

$center 100;
$PI pi();

$a 1;
$b 1;
$m 12;
$n1 5;
$n2 6;
$n3 48;

// Draw blue pattern
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)), -($n1));

    
$x $center $r cos($f) * 35;
    
$y $center $r sin($f) * 35;
    
imagesetpixel($image$x$y$blue);
}

// --- SECOND FUNCTION (red overlay curve) ---

$red imagecolorallocate($image25500);

$a 1;
$b 1;
$m 8;
$n1 5;
$n2 6;
$n3 24;

// Draw red pattern over blue
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)), -($n1));

    
$x $center $r cos($f) * 35;
    
$y $center $r sin($f) * 35;
    
imagesetpixel($image$x$y$red);
}

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


SECOND SLAVE CODE FOLLOWS

<?php    // PHP slave script drawing a fractal

// create a blank 200x200 image
$image imagecreate(200200);

// background white
$white imagecolorallocate($image255255255);
imagefilledrectangle($image00200200$white);

// red pixels for fractal
$red imagecolorallocate($image25500);

// starting point
$x 200;
$y 200;

// triangle corners
$corners = [];
$corners[0] = ['x' => 100'y' => 10];
$corners[1] = ['x' => 0,   'y' => 190];
$corners[2] = ['x' => 200'y' => 190];

// Chaos Game algorithm (Sierpinski Triangle)
for ($i 0$i 100000$i++) {
    
imagesetpixel($imageround($x), round($y), $red);

    
$a rand(02);
    
$x = ($x $corners[$a]['x']) / 2;
    
$y = ($y $corners[$a]['y']) / 2;
}

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