This article mainly introduces how to use php to output different heart-shaped patterns, use php to output a heart-shaped curve, and use php to output a Cartesian heart-shaped pattern. if you are interested, please refer to the article for your reference.
Php output heart-shaped curveThe code is as follows:
<? Phpfor ($ t = 0; $ t <360; $ t ++) {$ y = 2 * cos ($ t)-cos (2 * $ t ); // Cartesian heart-shaped curve function $ 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); // Image flip up/down $ x = $ y; $ str [] = $ x ;} $ im = imagecreate (400,400); // Create a canvas 400*400 $ black = imagecolorallocate ($ im, 0); $ red = imagecolorallocate ($ im, 255, 0, 0); // set the color imagepolygon ($ im, $ str, 360, $ red); imagestring ($ im, 5,190,190, "love", $ red); // output string Header ('content-type: image/gif '); // notifies the browser that the output of the gif image imagegif ($ im); // output the image imagedestroy ($ im ); // Destroy?>
The effect is as follows:
Output Cartesian heart pattern using phpThe code is as follows:
The code is as follows:
$ Width = 600; $ height = 650; header ("Content-type: image/gif"); $ img = imagecreate ($ width, $ height ); // create an image $ bg color = imagecolorallocate ($ img, 0); $ red = imagecolorallocate ($ img, 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); $ red = imagecolorallocate ($ img, 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 all the content of this article, hoping to help you learn.