使用js畫圖之正弦曲線
數(shù)學(xué)式:y=Asin(ωx+φ)+k
樣例:http://www.zhaojz.com.cn/demo/draw7.html
JS函數(shù)的聲明:
//畫正弦曲線
//dot 原點(diǎn)
//amplitude 振幅 -- A
//initialPhase 初相 -- φ
//setover 偏距 -- k
//palstance 角速度 -- ω
//len 周期數(shù)
function drawSinusoid(dot, amplitude,initialPhase,palstance,setover, len, opts){
var color = opts&&opts.color?opts.color:"DarkRed"; //曲線的顏色
var max = len*2*Math.PI/w; //x的最大值
//var x = -2*Math.PI/w/3;
var x = 0; //x的初值
var pre = [dot[0]+x, dot[1]+(amplitude*Math.sin(palstance*x+initialPhase)+setover)]; //y的初值
for(;x < max;x+=5){ //每五個(gè)單位畫一條線
var cur = [dot[0]+x, dot[1]+(amplitude*Math.sin(palstance*x+initialPhase)+setover)];
drawLine(pre, cur, {color: color}); // 畫線
pre = cur;
}
var d = Math.PI/(2*w);
for(var x =0;x < max;x+=d){//描點(diǎn)
var cur = [dot[0]+x, dot[1]+(amplitude*Math.sin(palstance*x+initialPhase)+setover)];
drawPoint({
pw:3,ph:3,color:'DarkRed',point: cur
});
}
var pend = [dot[0]+max, dot[1]+(amplitude*Math.sin(palstance*max+initialPhase)+setover)];
drawPoint({
pw:3,ph:3,color:'DarkRed',point: pend
});
drawLine(pre, pend);
}
相關(guān)文章
小程序顯示彈窗時(shí)禁止下層的內(nèi)容滾動(dòng)實(shí)現(xiàn)方法
這篇文章主要介紹了小程序顯示彈窗時(shí)禁止下層的內(nèi)容滾動(dòng)實(shí)現(xiàn)方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來(lái)看看吧2019-03-03鼠標(biāo)拖拽移動(dòng)子窗體的JS實(shí)現(xiàn)
這篇文章主要介紹了鼠標(biāo)拖拽移動(dòng)子窗體的JS實(shí)現(xiàn),需要的朋友可以參考下2014-02-02js判斷IE6/IE7/FF的代碼[XMLHttpRequest]
js下通過XMLHttpRequest判斷IE6/IE7/FF的代碼,需要的朋友可以參考下。2011-02-02js下關(guān)于onmouseout、事件冒泡的問題經(jīng)驗(yàn)小結(jié)
第3次遇到這個(gè)問題,于是總結(jié)了一下,將此短文發(fā)在首頁(yè),希望對(duì)瀏覽器事件機(jī)制有所了解的大俠們給予解答2010-12-12

JS數(shù)組搜索之折半搜索實(shí)現(xiàn)方法分析

Javascript農(nóng)歷與公歷相互轉(zhuǎn)換的簡(jiǎn)單實(shí)例

js實(shí)現(xiàn)獲取最新本周周一開始的日期(單周日歷卡)