| OLD | NEW |
| (Empty) |
| 1 <sky> | |
| 2 <style> | |
| 3 div { | |
| 4 height: 200px; | |
| 5 background-color: lightblue; | |
| 6 } | |
| 7 </style> | |
| 8 <div id="canvas" /> | |
| 9 <script> | |
| 10 import 'dart:math' as math; | |
| 11 import 'dart:typed_data'; | |
| 12 import 'dart:sky'; | |
| 13 | |
| 14 void main() { | |
| 15 var element = document.getElementById('canvas'); | |
| 16 element.requestPaint((PaintingContext context) { | |
| 17 Paint paint = new Paint(); | |
| 18 Point mid = new Point(context.width / 2.0, context.height / 2.0); | |
| 19 double radius = math.min(mid.x, mid.y); | |
| 20 | |
| 21 context.save(); | |
| 22 | |
| 23 context.clipRect(new Rect.fromLTRB(0.0, 0.0, context.width, radius)); | |
| 24 | |
| 25 context.translate(mid.x, mid.y); | |
| 26 paint.color = const Color.fromARGB(128, 255, 0, 255); | |
| 27 context.rotate(math.PI/4.0); | |
| 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 context.drawRect(new Rect.fromLTRB(-radius, -radius, radius, radius), | |
| 33 new Paint()..setShader(yellowBlue)); | |
| 34 | |
| 35 // Scale x and y by 0.5. | |
| 36 var scaleMatrix = new Float32List.fromList([ | |
| 37 0.5, 0.0, 0.0, 0.0, | |
| 38 0.0, 0.5, 0.0, 0.0, | |
| 39 0.0, 0.0, 0.0, 0.0, | |
| 40 0.0, 0.0, 0.0, 1.0, | |
| 41 ]); | |
| 42 context.concat(scaleMatrix); | |
| 43 paint.color = const Color.fromARGB(128, 0, 255, 0); | |
| 44 context.drawCircle(0.0, 0.0, radius, paint); | |
| 45 | |
| 46 context.restore(); | |
| 47 | |
| 48 context.translate(0.0, 50.0); | |
| 49 var builder = new LayerDrawLooperBuilder() | |
| 50 ..addLayerOnTop( | |
| 51 new DrawLooperLayerInfo() | |
| 52 ..setOffset(const Point(150.0, 0.0)) | |
| 53 ..setColorMode(TransferMode.srcMode) | |
| 54 ..setPaintBits(PaintBits.all), | |
| 55 (Paint layerPaint) { | |
| 56 layerPaint.color = const Color.fromARGB(128, 255, 255, 0); | |
| 57 layerPaint.setColorFilter( | |
| 58 new ColorFilter.mode(const Color.fromARGB(128, 0, 0, 255), | |
| 59 TransferMode.srcInMode)); | |
| 60 layerPaint.setMaskFilter( | |
| 61 new MaskFilter.blur(BlurStyle.normal, 3.0, highQuality: true)); | |
| 62 }) | |
| 63 ..addLayerOnTop( | |
| 64 new DrawLooperLayerInfo() | |
| 65 ..setOffset(const Point(75.0, 75.0)) | |
| 66 ..setColorMode(TransferMode.srcMode) | |
| 67 ..setPaintBits(PaintBits.shader), | |
| 68 (Paint layerPaint) { | |
| 69 Gradient redYellow = new Gradient.radial( | |
| 70 new Point(0.0, 0.0), radius/3.0, | |
| 71 [const Color(0xFFFFFF00), const Color(0xFFFF0000)], | |
| 72 null, TileMode.mirror); | |
| 73 layerPaint.setShader(redYellow); | |
| 74 // Since we're don't set PaintBits.maskFilter, this has no effect. | |
| 75 layerPaint.setMaskFilter( | |
| 76 new MaskFilter.blur(BlurStyle.normal, 50.0, highQuality: true)); | |
| 77 }) | |
| 78 ..addLayerOnTop( | |
| 79 new DrawLooperLayerInfo()..setOffset(const Point(225.0, 75.0)), | |
| 80 (Paint layerPaint) { | |
| 81 // Since this layer uses a DST color mode, this has no effect. | |
| 82 layerPaint.color = const Color.fromARGB(128, 255, 0, 0); | |
| 83 }); | |
| 84 paint.setDrawLooper(builder.build()); | |
| 85 context.drawCircle(0.0, 0.0, radius, paint); | |
| 86 | |
| 87 context.commit(); | |
| 88 }); | |
| 89 } | |
| 90 </script> | |
| 91 </sky> | |
| OLD | NEW |