sin()线的代码
当前位置:首页 ----> Web开发 ----> Php
关键词:jnkq
jnkq:
sin()线的代码      <?php
 $width = 400;
 $height = 300; 

 $data = array();
 for( $i = 0; $i < 500; $i++ )
 {
 $data []= sin( deg2rad( ( $i / 500 ) * 360 ) );
 }
 

 $xstart = $width/10;
 $ystart = $height - ($height/10);
 
 $image = imagecreate($width, $height);
 $back = imagecolorallocate($image, 255, 255, 255);
 $border = imagecolorallocate($image, 64, 64, 64);
 
 imageline( $image, $xstart, 0, $xstart, $ystart, $border );
 imageline( $image, $xstart, $ystart, $width, $ystart, $border );
 
 imagestring( $image, 2, $xstart-20, $ystart-10, &quot;1&quot;, $border );
 imagestring( $image, 2, $xstart-20, 0, &quot;-1&quot;, $border );
 imagestring( $image, 2, $xstart, $ystart+5, &quot;0&quot;, $border );
 imagestring( $image, 2, $width-20, $ystart+5, &quot;360&quot;, $border );
 
 $datatop = 1;
 $databottom = -1;
 
 $oldx = 0;
 $oldy = 0;
 $datacount = count( $data );
 $xscale = ( $width - $xstart ) / $datacount;
 $yscale = $ystart / ( $datatop - $databottom );
 $midline = $ystart / 2;
 for( $i = 0; $i < $datacount; $i++ )
 {
 $x = $xstart + ( $i * $xscale );
 $y = $midline - ( $data[$i] * $yscale );
 if ( $i > 0 )
 {
 imageline( $image, $oldx, $oldy, $x, $y, $border );
 }
 $oldx = $x;
 $oldy = $y;
 }header(&quot;Content-type: image/png&quot;);
 imagepng($image);
 imagedestroy($image); 
?> [ 本帖最后由 jnkq 于 2006-3-25 02:45 编辑 ]    附件          <img src="images/attachicons/image.gif" border="0" class="absmiddle" alt="" />  01.png  (1.08 KB)      

 2006-3-25 02:34            

     <img src="attachment.php?aid=739&noupdate=yes" border="0" onload="attachimg(this, 'load')" onmouseover="attachimg(this, 'mouseover')" onclick="zoom(this, 'attachment.php?aid=739')" alt="01.png" />


forest:
好东西,收藏了!


faallan:
瓦靠,B/S架构的“示波器”!!!


fakir:
这个方法更简单呵呵      复制内容到剪贴板代码:<?
header(&quot;Content-type: image/png&quot;);
$im = imagecreatetruecolor(800, 400);
for($x=0;$x<800;$x++){
 $y=sin(pi()*$x/200)*100+200;
 imagesetpixel($im,$x,$y,255);
};
imagepng($im);
imagedestroy($im);
?>


jnkq:
引用:原帖由 fakir 于 2006-3-25 22:45 发表
[code]
<?
header(&quot;Content-type: image/png&quot;);
$im = imagecreatetruecolor(800, 400);
for($x=0;$x<800;$x++){
 $y=sin(pi()*$x/200)*100+200;
 imagesetpixel($im,$x,$y,255);
} ... 您自己看看是不是可以?我这没看出来,一个红叉叉


fakir:
不会吧,我这里显示的老好了,没有问题啊


jnkq:
又看了一下,不行    附件          <img src="images/attachicons/image.gif" border="0" class="absmiddle" alt="" />  01.png  (24.06 KB)      

 2006-3-26 18:59            

     <img src="attachment.php?aid=741&noupdate=yes" border="0" onload="attachimg(this, 'load')" onmouseover="attachimg(this, 'mouseover')" onclick="zoom(this, 'attachment.php?aid=741')" alt="01.png" />


fakir:
晕,看看我的 [ 本帖最后由 fakir 于 2006-3-26 19:12 编辑 ]    附件          <img src="images/attachicons/image.gif" border="0" class="absmiddle" alt="" />  {D6C1D515-1DAF-418C-ABB4-7C628FA255DC}0.jpg  (11.7 KB)      

 2006-3-26 19:12            

     <img src="attachment.php?aid=743&noupdate=yes" border="0" onload="attachimg(this, 'load')" onmouseover="attachimg(this, 'mouseover')" onclick="zoom(this, 'attachment.php?aid=743')" alt="{D6C1D515-1DAF-418C-ABB4-7C628FA255DC}0.jpg" />


jnkq:
一样    附件          <img src="images/attachicons/image.gif" border="0" class="absmiddle" alt="" />  01.png  (19.54 KB)      

 2006-3-26 19:12            

     <img src="attachment.php?aid=742&noupdate=yes" border="0" onload="attachimg(this, 'load')" onmouseover="attachimg(this, 'mouseover')" onclick="zoom(this, 'attachment.php?aid=742')" alt="01.png" />


fakir:
莫非版本不一样?我的是php5……


jnkq:
我的是php5.1.2


fakir:
我的是5.1.1……不至于差这么多吧


fakir:
郁闷!重来一个完整的试试复制内容到剪贴板代码:<?
header(&quot;Content-type: image/png&quot;);
$picw=800; //图像宽
$pich=400; //图像高
$sizeofsin=100; //比例值 ,要输出不同大小标准正弦只改变它就可以了
$asin=1; //振幅
$tsin=2*pi(); //周期
$aofsin=$asin*$sizeofsin;
$tofsin=$tsin*$sizeofsin;
$im = imagecreate($picw, $pich);
imagecolorallocate($im,255,255,255);
$col=imagecolorallocate($im,0,0,0);
for($x=0;$x<$picw;$x++){
 $y=$pich-(sin((2*pi()/$tsin)*$x/$sizeofsin)*$aofsin+$pich/2);
 imagesetpixel($im,$x,$y,$col);
 if($x % (pi()*$sizeofsin/2)==0){
 imageline($im,$x,$pich/2-2,$x,$pich/2+2,$col);
 imagestring($im,1,$x+2,$pich/2+3,round($x/$sizeofsin/pi(),1).&quot;pi&quot;,$col);
 }
};
imageline($im,0,0,0,$pich,$col);
imageline($im,0,$pich/2,$picw,$pich/2,$col);
ImageLine($im,0,$pich/2-$aofsin,5,$pich/2-$aofsin,$col);
imagestring($im,1,10,$pich/2-$aofsin,$aofsin/$sizeofsin,$col);
imagepng($im);
imagedestroy($im);
?>[ 本帖最后由 fakir 于 2006-3-26 23:28 编辑 ]    附件          <img src="images/attachicons/image.gif" border="0" class="absmiddle" alt="" />  {8EBC57E8-A754-48EE-BA9D-8C343AB682D6}0.jpg  (7.87 KB)      

 2006-3-26 22:45        

抓图    

     <img src="attachment.php?aid=745&noupdate=yes" border="0" onload="attachimg(this, 'load')" onmouseover="attachimg(this, 'mouseover')" onclick="zoom(this, 'attachment.php?aid=745')" alt="{8EBC57E8-A754-48EE-BA9D-8C343AB682D6}0.jpg" />


hy0kl:
果然是强中自有强中手;

时至今日我才学到 GD ,真是菜啊;


Sunyanzi:
需要 GD 的支持 ...


hy0kl:
引用:原帖由 Sunyanzi 于 2006-11-8 11:49 发表
需要 GD 的支持 ... 没有 GD 画不出图来.
原文出处:http://bbs.phpchina.com/viewthread.php?tid=3484