How to draw sine and cosine curves on pictures in php

WBOY
Release: 2016-07-25 08:55:28
Original
1101 people have browsed it
  1. /**
  2. * How to draw sine and cosine curves on pictures
  3. * edit: bbs.it-home.org
  4. */
  5. define("MAX_WIDTH_PIXEL", 600);
  6. define("MAX_HEIGHT_PIXEL", 240);
  7. //Send header information
  8. header("Content -type: image/gif");
  9. //Create image
  10. $img = imageCreate(MAX_WIDTH_PIXEL, MAX_HEIGHT_PIXEL);
  11. //Set color
  12. $bgcolor = imageColorAllocate($img, 0xff, 0xe9, 0xe9);
  13. $red = imageColorAllocate($img, 255, 0, 0);
  14. $blue = imageColorAllocate($img, 0, 0, 255);
  15. $brown = imageColorAllocate($img, 100, 0, 0);
  16. $black = imageColorAllocate ($img, 0, 0, 0);
  17. $width = MAX_WIDTH_PIXEL/2; //Width
  18. $height = MAX_HEIGHT_PIXEL/2; //Height
  19. //Establish coordinate axis
  20. imageLine($img, $width, 0, $width, MAX_HEIGHT_PIXEL, $black);//y-axis
  21. imageLine($img, 0, $height, MAX_WIDTH_PIXEL, $height, $black);//x-axis
  22. //Depicting function graphics through loops
  23. for ($i=0; $i<=MAX_WIDTH_PIXEL; $i++)
  24. {
  25. $y1 = 100 * sin($i/100 * M_PI);
  26. imageSetPixel($img, $i, $height+$y1, $blue) ;
  27. $y2 = 100 * sin($i/300 * M_PI);
  28. imageSetPixel($img, $i, $height+$y2, $red);
  29. $y3 = 100 * sin($i/300 * M_PI) ;
  30. imageSetPixel($img, $i, $height-$y3, $brown);
  31. }
  32. //Display graphics
  33. imageGif($img);
  34. //Release resources
  35. imageDestroy($img);
  36. ?>
Copy code


source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template