OLD | NEW |
1 <sky> | 1 <sky> |
2 <style> | 2 <style> |
3 div { | 3 div { |
4 height: 200px; | 4 height: 200px; |
5 background-color: lightblue; | 5 background-color: lightblue; |
6 } | 6 } |
7 </style> | 7 </style> |
8 <div id="canvas" /> | 8 <div id="canvas" /> |
9 <script> | 9 <script> |
10 import 'dart:math' as math; | 10 import 'dart:math' as math; |
11 import 'dart:typed_data'; | 11 import 'dart:typed_data'; |
12 import 'dart:sky'; | 12 import 'dart:sky'; |
13 | 13 |
14 void main() { | 14 void main() { |
15 var element = document.getElementById('canvas'); | 15 var element = document.getElementById('canvas'); |
16 element.requestPaint((PaintingContext context) { | 16 element.requestPaint((PaintingContext context) { |
17 Paint paint = new Paint(); | 17 Paint paint = new Paint(); |
18 Point mid = new Point(context.width / 2.0, context.height / 2.0); | 18 Point mid = new Point(context.width / 2.0, context.height / 2.0); |
19 double radius = math.min(mid.x, mid.y); | 19 double radius = math.min(mid.x, mid.y); |
20 | 20 |
21 context.save(); | 21 context.save(); |
22 | 22 |
23 context.clipRect(new Rect.fromLTRB(0.0, 0.0, context.width, radius)); | 23 context.clipRect(new Rect.fromLTRB(0.0, 0.0, context.width, radius)); |
24 | 24 |
25 context.translate(mid.x, mid.y); | 25 context.translate(mid.x, mid.y); |
26 paint.color = const Color.fromARGB(128, 255, 0, 255); | 26 paint.color = const Color.fromARGB(128, 255, 0, 255); |
27 context.rotateDegrees(45.0); | 27 context.rotateDegrees(45.0); |
28 | 28 |
| 29 Gradient yellowBlue = new Gradient.Linear( |
| 30 [new Point(-radius, -radius), new Point(0.0, 0.0)], |
| 31 [const Color(0xFFFFFF00), const Color(0xFF0000FF)], |
| 32 null); |
29 context.drawRect(new Rect.fromLTRB(-radius, -radius, radius, radius), | 33 context.drawRect(new Rect.fromLTRB(-radius, -radius, radius, radius), |
30 paint); | 34 new Paint()..setShader(yellowBlue)); |
31 | 35 |
32 // Scale x and y by 0.5. | 36 // Scale x and y by 0.5. |
33 var scaleMatrix = new Float32List.fromList([ | 37 var scaleMatrix = new Float32List.fromList([ |
34 0.5, 0.0, 0.0, 0.0, | 38 0.5, 0.0, 0.0, 0.0, |
35 0.0, 0.5, 0.0, 0.0, | 39 0.0, 0.5, 0.0, 0.0, |
36 0.0, 0.0, 0.0, 0.0, | 40 0.0, 0.0, 0.0, 0.0, |
37 0.0, 0.0, 0.0, 1.0, | 41 0.0, 0.0, 0.0, 1.0, |
38 ]); | 42 ]); |
39 context.concat(scaleMatrix); | 43 context.concat(scaleMatrix); |
40 paint.color = const Color.fromARGB(128, 0, 255, 0); | 44 paint.color = const Color.fromARGB(128, 0, 255, 0); |
(...skipping 30 matching lines...) Expand all Loading... |
71 layerPaint.color = const Color.fromARGB(128, 255, 0, 0); | 75 layerPaint.color = const Color.fromARGB(128, 255, 0, 0); |
72 }); | 76 }); |
73 paint.setDrawLooper(builder.build()); | 77 paint.setDrawLooper(builder.build()); |
74 context.drawCircle(0.0, 0.0, radius, paint); | 78 context.drawCircle(0.0, 0.0, radius, paint); |
75 | 79 |
76 context.commit(); | 80 context.commit(); |
77 }); | 81 }); |
78 } | 82 } |
79 </script> | 83 </script> |
80 </sky> | 84 </sky> |
OLD | NEW |