php趣味100例 - php 画出余弦图

php余弦,余弦曲线

<?php
$width = 700;//图片的宽
$height = 300;//图片的高
 
header("Content-type: image/gif");
 
$img = imageCreate($width,$height);//创建一个图片
 
$bgcolor = imageColorAllocate($img, 0, 0, 0);//设置图片背景
 
$white = imageColorAllocate($img,250,250,250);//设置画笔的颜色
 
$width2  = $width/2;//width 
$height2 = $height/2;//height
 
//画出y轴 找出2个点 用imageLine来画出2个点的直线
//点1的坐标(x,y)  点2的坐标(m,n)
imageLine($img,$width2,0,$width2,$height,$white);
//画出y轴上面的箭头 - 左边
imageLine($img,$width2,0,($width2-8),8,$white);
//画出y轴上面的箭头 - 右边
imageLine($img,$width2,0,($width2+8),8,$white);
 
 
//画出X轴 跟Y轴一样找出2个点 然后用imageLine来画直线
imageLine($img,0,$height2,$width,$height2,$white);
//画x轴的 箭头 - 上面
imageLine($img,$width,$height2,($width-8),($height2-8),$white);
//画x轴的 箭头 - 下面
imageLine($img,$width,$height2,($width-8),($height2+8),$white);
 
//在图上写上X y轴字样 用函数imagefttext
$font = 'DejaVuSans.ttf';
imagefttext($img,11,0,($width2+10),25,$white,$font,'y');
imagefttext($img,11,0,($width-20),($height2+15),$white,$font,'x');
 
//图片在画出一个点 颜色是白色 用函数imagesetpixel
//找出点的坐标就可以了
//余弦 cos@ = x/r  r=x的平方+y的平方
 
for($i=0;$i<$width;$i++)
{
//x轴用$i表示
//y轴的坐标
$y = 100*cos($i/100 * M_PI);
imagesetpixel($img,$i,$height2+$y,$white);
}
 
 
imageGif($img);
imageDestroy($img);
?>

问题 & 评论

    共有 0 评论

写个评论或者问题

该视频目前没有评论。

如果有任何关于网站的意见,可以QQ联系或者发邮箱。

tags - tags - tags - tags - tags - tags - tags - tags - tags - tags - tags - tags - tags - tags - tags -