正弦函数图象
来源:百度文库 编辑:神马文学网 时间:2024/10/06 12:57:38
正弦函数图象
[复制PHP代码]PHP代码如下:
[复制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);
?> another 1
2 // letzte Änderung: Michael Berndt - Berlin
3 // Donnerstag der 01. September. 2005
4 // 10:20:42
5 //
6 // geformte Wellen erstellen mit deg2rad ()
7 //
8 //
9 // Beispiel Bild:
10 // http://michael-berndt.de/ie/tux/welle.png
11 //
12
13 define ("F", "/home/w/berndt.ttf");
14 $h=55;$b=215;$g=imagecreate($b,$h);
15 $hi= c("#ECF9C6",$g);$r= c("#9B0303",$g);$s= c("#9B0303",$g);
16 imagefilltoborder($g,0,0, 1,$r);imagefilledrectangle($g,1,1,$b - 2,$h - 2,$hi);
17 ImageTTFText ($g, 22, 0, 10, 35, $s, F, "www.leztest.de");
18 $p = $b * $h/ 10; for($i = 0; $i < $p; $i++){imagesetpixel($g, rand(0, $b), rand(0, $h), $s);}
19 $wn=3;$w =($wn * 360) / $b;
20
21 //////////////// Cosinus Welle //////////////////
22 $X = 0; $Y = $h;
23 for($pt = 0; $pt < $b; $pt++){
24 $nX = $X + 1;
25 $nY = ($h/2) + (cos(deg2rad($nX * $w)) * ($h/2));
26 ImageLine($g, $X, $Y, $nX, $nY, $s);
27 $X = $nX; $Y = $nY;
28 }
29 //////////////// Cosinus Welle //////////////////
30
31 //////////////// Sinus Welle ///////////////////
32 $X = 0; $Y = 0;
33 for ($pt = 0; $pt < $b; $pt++){
34 $nX = $X + 1;
35 $nY = ($h/2) + (sin(deg2rad($nX * $w - 90)) * ($h/2));
36 ImageLine($g, $X, $Y, $nX, $nY, $s);
37 $X = $nX; $Y = $nY;
38 }
39 //////////////// Sinus Welle ///////////////////
40
41 for ($x = 0; $x <= $h; $x += 20){ imageline($g, 0, $x, $b, $x, $s); }
42 for ($x = 0; $x <= $b; $x += 20){ imageline($g, $x, 0, $x, $h, $s); }
43 function c($f,$g){ $fs = imagecolorallocate($g,hexdec(substr($f,1,2)), hexdec(substr($f,3,2)), hexdec(substr($f,5,2))); return $fs; }
44 if ($g !== false) { $j = time();
45 header(‘Cache-control: max-age=31536000‘);
46 header(‘Expires: ‘ . gmdate(‘D, d M Y H:i:s‘, ($j + 31536000)) . ‘ GMT‘);
47 header(‘Content-disposition: inline; filename=berndt.png‘);
48 header(‘Content-transfer-encoding: binary‘);
49 header(‘Content-Type: image/png‘);
50 imagepng($g);
51 }
52 else {
53 echo ‘An error occured.‘;
54 }
55 ?>