Veronica's code for Drawing Complex Functions
FIRST SLAVE CODE FOLLOWS
<?php
// PHP slave script 1 -> drawing complex functions
// create a blank image that is 200 pixels wide and 200 pixels tall
$image = imagecreate(200, 200);
// create a color and fill (paint) the work area
// set the color RGB (255, 255, 255), which is WHITE
$white = imagecolorallocate($image, 255, 255, 255);
// fill the entire image
imagefilledrectangle($image, 0, 0, 200, 200, $white);
// === first function
// create another color
$blue = imagecolorallocate($image, 100, 100, 255);
// init vars
$center = 100;
$PI = 2 * pi();
$a = 1;
$b = 1;
$m = 12;
$n1 = 5;
$n2 = 6;
$n3 = 48;
// create the graphic
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($image, $x, $y, $blue);
}
// create yet another color
$pink = imagecolorallocate($image, 225, 75, 195);
// === second function
// change vars
$a = 1;
$b = 1;
$m = 8;
$n1 = 5;
$n2 = 6;
$n3 = 24;
// create another graphic and place it over the original graphic
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($image, $x, $y, $pink);
}
// tell the server what's coming, deliver it, and destroy it
header("Content-type: image/png");
imagepng($image);
imagedestroy($image);
?>
SECOND SLAVE CODE FOLLOWS
<?php
// PHP slave script 2 -> drawing a fractal
// create a blank image that is 200 pixels wide and 200 pixels tall
$image = imagecreate(200, 200);
// create a color and fill (paint) the work area
// set the color RGB (255, 255, 255), which is WHITE
$white = imagecolorallocate($image, 255, 255, 255);
imagefilledrectangle($image, 0, 0, 200, 200, $white);
// create another color
$red = imagecolorallocate($image, 255, 0, 0);
$orange = imagecolorallocate($image, 245, 120, 40);
$orangeyellow = imagecolorallocate($image, 245, 180, 45);
$yellow = imagecolorallocate($image, 235, 234, 55);
// initial variables
$x = 100;
$y = 200;
$corners[0] = array('x' => 100, 'y' => 20);
$corners[1] = array('x' => 0, 'y' => 180);
$corners[2] = array('x' => 200, 'y' => 180);
// create the graphic
for ($i = 0; $i < 100000; $i++)
{
if($x > 90)
{
imagesetpixel($image, round($x), round($y), $red);
}
elseif($x > 70)
{
imagesetpixel($image, round($x), round($y), $orange);
}
elseif($x > 45)
{
imagesetpixel($image, round($x), round($y), $orangeyellow);
}
else
{
imagesetpixel($image, round($x), round($y), $yellow);
}
$a = rand(0, 2);
$x = ($x + $corners[$a]['x']) / 2;
$y = ($y + $corners[$a]['y']) / 2;
}
// tell the server what's coming, deliver it, and destroy it
header('Content-Type: image/png');
imagepng($image);
imagedestroy($image);
?>