Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: experimental/SkV8Example/snow.js

Issue 143743004: Both gears and snow should detect if Path is available, and also report on the console if present. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « experimental/SkV8Example/gears.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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);
OLDNEW
« no previous file with comments | « experimental/SkV8Example/gears.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698