This article is a detailed analysis of the method of using php to draw the positive cosine curve on the image. if you need a friend, refer to the previous method of writing a dynamic trigonometric curve using actionscript, in fact, php outputs the trigonometric curve quite easily.
The code is as follows:
Define ("MAX_WIDTH_PIXEL", 600 );
Define ("MAX_HEIGHT_PIXEL", 240 );
// Send the header information
Header ("Content-type: image/gif ");
// Create an image
$ Img = imageCreate (MAX_WIDTH_PIXEL, MAX_HEIGHT_PIXEL );
// Set the 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 an axis
ImageLine ($ img, $ width, 0, $ width, MAX_HEIGHT_PIXEL, $ black); // Y axis
ImageLine ($ img, 0, $ height, MAX_WIDTH_PIXEL, $ height, $ black); // x axis
// Use loops to depict function images
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 the image
ImageGif ($ img );
// Release resources
ImageDestroy ($ img );
/* = = */
?>