RaposoTKD

parabola.php

Mar 21st, 2012
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.00 KB | None | 0 0
  1. <?php
  2.     header("content-type:image/png");
  3.     $w=1000;
  4.     $h=1000;
  5.     $im=imagecreatetruecolor($w,$h);
  6.     $fundo=imagecolorallocate($im,240,240,240);
  7.     $cinza=imagecolorallocate($im,200,200,200);
  8.     $preto=imagecolorallocate($im,0,0,0);
  9.     $vermelho=imagecolorallocate($im,255,0,0);
  10.    
  11.     imagefilledrectangle($im,0,0,$w,$h,$fundo);
  12.  
  13.     $xx=$w/100;
  14.     $yy=$h/100;
  15.    
  16.     for($i=0;$i<=100;$i++){
  17.         imageline($im,$xx*$i,0,$xx*$i,1000,$cinza);
  18.     }
  19.     for($i=0;$i<=100;$i++){
  20.         imageline($im,0,$yy*$i,1000,$yy*$i,$cinza);
  21.     }
  22.    
  23.     /*[prof]*/
  24.    
  25.     function f($x){
  26.         return ($x*$x)-16;
  27.     }
  28.     $x0=-10;
  29.     $xf=10;
  30.     $u=20;
  31.     $delta=1/$u;
  32.    
  33.     $p2x=$x0;
  34.     $p2y=f($p2x);
  35.     while($p2x<=$xf)
  36.     {
  37.         $p1x=$p2x;
  38.         $p1y=$p2y;
  39.         $p2x=$p1x+$delta;
  40.         $p2y=f($p2x);
  41.         imageline($im,($w/2)+$u*$p1x,($h/2)-$u*$p1y,($w/2)+$u*$p2x,($h/2)-$u*$p2y,$vermelho);
  42.     }
  43.    
  44.     /*[\prof]*/
  45.    
  46.     imageline($im,0,$w/2,1000,$w/2,$preto);
  47.     imageline($im,$h/2,0,$h/2,1000,$preto);
  48.    
  49.     imagepng($im);
  50.     imagecolordeallocate($im,$fundo);
  51.     imagedestroy($im);
  52.    
  53. ?>
Add Comment
Please, Sign In to add comment