1cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.orgvar IS_SKV8 = typeof document == "undefined"; 2f679d1bf38a9e319c2b38fa53852f05b7f246e8ecommit-bot@chromium.orgvar HAS_PATH = typeof Path2D != "undefined"; 3cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org 4cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.orgfunction circlePath(r) { 5c896f4de12a8bb5c2404f03e5be9089fe3f2c7bdcommit-bot@chromium.org if (HAS_PATH) { 6f679d1bf38a9e319c2b38fa53852f05b7f246e8ecommit-bot@chromium.org var p = new Path2D(); 7c896f4de12a8bb5c2404f03e5be9089fe3f2c7bdcommit-bot@chromium.org p.arc(0, 0, r, 0, 2*Math.PI); 8cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org p.closePath(); 9cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org return p; 10cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org } else { 11cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org return null; 12cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org } 13cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org} 14cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org 15cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.orgvar onDraw = function() { 16cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org var W = 500; 17cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org var H = 500; 18cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org var NumParticles = 100; 19cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org 20cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org var angle = 0; 21cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org var ticks = 0; 22cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org var particles =[]; 23cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org 24cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org for (var i = 0; i < NumParticles; i++) { 25cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org particles[i] = { 26cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org x: Math.floor(Math.random()*W), 27cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org y: Math.floor(Math.random()*H), 28cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org r: Math.floor(Math.random()*7+1), 29cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org path: circlePath(Math.random()*7+1), 30cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org } 31cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org } 32cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org 33cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org function draw(ctx) { 34cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org ctx.fillStyle = "#ADD8E6"; 35cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org ctx.fillRect(0, 0, W-1, H-1); 36cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org ctx.fillStyle = "#FFFFFF"; 37cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org 38cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org angle += 0.0039; 39cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org for (var i = 0; i < particles.length; i++) { 40cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org var p = particles[i]; 41cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org p.x += Math.floor(Math.sin(angle)*5.0); 42cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org p.y += 0.6*p.r; 43cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org if (p.x > W) { 44cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org p.x-=W; 45cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org } 46cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org if (p.x < 0) { 47cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org p.x += W; 48cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org } 49cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org if(p.y>(H+1)){ 50cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org p.y = 0; 51cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org } 52c896f4de12a8bb5c2404f03e5be9089fe3f2c7bdcommit-bot@chromium.org if (HAS_PATH) { 53cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org ctx.save(); 54cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org ctx.translate(p.x, p.y); 55cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org ctx.fill(p.path); 56cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org ctx.restore(); 57cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org } else { 58cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org ctx.beginPath(); 59cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org ctx.moveTo(p.x, p.y); 60cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org ctx.arc(p.x, p.y, p.r, 0, 2*Math.PI, true); 61cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org ctx.closePath(); 62cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org ctx.fill(); 63cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org } 64cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org }; 65cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org 66cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org ticks++; 67cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org if (IS_SKV8) { 68cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org inval(); 69cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org } 70cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org } 71cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org 72cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org function fps() { 73cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org console.log(ticks); 74cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org ticks = 0; 75cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org setTimeout(fps, 1000); 76cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org } 77cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org 78cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org setTimeout(fps, 1000); 79cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org 80cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org return draw; 81cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org}(); 82cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org 83cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.orgif (!IS_SKV8) { 84cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org window.onload = function(){ 85cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org var canvas = document.getElementById("snow"); 86cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org var ctx = canvas.getContext("2d"); 87cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org function drawCallback() { 88cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org onDraw(ctx); 89cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org setTimeout(drawCallback, 1); 90cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org } 91cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org setTimeout(drawCallback, 1); 92cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org } 93cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org} 94c896f4de12a8bb5c2404f03e5be9089fe3f2c7bdcommit-bot@chromium.org 95c896f4de12a8bb5c2404f03e5be9089fe3f2c7bdcommit-bot@chromium.orgconsole.log("HAS_PATH: " + HAS_PATH); 96