Formula matematik: y=Asin(ωx φ) k
Sampel: http://www.zhaojz.com.cn/demo/draw7.html
Pengisytiharan fungsi JS:
//Lukis lengkung sinus
//asal titik
//amplitud Amplitud -- A
//initialPhase fasa permulaan -- φ
//setover offset -- k
//halaju sudut pastan -- ω
//len bilangan kitaran
fungsi drawSinusoid(titik, amplitud, fasa awal, debaran, setover, len, opts){
var color = opts&&opts.color?opts.color:"Merah Gelap"; //Warna lengkung
var max = len*2*Math.PI/w; //Nilai maksimum bagi x
//var x = -2*Math.PI/w/3;
var x = 0; //Nilai awal bagi x
var pra = [titik[0] x, titik[1] (amplitud*Math.sin(palstance*x initialPhase) setover)]; //Nilai awal y
for(;x < max;x =5){ //Lukis garisan setiap lima unit
var cur = [titik[0] x, titik[1] (amplitud*Math.sin(palstance*x initialPhase) setover)];
drawLine(pra, cur, {color: color}); // Lukis garisan
pra = cur;
}
var d = Math.PI/(2*w);
for(var x =0;x < max;x =d){//Plot point
var cur = [titik[0] x, titik[1] (amplitud*Math.sin(palstance*x initialPhase) setover)];
drawPoint({
pw:3,ph:3,warna:'Merah Gelap',titik: cur
});
}
var pend = [titik[0] maks, dot[1] (amplitud*Math.sin(palstance*max initialPhase) setover)];
drawPoint({
pw:3,ph:3,warna:'Merah Gelap',titik: pend
});
drawLine(pra, pend);
}