Home >Backend Development >PHP Tutorial >用PHP的GD库画的两个几何图

用PHP的GD库画的两个几何图

WBOY
WBOYOriginal
2016-06-23 13:25:36934browse

//code6.php    没有函数化

<?php header("Content-type:image/png");$img=imagecreatetruecolor(400, 400);$black=imagecolorallocate($img, 0, 0, 0);$red=imagecolorallocate($img, 255, 0, 0);$green=imagecolorallocate($img, 0, 255, 0);$blue=imagecolorallocate($img, 0, 0, 255);imagefill($img, 0, 0, $black);imageline($img, 0, 0, 400, 400, $green);imageline($img, 40, 0, 400, 400, $green);imageline($img, 80, 0, 400, 400, $green);imageline($img, 120, 0, 400, 400, $green);imageline($img, 160, 0, 400, 400, $green);imageline($img, 200, 0, 400, 400, $green);imageline($img, 240, 0, 400, 400, $green);imageline($img, 280, 0, 400, 400, $green);imageline($img, 320, 0, 400, 400, $green);imageline($img, 360, 0, 400, 400, $green);imageline($img, 390, 0, 400, 400, $green);imageline($img, 0, 40, 400, 400, $green);imageline($img, 0, 80, 400, 400, $green);imageline($img, 0, 120, 400, 400, $green);imageline($img, 0, 160, 400, 400, $green);imageline($img, 0, 200, 400, 400, $green);imageline($img, 0, 240, 400, 400, $green);imageline($img, 0, 280, 400, 400, $green);imageline($img, 0, 320, 400, 400, $green);imageline($img, 0, 360, 400, 400, $green);imageline($img, 0, 390, 400, 400, $green);imageline($img, 0, 400, 400, 0, $green);imageline($img, 0, 400, 400, 40, $green);imageline($img, 0, 400, 400, 80, $green);imageline($img, 0, 400, 400, 120, $green);imageline($img, 0, 400, 400, 160, $green);imageline($img, 0, 400, 400, 200, $green);imageline($img, 0, 400, 400, 240, $green);imageline($img, 0, 400, 400, 280, $green);imageline($img, 0, 400, 400, 320, $green);imageline($img, 0, 400, 400, 360, $green);imageline($img, 0, 400, 400, 390, $green);imageline($img, 0, 400, 360, 0, $green);imageline($img, 0, 400, 320, 0, $green);imageline($img, 0, 400, 280, 0, $green);imageline($img, 0, 400, 240, 0, $green);imageline($img, 0, 400, 200, 0, $green);imageline($img, 0, 400, 160, 0, $green);imageline($img, 0, 400, 120, 0, $green);imageline($img, 0, 400, 80, 0, $green);imageline($img, 0, 400, 40, 0, $green);imageline($img, 0, 400, 10, 0, $green);imagepng($img);?>

//code7.php  函数化处理

<?php header("Content-type:image/png");$img=imagecreatetruecolor(400, 400);$black=imagecolorallocate($img, 0, 0, 0);$red=imagecolorallocate($img, 255, 2550, 0);$green=imagecolorallocate($img, 0, 255, 0);$blue=imagecolorallocate($img, 0, 0, 255);imagefill($img, 0, 0, $black);for($i=0;$i<=400;$i+=10){imageline($img, 0, $i, 200, 200, $red);}for($j=0;$j<=400;$j+=20){imageline($img, $j, 0, 200, 200, $red);}for($x=0;$x<=400;$x+=10){imageline($img, 200, 200, 400, $x, $red);}for($y=0;$y<=400;$y+=20){imageline($img, 200, 200, $y, 400, $red);}imagepng($img);?>

//code6.png

//code7.png


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