Tedd's code for Drawing Complex Functions

Complex Graph1 Complex Graph2

FIRST SLAVE CODE FOLLOWS

<?php    // PHP slave script 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, 0, 0, 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        
    
$red = imagecolorallocate($image, 255, 0, 0); 

    
// === 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, $red);
        }
    
    
// 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 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); 
    
    
// init vars                
    
$x = 200;
    
$y = 200;         
    
$corners[0] = array('x' => 100, 'y' =>  10);
    
$corners[1] = array('x' =>   0, 'y' => 190);
    
$corners[2] = array('x' => 200, 'y' => 190);
    
    
// create the graphic        
    
for ($i = 0; $i < 100000; $i++)
        {
        
imagesetpixel($image, round($x), round($y), $red);
        
$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);
?> 
 

CODE FOLLOWS

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

    
error_reporting(E_ALL);    // set error reporting to all
?>

    <h1>Tedd's code for Drawing Complex Functions</h1>
            
        <img src="complex1.php" alt="Complex Graph1"> <!-- this is it -->
        <img src="complex2.php" alt="Complex Graph2"> <!-- this is it -->

<?php

    
// list code for slave routine         
    
echo('<hr><br>FIRST SLAVE CODE FOLLOWS<br><br>');       
    
highlight_file ('complex1.php'); 

    
// list code for slave routine         
    
echo('<hr><br>SECOND SLAVE CODE FOLLOWS<br><br>');       
    
highlight_file ('complex2.php');             
            
    include(
'includes/footer.php');
?>