Use php to output different heart-shaped patterns_php skills

WBOY
Release: 2016-05-16 19:53:57
Original
2963 people have browsed it

First of all, I would like to share with you the code for php to output a heart-shaped curve . The code is as follows

<&#63;php
for($t=0;$t<360;$t++)
{
 $y=2*cos($t)-cos(2*$t); //笛卡尔心形曲线函数
 $x=2*sin($t)-sin(2*$t);
 $x+=3;
 $y+=3;
 $x*=70;
 $y*=70;
 $x=round($x);
 $y=round($y);
 $str[]=$x;
 $y=$y+2*(180-$y);//图像上下翻转
 $x=$y;
 $str[]=$x;
}
 $im=imagecreate(400,400);//创建画布400*400
 $black=imagecolorallocate($im,0,0,0);
 $red=imagecolorallocate($im,255,0,0);//设置颜色
 imagepolygon($im,$str,360,$red);
 imagestring($im,5,190,190,"love",$red);//输出字符串
 header('Content-type:image/gif');//通知浏览器输出的是gif图片
 imagegif($im);//输出图片
 imagedestroy($im);//销毁
&#63;>
Copy after login

The effect is as follows:

Use PHP to output the Cartesian heart pattern, the code is as follows

Copy code The code is as follows:
$width = 600; $height = 650; header("Content- type: image/gif"); $img = imagecreate($width,$height);//Create a picture $bg color = imagecolorallocate($img,0,0,0); $red = imagecolorallocate($img, 255,0,0); for($i=0;$i<=100;$i ){ for($j=0;$j<=100;$j ){ $r = M PI/50 $i * (1-sin(M_PI/50 $j)) 40; $x = $r cos(M PI/50 $j) sin(M PI/50 $i) $width/2; $y = -$r sin (M_PI/50*$j) $height/6; imagesetpixel($img,$x,$y,$red); } } imagegif($img); imagedestroy($img);

$width = 600;$height = 650;header("Content-type: image/gif");$img = imagecreate($width,$height);//Create an image$bg_color = imagecolorallocate($ img,0,0,0);$red = imagecolorallocate($img,255,0,0);for($i=0;$i<=100;$i ){for($j=0;$j< ;=100;$j ){ $r = M_PI/50*$i * (1-sin(M_PI/50*$j))*40;$x = $r *cos(M_PI/50*$j)* sin(M_PI/50*$i) $width/2;$y = -$r*sin(M_PI/50*$j) $height/6;imagesetpixel($img,$x,$y,$red); }}imagegif($img);imagedestroy($img);


The above is the entire content of this article, I hope it will be helpful to everyone’s study.

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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!