Skip to content

PHP code to draw a parabola and create image

Published
Reading time
1 min read
Views
1.6k views
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);
?>

Questions & comments

Did this work for you, or did you hit a different error? Ask below and we will help.

Comments are reviewed before they appear.

More like this

More in Programming

Programming

PHP code to draw cos function on image

Today i will tell you how to draw cos function in PHP. This is very simple task to draw a cosine function with PHP code. These are functions of Mathematics and used in Nu…

Programming

Draw sine function with PHP code on an image.

Now we learn how to draw a sine function in PHP. It is very simple and easy to draw sine function in PHP language. This function will generate a sine wave on image. Watch…

Programming

PHP code to draw tan function on an image

In this article you will learn about tan function. How to draw tan function on an image with PHP code. Mostly these functions are used in mathematics, computer pixels and…

Programming

Easy Way To Draw Line On Image in JAVA

In this article you will learn how to draw line on an image in JAVA language. This is very easy way. You also can store this image in your System. BufferedImage img = new…