欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

PHP版国旗

程序员文章站 2022-04-26 16:05:40
...
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('Content-type: image/png');
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('x'=>$r*cos(($theta+$i*72)*$PI/180)+$position_X,'y'=>-$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('x1' => $points[$i]['x'], 'y1' => $points[$i]['y'], 'x2' => $points[$j]['x'], 'y2' => $points[$j]['y']);
	}
	for($i=0;$i<5;$i++){//五交点坐标	
		$j = $i>3?0:$i+1;
		$x12 = $lines[$i]['x1'] - $lines[$i]['x2'];
		$x34 = $lines[$j]['x1'] - $lines[$j]['x2'];
		$y12 = $lines[$i]['y1'] - $lines[$i]['y2'];
		$y34 = $lines[$j]['y1'] - $lines[$j]['y2'];
		$c = $x12 * $y34 - $y12 * $x34;
		$a = $lines[$i]['x1'] * $lines[$i]['y2'] - $lines[$i]['y1'] * $lines[$i]['x2'];
		$b = $lines[$j]['x1'] * $lines[$j]['y2'] - $lines[$j]['y1'] * $lines[$j]['x2'];
		$x = ($a * $x34 - $b * $x12) / $c;
		$y = ($a * $y34 - $b * $y12) / $c;
		$intersection[$i]= array('x'=>$x,'y'=>$y);
	}
	for($i=0;$i<3;$i++){//三个三角形
		$Polygon[$i] = array($points[$i]['x'],$points[$i]['y'],$points[$i+2]['x'],$points[$i+2]['y'],$intersection[$i+2]['x'],$intersection[$i+2]['y']);	
		imagefilledpolygon($mFlag, $Polygon[$i], 3, $yellow);
	}
	
}
?>
相关标签: PHP版国旗