OLD | NEW |
1 /** | 1 /** |
2 * @fileoverview Sample onDraw script for use with SkV8Example. | 2 * @fileoverview Sample onDraw script for use with SkV8Example. |
3 */ | 3 */ |
4 var onDraw = function(){ | 4 var onDraw = function(){ |
5 var p = new Path(); | 5 var p = new Path2D(); |
6 p.moveTo(0, 0); | 6 p.moveTo(0, 0); |
7 p.bezierCurveTo(0, 100, 100, 0, 200, 200); | 7 p.bezierCurveTo(0, 100, 100, 0, 200, 200); |
8 p.close(); | 8 p.close(); |
9 p.moveTo(0, 300); | 9 p.moveTo(0, 300); |
10 p.arc(0, 300, 40, Math.PI/2, 3/2*Math.PI); | 10 p.arc(0, 300, 40, Math.PI/2, 3/2*Math.PI); |
11 function f(context) { | 11 function f(context) { |
12 context.translate(10, 10); | 12 context.translate(10, 10); |
13 for (var i=0; i<256; i++) { | 13 for (var i=0; i<256; i++) { |
14 context.strokeStyle = '#0000' + toHex(i); | 14 context.strokeStyle = '#0000' + toHex(i); |
15 context.stroke(p); | 15 context.stroke(p); |
16 context.translate(1, 0); | 16 context.translate(1, 0); |
17 } | 17 } |
18 context.fillStyle = '#ff0000'; | 18 context.fillStyle = '#ff0000'; |
19 print(context.width, context.height); | 19 print(context.width, context.height); |
20 context.resetTransform(); | 20 context.resetTransform(); |
21 context.fillRect(context.width/2, context.height/2, 20, 20); | 21 context.fillRect(context.width/2, context.height/2, 20, 20); |
22 }; | 22 }; |
23 return f; | 23 return f; |
24 }(); | 24 }(); |
25 | 25 |
26 | 26 |
27 function toHex(n) { | 27 function toHex(n) { |
28 var s = n.toString(16); | 28 var s = n.toString(16); |
29 if (s.length == 1) { | 29 if (s.length == 1) { |
30 s = "0" + s; | 30 s = "0" + s; |
31 } | 31 } |
32 return s; | 32 return s; |
33 } | 33 } |
OLD | NEW |