OLD | NEW |
1 var IS_SKV8 = typeof document == "undefined"; | 1 var IS_SKV8 = typeof document == "undefined"; |
| 2 var HAS_PATH = typeof Path != "undefined"; |
2 | 3 |
3 function circlePath(r) { | 4 function circlePath(r) { |
4 if (IS_SKV8) { | 5 if (HAS_PATH) { |
5 var p = new Path(); | 6 var p = new Path(); |
6 p.oval(0, 0, r, r); | 7 p.arc(0, 0, r, 0, 2*Math.PI); |
7 p.closePath(); | 8 p.closePath(); |
8 return p; | 9 return p; |
9 } else { | 10 } else { |
10 return null; | 11 return null; |
11 } | 12 } |
12 } | 13 } |
13 | 14 |
14 var onDraw = function() { | 15 var onDraw = function() { |
15 var W = 500; | 16 var W = 500; |
16 var H = 500; | 17 var H = 500; |
(...skipping 24 matching lines...) Expand all Loading... |
41 p.y += 0.6*p.r; | 42 p.y += 0.6*p.r; |
42 if (p.x > W) { | 43 if (p.x > W) { |
43 p.x-=W; | 44 p.x-=W; |
44 } | 45 } |
45 if (p.x < 0) { | 46 if (p.x < 0) { |
46 p.x += W; | 47 p.x += W; |
47 } | 48 } |
48 if(p.y>(H+1)){ | 49 if(p.y>(H+1)){ |
49 p.y = 0; | 50 p.y = 0; |
50 } | 51 } |
51 if (IS_SKV8) { | 52 if (HAS_PATH) { |
52 ctx.save(); | 53 ctx.save(); |
53 ctx.translate(p.x, p.y); | 54 ctx.translate(p.x, p.y); |
54 ctx.fill(p.path); | 55 ctx.fill(p.path); |
55 ctx.restore(); | 56 ctx.restore(); |
56 } else { | 57 } else { |
57 ctx.beginPath(); | 58 ctx.beginPath(); |
58 ctx.moveTo(p.x, p.y); | 59 ctx.moveTo(p.x, p.y); |
59 ctx.arc(p.x, p.y, p.r, 0, 2*Math.PI, true); | 60 ctx.arc(p.x, p.y, p.r, 0, 2*Math.PI, true); |
60 ctx.closePath(); | 61 ctx.closePath(); |
61 ctx.fill(); | 62 ctx.fill(); |
(...skipping 21 matching lines...) Expand all Loading... |
83 window.onload = function(){ | 84 window.onload = function(){ |
84 var canvas = document.getElementById("snow"); | 85 var canvas = document.getElementById("snow"); |
85 var ctx = canvas.getContext("2d"); | 86 var ctx = canvas.getContext("2d"); |
86 function drawCallback() { | 87 function drawCallback() { |
87 onDraw(ctx); | 88 onDraw(ctx); |
88 setTimeout(drawCallback, 1); | 89 setTimeout(drawCallback, 1); |
89 } | 90 } |
90 setTimeout(drawCallback, 1); | 91 setTimeout(drawCallback, 1); |
91 } | 92 } |
92 } | 93 } |
| 94 |
| 95 console.log("HAS_PATH: " + HAS_PATH); |
OLD | NEW |