-
- /**
- * How to draw sine and cosine curves on pictures
- * edit: bbs.it-home.org
- */
- 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
- //Establish coordinate axis
- imageLine($img, $width, 0, $width, MAX_HEIGHT_PIXEL, $black);//y-axis
- imageLine($img, 0, $height, MAX_WIDTH_PIXEL, $height, $black);//x-axis
- //Depicting 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);
- ?>
Copy code
|