This article will share with you the special effect of using javascript to implement Newton volleyball. It is very good. We recommend it to you here for your reference. Newton pendulum is a desktop demonstration device invented in the 1960 s. Five sphere of the same quality are fixed by the sling and closely arranged with each other. Also called: Newton swing ball, momentum conservation swing ball, permanent moving ball, physical Hitting Ball, hitting the ball and so on.
(Function (window, undefined) {window. none | (window. none ={}); // gravity acceleration var G = 9.8; var PI = Math. PI; // frame rate var FPS = 48; // * // IE angle Conversion function rorateIt (node, deg) {// obtain the midpoint var rect = node of the rectangle before the last deformation. getBoundingClientRect (), cx1 = (rect. right-rect. left)/2, // center x cy1 = (rect. bottom-rect. top)/2, // center y deg 2rad = Math. PI/180, // converts degrees to radians rad = deg * deg 2rad, cos = Math. cos (rad), sin = Math. sin (rad); 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) {// In IE7, if hasLayout is not obtained, the filter will fail node. style. writingMode = "tb-rl";} var filter = node. filters. item (ident ); // + ------- + // | M11 | M12 | // + ------- + // | M21 | M22 | // + ------- + filter. m11 = cos; filter. m12 =-sin; filter. m21 = sin; filter. m22 = cos; // obtain the current center rect = node. getBoundingClientRect (); var cx = (rect. right-rect. left)/2; var cy = (re Ct. bottom-rect. top)/2; // adjust the coordinate system of this element to implement node of CSS3 transform-origin. style. marginLeft = cx1-cx + "px"; node. style. marginTop = cy1-cy + "px";} * // external function reference // whether IE function isIE () {return navigator. userAgent. indexOf ("MSIE")>-1;} // obtain the current style function returnStyle (obj, styleName) {var myObj = typeof obj = "string "? Document. getElementById (obj): obj; if (document. all) {return eval ("myObj. currentStyle. "+ styleName);} else {return eval (" document. defaultView. getComputedStyle (myObj, null ). "+ styleName) ;}}// external function reference // Image method var img = function (src) {var img = new Image (); img. src = src; return img;} // direction class, vertical downward to 0 degrees counterclockwise as var face = function (deg, rad) {// 0-360 this. unit = 'deg '; if (rad) deg = 180/PI * deg; this. deg = deg; this. rad = PI/180 * this. deg;} // vector class var vector = function (size, fx) {var cstrct = this. constructor; this. size = size; this. face = fx | new face (0); fx = this. face; this. toHv = function () {var h = new cstrct (Math. sin (fx. rad) * size, 90); var v = new cstrct (Math. cos (fx. rad) * size, 0); return [h, v] ;}// inheritance, obj: object to be inherited from the vector, arg: arguments vector. extend = function (obj, arg) {vector. apply (obj, arg);} // vector merge method vector. merger = function (arrvector) {if (arguments. length> 1) arrvector = arguments; var cstrct = arrvector [0]. constructor; var I = 0, ilav = arrvector. length; var sum = [0, 0]; for (; I
= M) {self. rigid. rotate (new face (0), self. axis); clearTimeout (tid); I =-m; if (fun) fun (); return;} var f = new face (y, 'rad '); self. rigid. rotate (f, axis = self. axis); I + = fm; tid = setTimeout (function () {self. swing. call (self, o, fun)}, t);} this. moveTo = function (p) {self. body. style. left = p. x + "px"; self. body. style. top = p. y + "px" ;}}// world None. world = function (param) {// param: {force: [multiple force objects]} this. param = param | {}; th Is. config = {// Global External Force g: new a (G), className: '', width: '000000', height: '000000', left: 0, top: -200, arnav: ['about', 'mywork', 'SITE', 'other', 'mytool'], imgW: 60, imgN: 5, sDeg: 5, hitSound: 'Sounds/hit.wav ', vol: 0.1} this. init () ;}; None. world. prototype = {// initialize dom: {}, init: function () {var c = this. config; var p = this. param; // dom var dom = document. createElement ("p"); dom. className = c. className; dom. style. positio N = "absolute"; dom. style. width = p. width | c. width; dom. style. height = p. height | c. height; dom. style. left = (p. left | c. left) + "px"; dom. style. top = (p. top | c. top) + "px"; this. dom = dom; document. body. appendChild (this. dom) ;}, // Add a rigid body addRigid: function (rigid, p) {if (! (Rigid instanceof Array) {rigid = [rigid];} if (! P) p = [point (0, 0)]; if (! (P instanceof Array) p = [p]; for (var I = 0, rl = rigid. length; I
The above is all the content of this article. I hope you will like it. It is helpful for you to learn javascript.