Home >php教程 >php手册 >php使用GD库画五角星

php使用GD库画五角星

WBOY
WBOYOriginal
2016-06-13 10:51:521649browse

01     $width = 500; 

02     $height = 500; 

03   

04     $im = imagecreatetruecolor($width, $height); 

05   

06     $red = imagecolorallocate($im, 230, 0, 0); 

07     imagefill($im, 0, 0, $red); 

08   

09     $yellow = imagecolorallocate($im, 255, 255, 0); 

10       

11     //设定画出五角星的五个顶点形成的 正五边形的边长 

12     $b=100; 

13     $pi=3.14/180; 

14   

15     $p1x = 150; 

16     $p1y = 250; 

17   

18     $p2x = 150+(cos(36*$pi)*$b); 

19     $p2y = 250-(sin(36*$pi)*$b); 

20   

21     $p3x = 150+(2*cos(36*$pi)*$b); 

22     $p3y = 250; 

23   

24     $p4x = $p3x-sin(18*$pi)*$b; 

25     $p4y = 250+cos(18*$pi)*$b; 

26   

27     $p5x = 150+sin(18*$pi)*$b; 

28     $p5y = 250+cos(18*$pi)*$b; 

29       

30     //连接相应的点 画线 

31     imageline($im, $p1x, $p1y, $p3x, $p3y, $yellow); 

32     imageline($im, $p1x, $p1y, $p4x, $p4y, $yellow); 

33   

34     imageline($im, $p2x, $p2y, $p4x, $p4y, $yellow); 

35     imageline($im, $p2x, $p2y, $p5x, $p5y, $yellow); 

36   

37     imageline($im, $p3x, $p3y, $p5x, $p5y, $yellow); 

38   

39     header('Content-Type:image/png'); 

40   

41     imagepng($im); 

42   

43     imagedestroy($im); 

44   

45 ?>

Statement:
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