当前位置: 首页 > 图文教程 > 网络编程 > Javascript > JavaScript弹簧振子超简洁版 完全符合能量守恒,胡克定理

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 JavaScript弹簧振子超简洁版 完全符合能量守恒,胡克定理


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 364 ::
收藏到网摘: n/a

完全符合能量守恒,胡克定理的JavaScript弹簧振子(超简洁版,超越第一版!) 上一版用的是物理思想,这次用的是数学思想,如果您下载过第一版的代码就能明显感到数学的强大!!!!!
这里是弹簧的JS代码:
复制代码 代码如下:

<script type="text/javascript">
/////////////////this spring begin/////////////////////
var X=0.1//X轴增量
var T=0;//X轴初位置
var M=200; //原始振幅倍数
var A=0.7;//振幅倍数衰减数
var D='R';//运动方向
var O=0;//元素
var L=0;//位置
var TI=30;
var S=false;
var HR=false;
function R(){
HR=true;
if(S)
{
return;
}
O.style.left= L+(Math.sin(T))*M+"px";//获取弹簧运动速度
T=T+X;//X轴增长
M-=A;//单位时间衰减
if(M<=0)//振幅为零
{
S=true;
return;//退出
}
setTimeout("R()",TI);//回调
}
///////////////////this spring over///////////////////////////
function I()
{
if(HR){
return;
}
S=false;
O=document.getElementById("div");
X=parseFloat(document.getElementById("X").value);
M=parseFloat(document.getElementById("M").value);
A=parseFloat(document.getElementById("A").value);
TI=parseFloat(document.getElementById("TI").value);
L=document.getElementById("div").offsetLeft;
R();
}
function TS()
{
S=true;
}
function B()
{
if(S)
{
T=0
HR=false;
S=false;
X=parseFloat(document.getElementById("X").value);
M=parseFloat(document.getElementById("M").value);
A=parseFloat(document.getElementById("A").value);
document.getElementById("div").style.left=L+"px";
}
}
</script>

这里是该网页中的HTML(没啥用,为了演示)
复制代码 代码如下:

<div id="P" style="width:500px;height:400px;">
<input style="width:50px" type="text" id="X" value="0.1" />X轴增量<br/><input style="width:50px" type="text" id="M" value="200" />原始振幅倍数<br/>
<input style="width:50px" type="text" id="A" value="0.7" />振幅倍数衰减数<br/>
<input style="width:50px" type="text" id="TI" value="30" />运行时间间隔(毫秒)<br/>
<input style="width:80px" type="button" onclick="TS()" value="停止"/>停止后请从新激活<br/><input style="width:80px" type="button" onclick="B()" value="从新激活"/>
</div><div style=" position:absolute;"><div id="div" onclick="I()" value="设置完后点我!" style="position:absolute; top:-264px; left:211px; width:50px; height:50px; background-color:#FF0;"></div></div>

这比上次的代码大有长进!100%原创!
转载http://www.cnblogs.com/NONE/