这两天去图书馆借了几本书,准备去实习了,所以打算看点书,就顺便把javascript高效图形
>
Fast Sine Demonstration <script type='text/javascript' src='http:libs.baidu.com/jquery/1.9.0/jquery.js'>《script》 <script type='text/javascript'> $(document).ready(function(){ (function(){ var fastSin = function(steps){ var table = [], ang = 0, angStep = (Math.PI * 2) / steps; do{ table.push(Math.sin(ang)); ang += angStep; }while(ang < Math.PI * 2); return table; }; var sinTable = fastSin(4096); var $drawTarget = $('#draw-target'), divs = '', i, bars, x = 0; // 使一个点按正玄曲线波动 var drawGrap = function(ang, freq, height){ var height2 = height * 2; for(var i = 0; i < 480; i++){ bars[i].style.top = 160 - height + sinTable[(ang + (i * freq)) & 4095] * height + 'px'; bars[i].style.height = height2 + 'px'; } }; for(i = 0; i < 480; i++){ divs += '
'; } $drawTarget.append(divs); bars = $drawTarget.children(); var time = setInterval(function(){ drawGrap(x * 50, 32 - (sinTable[(x * 20) & 4095] * 16), 50 - (sinTable[(x * 10) & 4095] * 20)); x++; }, 20); })(); }); 《script》