链式反射特效
代码语言:html
所属分类:动画
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title> chain reaction</title> <style> body { font-family: Arial, Helvetica, "Liberation Sans", FreeSans, sans-serif; background-color: #000; margin: 0; padding: 0; border-width: 0; } </style> </head> <body translate="no"> <script> window.addEventListener("load", function () { const gridStep = 40; // grid step (distance between atoms - center to center) const radiusToStepRatio = 0.3; // radius to step ratio, didn't guess ? < 0.5 const activity = 3; // maximum number of atoms destroyed by one particle const atomRadius = gridStep * radiusToStepRatio; let canv, ctx; // canvas and drawing context for atoms let canvP, ctxP; // canvas and drawing context for particles let maxx, maxy; // canvas size let orgx, orgy; // position of the center of top left atom let nbx, nby; // nb of atoms horiz. / vert. let crystal; // matrix of atoms let explosions; // table of disintegrations to come / in progress let endsOfExplosion; // list of elements to be removed from explosions let requestID; // to cancel animation in progress let lRay; // maximum length for particle path let nbEff = 0; // shortcuts for Math functions const mrandom = Math.random; const mfloor = Math.floor; const mround = Math.round; const mceil = Math.ceil; const mtrunc = Math.trunc; const mabs = Math.abs; const mmin = Math.min; const mmax = Math.max; const mPI = Math.PI; const mPIS2 = Math.PI / 2; const m2PI = Math.PI * 2; const msin = Math.sin; const mcos = Math.cos; const matan2 = Math.atan2; const mhypot = Math.hypot; const msqrt = Math.sqrt; //----------------------------------------------------------------------------- // miscellaneous functions //----------------------------------------------------------------------------- function alea(min, max) { /* random float min..max or 0..min if max is undefined min and max are supposed to be numbers, max (if provided) > min */ if (typeof max == 'undefined') return min * mrandom(); return min + (max - min) * mrandom(); } // alea // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - function intAlea(min, max) { /* with 2 parameters : returns random integer min..max - 1 .........完整代码请登录后点击上方下载按钮下载查看
网友评论0