当前位置: 移动技术网 > IT编程>开发语言>PHP > 如何使用php绘制在图片上的正余弦曲线

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

2019年04月10日  | 移动技术网IT编程  | 我要评论

000677贴吧,音乐家,女风衣

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

复制代码 代码如下:

<?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<=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);
 }

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

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

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网