亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

php趣味編程 - php 余弦曲線

標簽:
PHP

wKiom1LLchWA8l1KAAA1vyo4AjU561.jpg

<?php

$width = 700;//图片的宽

$height = 300;//图片的高

header("Content-type: image/gif");

$img = imageCreate($width,$height);//创建一个图片

$bgcolor = imageColorAllocate($img, 0, 0, 0);//设置图片背景

$white = imageColorAllocate($img,250,250,250);//设置画笔的颜色

$width2  = $width/2;//width

$height2 = $height/2;//height

//画出y轴 找出2个点 用imageLine来画出2个点的直线

//点1的坐标(x,y)  点2的坐标(m,n)

imageLine($img,$width2,0,$width2,$height,$white);

//画出y轴上面的箭头 - 左边

imageLine($img,$width2,0,($width2-8),8,$white);

//画出y轴上面的箭头 - 右边

imageLine($img,$width2,0,($width2+8),8,$white);

//画出X轴 跟Y轴一样找出2个点 然后用imageLine来画直线

imageLine($img,0,$height2,$width,$height2,$white);

//画x轴的 箭头 - 上面

imageLine($img,$width,$height2,($width-8),($height2-8),$white);

//画x轴的 箭头 - 下面

imageLine($img,$width,$height2,($width-8),($height2+8),$white);

//在图上写上X y轴字样 用函数imagefttext

$font = 'DejaVuSans.ttf';

imagefttext($img,11,0,($width2+10),25,$white,$font,'y');

imagefttext($img,11,0,($width-20),($height2+15),$white,$font,'x');

//图片在画出一个点 颜色是白色 用函数imagesetpixel

//找出点的坐标就可以了

//余弦 cos@ = x/r  r=x的平方+y的平方

for($i=0;$i<$width;$i++)

{

    //x轴用$i表示

    //y轴的坐标

    $y = 100*cos($i/100 * M_PI);

    imagesetpixel($img,$i,$height2+$y,$white);

}

imageGif($img);

imageDestroy($img);

?>

點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消