Home >Backend Development >PHP Tutorial >How to draw sine and cosine curves on pictures using PHP_PHP Tutorial

How to draw sine and cosine curves on pictures using PHP_PHP Tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-21 15:08:39990browse

In the past, I used actionscript to dynamically draw trigonometric function curves. In fact, it is very simple to output trigonometric function curves in PHP.

Copy code The code is as follows:

define("MAX_WIDTH_PIXEL", 600);
define("MAX_HEIGHT_PIXEL", 240);

//Send header information
header("Content-type: image/gif");

//Create image
$img = imageCreate(MAX_WIDTH_PIXEL, MAX_HEIGHT_PIXEL);

//Set color
$bgcolor = imageColorAllocate($img, 0xff, 0xe9, 0xe9);
$red = imageColorAllocate($img, 255, 0, 0);
$blue = imageColorAllocate($img, 0, 0, 255);
$brown = imageColorAllocate($img, 100, 0, 0);
$black = imageColorAllocate($img, 0, 0, 0);

$width = MAX_WIDTH_PIXEL/2; //Width
$height = MAX_HEIGHT_PIXEL/2; //Height

//Create coordinate axis
imageLine($img, $width, 0, $width, MAX_HEIGHT_PIXEL, $black); //y-axis
imageLine($img, 0, $height, MAX_WIDTH_PIXEL, $ height, $black);//x-axis

//Describe function graphics through loops
for($i=0; $i<=MAX_WIDTH_PIXEL; $i++)
{
$y1 = 100 * sin($i/100 * M_PI);
imageSetPixel($img, $i, $height+$y1, $blue);

$y2 = 100 * sin($i/300 * M_PI);
imageSetPixel($img, $i, $height+$y2, $red);

$y3 = 100 * sin($i/300 * M_PI);
imageSetPixel($img, $i, $height-$y3, $brown);
}

//Display graphics
imageGif($img);

//Release resources
imageDestroy($img);
/*==Hermit Bird==*/
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327471.htmlTechArticleI used to use actionscript to dynamically draw trigonometric function curves. In fact, it is very simple to output trigonometric function curves in PHP. Copy the code The code is as follows: ?php define("MAX_WIDTH_PIXEL", 600); define("MA...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn