01 | <?php |
02 | $Nationflag = ImageCreate(660, 440); |
03 | ImageColorAllocate ( $Nationflag ,255,0,0); |
04 | DrawPentacle( $Nationflag ,180,150,120,120); |
05 | DrawPentacle( $Nationflag ,80,30,210,50); |
06 | DrawPentacle( $Nationflag ,120,30,250,100); |
07 | DrawPentacle( $Nationflag ,180,30,250,160); |
08 | DrawPentacle( $Nationflag ,100,30,210,210); |
09 | Header( 'Content-type: image/png' ); |
10 | ImagePng( $Nationflag ); |
11 | ImageDestroy( $Nationflag ); |
12 |
13 | /* |
14 | 函数:绘制五角星 |
15 | 参数 |
16 | $mFlag:图像标识 |
17 | $mAngle:旋转角度 |
18 | $mRadius:外接圆半径 |
19 | $position_X:绘制坐标X |
20 | $position_Y:绘制坐标Y |
21 | */ |
22 | function DrawPentacle( $mFlag , $mAngle , $mRadius , $position_X , $position_Y ){ |
23 | $yellow = imagecolorallocate( $mFlag , 255, 255, 0); |
24 | $PI = 3.14; |
25 | $theta =54+ $mAngle ; |
26 | for ( $i =0; $i <5; $i ++) { //五顶点坐标 |
27 | $r = $mRadius *sin(18* $PI /180)/sin(54* $PI /180); |
28 | $points [ $i ]= array ( 'x' => $r * cos (( $theta + $i *72)* $PI /180)+ $position_X , 'y' =>- $r *sin(( $theta + $i *72)* $PI /180)+ $position_Y ); |
29 | } |
30 | for ( $i =0; $i <5; $i ++){ //五条线坐标 |
31 | $j = $i >2? $i -3: $i +2; |
32 | $lines [ $i ] = array ( 'x1' => $points [ $i ][ 'x' ], 'y1' => $points [ $i ][ 'y' ], 'x2' => $points [ $j ][ 'x' ], 'y2' => $points [ $j ][ 'y' ]); |
33 | } |
34 | for ( $i =0; $i <5; $i ++){ //五交点坐标 |
35 | $j = $i >3?0: $i +1; |
36 | $x12 = $lines [ $i ][ 'x1' ] - $lines [ $i ][ 'x2' ]; |
37 | $x34 = $lines [ $j ][ 'x1' ] - $lines [ $j ][ 'x2' ]; |
38 | $y12 = $lines [ $i ][ 'y1' ] - $lines [ $i ][ 'y2' ]; |
39 | $y34 = $lines [ $j ][ 'y1' ] - $lines [ $j ][ 'y2' ]; |
40 | $c = $x12 * $y34 - $y12 * $x34 ; |
41 | $a = $lines [ $i ][ 'x1' ] * $lines [ $i ][ 'y2' ] - $lines [ $i ][ 'y1' ] * $lines [ $i ][ 'x2' ]; |
42 | $b = $lines [ $j ][ 'x1' ] * $lines [ $j ][ 'y2' ] - $lines [ $j ][ 'y1' ] * $lines [ $j ][ 'x2' ]; |
43 | $x = ( $a * $x34 - $b * $x12 ) / $c ; |
44 | $y = ( $a * $y34 - $b * $y12 ) / $c ; |
45 | $intersection [ $i ]= array ( 'x' => $x , 'y' => $y ); |
46 | } |
47 | for ( $i =0; $i <3; $i ++){ //三个三角形 |
48 | $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' ]); |
49 | imagefilledpolygon( $mFlag , $Polygon [ $i ], 3, $yellow ); |
50 | } |
51 | |
52 | } |
53 | ?> |