[非原创]正弦函数图象
时间:2006-12-19
来源:互联网
PHP代码:
<?php
Header("Content-type: image/png");
$width = 800 ; //图像的宽度
$height = 500 ; //图像的高度
$pixel = 720 ; //画点的个数
$xOffset= 10; //y 轴的偏移量
$yOffset= 250 ; //x 轴的偏移量
$im = imagecreate($width , $height);
$cream = imagecolorallocate($im , 255 , 255 , 200);
$blue = imagecolorallocate($im , 0 , 0 , 255);
$black = imagecolorallocate($im , 0 , 0 , 0);
$red = imagecolorallocate($im , 255 , 0 , 0);
$green = imagecolorallocate($im , 0 , 255 , 0);
imageline($im,0,$yOffset,($width-15),$yOffset,$black); /* x 轴 */
imageline($im,$xOffset,0,$xOffset,$height,$black); /* y 轴 */
imagestring($im , 5 , ($xOffset + 2) , ($yOffset + 2) , "0" , $red);//设置坐标原点
imagestring($im , 5 , ($xOffset-3), 0, "^" , $red);
imagestring($im , 5 ,($width-16),($yOffset-7), ">" , $red);
imagestring($im , 5 ,($width-10),($yOffset-15), "x" , $red);
for ($i = 0 ; $i < $pixel ; $i++){
$x = $i+$xOffset;
$y = cos(deg2rad($i))*100+$yOffset;
$z = $yOffset-sin(deg2rad($i))*200;
$k = tan(deg2rad($i))*100+$yOffset;
imagesetpixel($im , $x , $y , $blue);
imagesetpixel($im , $x , $z , $red);
imagesetpixel($im , $x , $k , $green);
if($i%90==0&&$i!=0){
imageline($im,$x,0,$x,$height,$black);
}
}
imagepng($im);
imagedestroy($im);
?>
作者: muqiao 发布时间: 2006-12-18
作者: cator 发布时间: 2006-12-18
作者: leehui1983 发布时间: 2006-12-18
请教,我不会撒,还没看gd2函数库,我只是改别人的,
作者: muqiao 发布时间: 2006-12-18
PHP代码:
<?php
Header("Content-type: image/png");
$width = 800 ; //图像的宽度
$height = 500 ; //图像的高度
$pixel = 720 ; //画点的个数
$xOffset= 10 ; //y 轴的偏移量
$yOffset= 250 ; //x 轴的偏移量
$avi = 15 ; //平均数
$im = imagecreate($width , $height);
$cream = imagecolorallocate($im , 255 , 255 , 200);
$blue = imagecolorallocate($im , 0 , 0 , 255);
$black = imagecolorallocate($im , 0 , 0 , 0);
$red = imagecolorallocate($im , 255 , 0 , 0);
$green = imagecolorallocate($im , 0 , 255 , 0);
imageline($im,0,$yOffset,($width-15),$yOffset,$black); /* x 轴 */
imageline($im,$xOffset,0,$xOffset,$height,$black); /* y 轴 */
imagestring($im , 5 , ($xOffset + 2) , ($yOffset + 2) , "0" , $red);//设置坐标原点
imagestring($im , 5 , ($xOffset - 3) , 0, "^" , $red);
imagestring($im , 5 , ($width - 16) , ($yOffset - 7 ), ">" , $red);
imagestring($im , 5 , ($width - 10) , ($yOffset - 15), "x" , $red);
for($j = 0;$j < $pixel ; $j++){
for ($k = 0 ; $k < $avi ; $k++){
$i = $k/$avi+($j-1);
$x = $i+$xOffset;
$y = cos(deg2rad($i))*100+$yOffset;
$z = $yOffset-sin(deg2rad($i))*200;
$k = tan(deg2rad($i))*100+$yOffset;
imagesetpixel($im , $x , $y , $blue);
imagesetpixel($im , $x , $z , $red);
imagesetpixel($im , $x , $k , $green);
if($i%90==0&&$i!=0){
imageline($im,$x,0,$x,$height,$black);
}
}
}
imagepng($im);
imagedestroy($im);
?>
作者: muqiao 发布时间: 2006-12-19
作者: Nickboy 发布时间: 2006-12-19
那��好�c��?
作者: w992 发布时间: 2006-12-19
作者: muqiao 发布时间: 2006-12-19
如果要画振幅比较大的类 sin 函数曲线,就得考虑用另外的一种算法了,用画小段的线代替点.
作者: hy0kl 发布时间: 2006-12-19
作者: xiaojia 发布时间: 2006-12-22
不要看起来断断续续的。

作者: jefsun 发布时间: 2006-12-28
代码:
<?phpHeader("Content-type: image/png");
$width = 800 ; //图像的宽度
$height = 500 ; //图像的高度
$pixel = 720 ; //画点的个数
$xOffset= 10; //y 轴的偏移量
$yOffset= 250 ; //x 轴的偏移量
$im = imagecreate($width , $height);
$cream = imagecolorallocate($im , 255 , 255 , 200);
$blue = imagecolorallocate($im , 0 , 0 , 255);
$black = imagecolorallocate($im , 0 , 0 , 0);
$red = imagecolorallocate($im , 255 , 0 , 0);
$green = imagecolorallocate($im , 0 , 255 , 0);
imageline($im,0,$yOffset,($width-15),$yOffset,$black); /* x 轴 */
imageline($im,$xOffset,0,$xOffset,$height,$black); /* y 轴 */
imagestring($im , 5 , ($xOffset + 2) , ($yOffset + 2) , "0" , $red);//设置坐标原点
imagestring($im , 5 , ($xOffset-3), 0, "^" , $red);
imagestring($im , 5 ,($width-16),($yOffset-7), ">" , $red);
imagestring($im , 5 ,($width-10),($yOffset-15), "x" , $red);
for ($i = 0 ; $i < $pixel ; $i++){
if ($i != 0) $lastX = $x;
if ($i != 0) $lastY = $y;
if ($i != 0) $lastZ = $z;
if ($i != 0) $lastK = $k;
$x = $i+$xOffset;
$y = cos(deg2rad($i))*100+$yOffset;
$z = $yOffset-sin(deg2rad($i))*200;
$k = tan(deg2rad($i))*100+$yOffset;
imagesetpixel($im , $x , $y , $blue);
if ($i != 0) imageline($im, $x, $y, $lastX, $lastY, $blue);
imagesetpixel($im , $x , $z , $red);
if ($i != 0) imageline($im, $x, $z, $lastX, $lastZ, $red);
imagesetpixel($im , $x , $k , $green);
if ($i != 0) imageline($im, $x, $k, $lastX, $lastK, $green);
if($i%90==0&&$i!=0){
imageline($im,$x,0,$x,$height,$black);
}
}
imagepng($im);
imagedestroy($im);
?>
作者: dgwxx 发布时间: 2007-01-01
作者: muqiao 发布时间: 2007-01-01
$im = imagecreate($width , $height);
$cream = imagecolorallocate($im , 255 , 255 , 200);
替换成:
$im = imagecreatetruecolor($width , $height);
imageantialias($im,true);
$cream = imagecolorallocate($im , 255 , 255 , 200);
imagefill($im, 0, 0, $cream);
即可实现抗锯齿,做出来的图好看多了。
作者: dgwxx 发布时间: 2007-01-01
作者: muqiao 发布时间: 2007-01-01
作者: dzjzmj 发布时间: 2007-01-02
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28