PHP code to draw a parabola and create image


Hello Friends today i will discuss how to draw a parabola with PHP code and create an image. We will draw this parabola with standard equation.

<?php
$x = 400;
$y = 400;
$gd = imagecreatetruecolor($x, $y);   //create background image
$red = imagecolorallocate($gd, 255, 255, 255);   //create image
for ($i = 0; $i < 400; $i++) {
  imagesetpixel($gd, 200, $i, $red);  //draw vertical line
  imagesetpixel($gd, $i, 200, $red);  //draw horizontal line
    $x = $i;
  $y = sqrt(40*$x);
  imagesetpixel($gd, $x+200, $y+200, $red);  //draw parabola
  imagesetpixel($gd, $x+200, 200-$y, $red);  //draw parabola
}
header('Content-Type: image/png');
imagepng($gd);
?>
PHP code to draw a parabola and create image PHP code to draw a parabola and create image Reviewed by Unknown on 11:31 Rating: 5