如需轉載請註明出處~。~。<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>正弦曲線</title> <style type="text/css"> body { background-color:Black;} #menu { top:150px; left:800px; width:300px; height:150px; position:absolute; cursor:move; border-style:solid; border-color:Red;} .bt { width:70px;} .text { width:40px;} </style> <script language="javascript" type="text/javascript"> var a = 50; var omiga = 2; var phase = 0; var r = 0; var time = 0; var timer = ""; function Show(o,diva,type,phasetxt) { document.getElementById("sin").innerHTML = ""; if(o==""||o==0) omiga=2; else omiga=o; if(diva==""||diva==0) a=50; else a=diva; if(document.getElementById("phasetext").value=="") phase=0; else phase= parseFloat(phasetxt); if(type=="D") { for(var i = time+0; i<360+time; i++) { var radian = Math.PI/180*i; var left = i-time+50; var top = -a* Math.sin(omiga * radian + phase)+ 50; document.getElementById("sin").appendChild(CreatePoint(left,top,"red")); } } else { for(var i = 0; i<360; i++) { var radian = Math.PI/180*i; var left = i+50; var top = -a* Math.sin(omiga * radian + phase)+ 50; document.getElementById("sin").appendChild(CreatePoint(left,top,"red")); } } for(var i = 50; i<=420; i++) document.getElementById("sin").appendChild(CreatePoint(i,50,"white")); for(var i = 0; i<=100; i++) document.getElementById("sin").appendChild(CreatePoint(50,i,"white")); if(type=="D") { time += 10; timer= setTimeout("Okclick('D')",200); } } function CreatePoint(left,top,color) { var point = document.createElement("div"); with(point) { style.width = "2px"; style.height = "2px"; style.backgroundColor = color; style.position = "absolute"; style.left = left + "px"; style.top = top + "px"; } return point; } var X=0,Y=0; var Divmove =function(){} Divmove.Move = function(id) { var div=document.getElementById(id); div.onmousedown = function() { X=event.clientX - div.offsetLeft; Y=event.clientY - div.offsetTop; document.onmousemove = function() { div.style.left=event.clientX - X; div.style.top=event.clientY - Y; } document.onmouseup = function() { document.onmousemove = null; } } } function Okclick(tp) { var o=document.getElementById("Omiga").value; var diva=document.getElementById("diva").value; var phasetxt=document.getElementById("phasetext").value; var type=tp; Show(o,diva,type,phasetxt); } </script></head><body onload="Show(2,0,0)"> <form id="form1" runat="server"> <div id="sin"> </div> </form> <div id="divmove" style="position: absolute; left: 420px;top: 0px;width:300px;height:150px; background-image:url(images/divbg.gif); color:White; cursor:move; border:solid 4pxwhite;" onmousedown="Divmove.Move('divmove')"> <div style=" background-color:Gray; filter:alpha(opacity=50);">輸入參數:<hr /></div><br /> 頻率:<input class="text" id="Omiga" type="text" /> 振幅:<input id="diva" class="text" type="text" /> 相位:<inputid="phasetext" class="text" type="text" /> <br /><br /><hr /> <input id="Ok" class="bt" type="button" value="確定"onclick="Okclick()" /><input id="Dshow" class="bt" type="button"onclick="Okclick('D')" value="動態顯示" /><input id="Cshow"class="bt" type="button" onclick="clearTimeout(timer);" value="停止動態" /> </div></body></html>