Home > php教程 > php手册 > 如何使用php绘制在图片上的正余弦曲线

如何使用php绘制在图片上的正余弦曲线

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 11:50:33
Original
1519 people have browsed it

以前用actionscript写动态绘制三角函数曲线,其实php输出三角函数曲线也很简单。

复制代码 代码如下:


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

 //发送标头信息
 header("Content-type: image/gif");

 //建立图像
 $img = imageCreate(MAX_WIDTH_PIXEL, MAX_HEIGHT_PIXEL);

 //设定颜色
 $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;    //宽度
 $height = MAX_HEIGHT_PIXEL/2;    //高度

 //建立坐标轴
 imageLine($img, $width, 0, $width, MAX_HEIGHT_PIXEL, $black);//y轴
 imageLine($img, 0, $height, MAX_WIDTH_PIXEL, $height, $black);//x轴

 //通过循环来实现函数图形的描绘
 for($i=0; $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);
 }

 //显示图形
 imageGif($img);

 //释放资源
 imageDestroy($img);
        /*==隐逸鸟==*/
?>

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template