Use php to output different heart-shaped patterns. php heart-shaped pattern _ PHP Tutorial

Source: Internet
Author: User
Tags image flip
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.