利用php輸出不同的心形圖案
來源:易賢網 閱讀:2092 次 日期:2016-08-26 14:52:45
溫馨提示:易賢網小編為您整理了“利用php輸出不同的心形圖案”,方便廣大網友查閱!

首先為大家分享php輸出心形曲線的代碼,代碼如下

代碼如下:

<?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);//創(chuàng)建畫布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);//銷毀

?>

利用php輸出笛卡爾心形圖案,代碼如下

代碼如下:

$width = 600; $height = 650; header("Content-type: image/gif"); $img = imagecreate($width,$height);//創(chuàng)建一張圖片 $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);//創(chuàng)建一張圖片$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);

以上就是本文的全部內容,希望對大家的學習有所幫助。

更多信息請查看網絡編程
易賢網手機網站地址:利用php輸出不同的心形圖案
關于我們 | 聯系我們 | 人才招聘 | 網站聲明 | 網站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 加入群交流 | 手機站點 | 投訴建議
工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網安備53010202001879號 人力資源服務許可證:(云)人服證字(2023)第0102001523號
聯系電話:0871-65317125(9:00—18:00) 獲取招聘考試信息及咨詢關注公眾號:hfpxwx
咨詢QQ:526150442(9:00—18:00)版權所有:易賢網