Use php to output different heart-shaped patterns and php heart-shaped patterns
First, we will share with youPhp 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:
Copy codeThe 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.