Home > php教程 > PHP源码 > body text

PHP版国旗

PHP中文网
Release: 2016-05-25 17:09:20
Original
1925 people have browsed it

php代码

<?php
$Nationflag = ImageCreate(660, 440);
ImageColorAllocate ($Nationflag,255,0,0);
DrawPentacle($Nationflag,180,150,120,120);
DrawPentacle($Nationflag,80,30,210,50);
DrawPentacle($Nationflag,120,30,250,100);
DrawPentacle($Nationflag,180,30,250,160);
DrawPentacle($Nationflag,100,30,210,210);
Header(&#39;Content-type: image/png&#39;);
ImagePng($Nationflag);
ImageDestroy($Nationflag); 

/*
	函数:绘制五角星
	参数
		$mFlag:图像标识
		$mAngle:旋转角度
		$mRadius:外接圆半径
		$position_X:绘制坐标X
		$position_Y:绘制坐标Y
*/
function DrawPentacle($mFlag,$mAngle,$mRadius,$position_X,$position_Y){
	$yellow = imagecolorallocate($mFlag, 255, 255, 0);
	$PI = 3.14;
	$theta=54+$mAngle;
	for ($i=0;$i<5;$i++) {//五顶点坐标	
		$r = $mRadius*sin(18*$PI/180)/sin(54*$PI/180); 
		$points[$i]= array(&#39;x&#39;=>$r*cos(($theta+$i*72)*$PI/180)+$position_X,&#39;y&#39;=>-$r*sin(($theta+$i*72)*$PI/180)+$position_Y);
	}		
	for($i=0;$i<5;$i++){//五条线坐标
		$j=$i>2?$i-3:$i+2;
		$lines[$i] = array(&#39;x1&#39; => $points[$i][&#39;x&#39;], &#39;y1&#39; => $points[$i][&#39;y&#39;], &#39;x2&#39; => $points[$j][&#39;x&#39;], &#39;y2&#39; => $points[$j][&#39;y&#39;]);
	}
	for($i=0;$i<5;$i++){//五交点坐标	
		$j = $i>3?0:$i+1;
		$x12 = $lines[$i][&#39;x1&#39;] - $lines[$i][&#39;x2&#39;];
		$x34 = $lines[$j][&#39;x1&#39;] - $lines[$j][&#39;x2&#39;];
		$y12 = $lines[$i][&#39;y1&#39;] - $lines[$i][&#39;y2&#39;];
		$y34 = $lines[$j][&#39;y1&#39;] - $lines[$j][&#39;y2&#39;];
		$c = $x12 * $y34 - $y12 * $x34;
		$a = $lines[$i][&#39;x1&#39;] * $lines[$i][&#39;y2&#39;] - $lines[$i][&#39;y1&#39;] * $lines[$i][&#39;x2&#39;];
		$b = $lines[$j][&#39;x1&#39;] * $lines[$j][&#39;y2&#39;] - $lines[$j][&#39;y1&#39;] * $lines[$j][&#39;x2&#39;];
		$x = ($a * $x34 - $b * $x12) / $c;
		$y = ($a * $y34 - $b * $y12) / $c;
		$intersection[$i]= array(&#39;x&#39;=>$x,&#39;y&#39;=>$y);
	}
	for($i=0;$i<3;$i++){//三个三角形
		$Polygon[$i] = array($points[$i][&#39;x&#39;],$points[$i][&#39;y&#39;],$points[$i+2][&#39;x&#39;],$points[$i+2][&#39;y&#39;],$intersection[$i+2][&#39;x&#39;],$intersection[$i+2][&#39;y&#39;]);	
		imagefilledpolygon($mFlag, $Polygon[$i], 3, $yellow);
	}
	
}
?>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template