Use php to output different heart-shaped patterns and php heart-shaped patterns. Use php to output different heart-shaped patterns. The php heart-shaped pattern first shares the php code for outputting the heart-shaped curve. the code is as follows: phpfor ($ t0; $ t360; $ t ++) {$ y2 * cos ($ t)-cos (2 * $ t); Cartesian uses php to output different 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:
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.
Pipeline first shares the php code for outputting a heart-shaped curve. the code is as follows: phpfor ($ t = 0; $ t360; $ t ++) {$ y = 2 * cos ($ t) -cos (2 * $ t); // Cartesian...