js实现的牛顿摆效果_javascript技巧_脚本之家

2019-12-05 22:20栏目:竞技宝竞猜
TAG:

Newton摆是三个1959时期发明的桌面演示装置,多少个品质相似的圆球由吊绳固定,互相紧凑排列。又叫:Newton摆球、动量守恒摆球、永动球、物理撞球、碰碰球等。

图片 1

(function{ window.None || ; //重力加速度 var G=9.8; var PI=Math.PI; //帧频 var FPS=48; /*//IE角度转换function rorateIt{ //取得末变形前矩形的中点 var rect = node.getBoundingClientRect(), cx1 = (rect.right - rect.left) / 2, // center x cy1 = (rect.bottom - rect.top) / 2, // center y deg2rad = Math.PI / 180,//角度转弧度 rad = deg * deg2rad , cos = Math.cos, sin = Math.sin; var ident = "DXImageTransform.Microsoft.Matrix"; node.style.filter = "progid:"+ident +"(M11='1.0',sizingmethod='auto expand')"; //http://www.satzansatz.de/cssd/onhavinglayout.html if(!node.currentStyle.hasLayout){//在IE7中,如果没有获得hasLayout,滤镜会失效 node.style.writingMode = "tb-rl"; } var filter = node.filters.item; // +-------+-------+ // | M11 | M12 | // +-------+-------+ // | M21 | M22 | // +-------+-------+ filter.M11 = cos; filter.M12 = -sin; filter.M21 = sin; filter.M22 = cos; //取得当前中心 rect = node.getBoundingClientRect(); var cx = (rect.right - rect.left) / 2; var cy = (rect.bottom - rect.top) / 2; //调整此元素的坐标系,实现CSS3 transform-origin的功能 node.style.marginLeft = cx1 - cx + "px"; node.style.marginTop = cy1 - cy + "px";} */ //外部函数引用 //是否IE function isIE(){ return navigator.userAgent.indexOf>-1; } //获取当前样式 function returnStyle{ var myObj = typeof obj == "string" ? document.getElementById : obj; if{ return eval("myObj.currentStyle." + styleName); } else { return eval("document.defaultView.getComputedStyle." + styleName); } } //外部函数引用 //图片方法 var img=function{ var img=new Image(); img.src=src; return img; } //方向类,以垂直向下为0度逆时针为正 var face=function{ //0-360 this.unit='deg'; ifdeg=180/PI*deg; this.deg=deg; this.rad=PI/180*this.deg; } //矢量类 var vector=function{ var cstrct=this.constructor; this.size=size; this.face=fx||new face; fx=this.face; this.toHv=function(){ var h=new cstrct*size,90); var v=new cstrct*size,0); return [h,v]; } } //继承,obj:需要从矢量继承的对象,arg:arguments vector.extend=function{ vector.apply; } //矢量合并方法 vector.merger=function{ ifarrvector=arguments; var cstrct=arrvector[0].constructor; var i=0,ilav=arrvector.length; var sum=[0,0]; for{ var hv=arrvector[i].toHv(); sum[0]+=hv[0].size; sum[1]+=hv[1].size; } var size=Math.sqrt(sum[0]*sum[0]+sum[1]*sum[1]); var fa=new face(Math.atan; return new cstrct; } //力类,参数为大小和方向 var force=function{ this.unit='N'; //继承自矢量 vector.apply; } //加速度类 var a=function{ this.unit='m/s^2'; vector.extend; } //速度类 var speed=function{ this.unit='m/s'; vector.extend; } //刚体类,参数 var rigid=function{ //一般情况下body为一个img对象,所以暂且只有正方形或长方形两种形式 this.body=body; this.m=m; //质量 this.focus=(this.body instanceof Image)?point(this.body.width/2,this.body.height/2):point(this.body.style.width/2,this.body.style.height/2); this.axis=point this.force=new force; this.a=new a(this.force.size/this.m,this.force.face); this.speed=new speed; //设置,可重新设置上面所有参数 this.set=function{ this[prop]=value; } this.addForce=function{ return this.force=vector.merger; } //旋转 this.rotate=function{ axis=axis||this.axis||this.focus; //cx1=returnStyle; //cy1=returnStyle; var rect=this.body.getBoundingClientRect(), //cx1=rect.left+axis.x, //cy1=rect.top+axis.y, cx1 = (rect.right - rect.left) / 2, cy1 = (rect.bottom - rect.top) / 2, rad=face.rad, cos = Math.cos, sin = Math.sin{ var ident = "DXImageTransform.Microsoft.Matrix"; this.body.style.filter = "progid:"+ident +"(M11='1.0',sizingmethod='auto expand')"; if(!returnStyle(this.body,"hasLayout")){//在IE7中,如果没有获得hasLayout,滤镜会失效 this.body.style.writingMode = "tb-rl"; } var filter = this.body.filters.item; filter.M11 = cos; filter.M12 = -sin; filter.M21 = sin; filter.M22 = cos; } rect = this.body.getBoundingClientRect(); //var cx=rect.left+axis.x; //var cy=rect.top+axis.y; var cx = (rect.right - rect.left) / 2; var cy = (rect.bottom - rect.top) / 2; //调整此元素的坐标系,实现CSS3 transform-origin的功能 this.body.style.left=parseInt(this.body.style.left,10) + cx1 - cx + "px"; this.body.style.top=parseInt(this.body.style.top,10) + cy1 - cy + "px"; //CSS3 var sdeg="rotate"; var paxis=axis.x+"px "+axis.y+"px"; this.body.style.transformOrigin=paxis; this.body.style.MozTransformOrigin=paxis; this.body.style.WebkitTransformOrigin=paxis; this.body.style.OTransformOrigin=paxis; this.body.style.WebkitTransform=sdeg; this.body.style.MozTransform=sdeg; this.body.style.OTransform=sdeg; this.body.style.transform=sdeg; } } //刚体组合 rigid.merger=function(){ } //无弹性绳子类 var rope=function{ this.body=body; this.length=length; this.maxForce=maxForce || Infinity || Number.MAX_VALUE; } //组合体类 var comb=function{ } //单摆类 var pendulum=function{ } //类单摆 var likePend=function{//刚体,初始角度,摆动频率 var self=this; this.rigid=rigid; this.body=this.rigid.body; this.axis=this.rigid.axis; this.dom=this.rigid.dom; this.m=this.rigid.m; this.rad=fa?fa.rad:fa=new face; //摆动 //角度30 var fx=fa.rad; //角度平方根 var m=Math.sqrt; //摆动时间1秒 var atime=time||0.5; var fnum=FPS*atime; //单位增量 var fm=m/fnum; //i:角度平方根到0 var i=-m,tid; var g=new a; var t=1000/FPS; //o:{s:1,f:30,t:0,fun:callback} :s:速度增加还是减小,f:从多少度,t:到多少度,fun:摆完后运行的函数 this.swing=function{/* var asps=g.size*Math.cos/; var fss=new force(asps,new face; this.rigid.force=fss; var a=this.rigid.a; //单位时间内速度的增量 var a1=Math.acos((asps+this.rigid.speed.size)/2) this.rigid.speed=new speed; a2=a1*2;*/ //{s:-1,inc:1} o=o||{s:1}; var y=-o.s*i*i+fx*o.s; if{ self.rigid.rotate,self.axis); clearTimeoutfun(); return; } var f=new face; self.rigid.rotate; i+=fm; tid=setTimeout{self.swing.call; } this.moveTo=function{ self.body.style.left=p.x+"px"; self.body.style.top=p.y+"px"; } } //世界 None.world=function{ //param:{force:[多个force对象]} this.param=param||{}; this.config={ //全局外力 g:new a, className:'', width:'100%', height:'100%', left:0, top:-200, arrNav:['about','myWork','site','other','myTools'], imgW:60, imgN:5, sDeg:5, hitSound:'sounds/hit.wav', vol:0.1 } this.init(); }; None.world.prototype={ //初始化 dom:{}, init:function(){ var c=this.config; var p=this.param; //dom var dom=document.createElement; dom.className=c.className; dom.style.position="absolute"; dom.style.width=p.width||c.width; dom.style.height=p.height||c.height; dom.style.left= +"px"; dom.style.top= +"px"; this.dom=dom; document.body.appendChild; }, //添加一个刚体 addRigid:function{ if(!(rigid instanceof Array)){ rigid=[rigid]; } if]; if)p=[p]; for(var i=0,rl=rigid.length;i以上所述就是本文的全部内容了,希望大家能够喜欢。能够对大家学习javascript有所帮助。

无数人中意在办公室摆一些工艺品摆件,可是今后期货市场场情上中国人民解放军海军事工业程高校业艺品摆件的档案的次序有无数,每一种摆件都有它的意义,大家日常不精晓该怎么筛选。那么您知道办公室工艺品摆件有何吗?大家经常听二种普及办公室工艺品摆件,那么您询问呢?上面作者就来为我们介绍一下呢。

办公室工艺品摆件有如何

1、梦想之航

梦想之航摆件相当多的对象都以特地心仪的,它不止在做工上十一分的精美,并且所包含的意味也是老大稳固独特的。梦想之航,深意着大家的企盼将在杨帆(yáng fān卡塔尔(قطر‎起航,携带大家人生将在达到辉煌。那样的摆件相符年轻的首长,预示着温馨想要风流洒脱番看作。年老的长官则足以见到他们永恒在为温馨的期待而拼搏,守护着友好心灵最美好的地点。

2、牛顿永动球

Newton永动球那后生可畏款Newton永动球笔者想我们都不会不熟悉,因为它出现在重重电视机上,领导们都喜悦在自身的办公桌子的上面摆放那样二个摆件。将Newton撞球设于办公桌子的上面,当我们做事困苦、眼睛酸疼时,停下来,摆动几下Newton摆球,就能够到达放松紧张疲惫的心,随着摆球转动眼球,倍感舒服。那样的摆件适合任何年龄阶段。

3、万像更新

版权声明:本文由龙竞技官网发布于竞技宝竞猜,转载请注明出处:js实现的牛顿摆效果_javascript技巧_脚本之家