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

Unified Diff: sky/examples/raw/painting.dart

Issue 1188823008: Resurrect painting.sky example as painting.dart. (Closed) Base URL: git@github.com:/domokit/mojo.git@master
Patch Set: as sky Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/examples/raw/painting.dart
diff --git a/sky/examples/raw/painting.dart b/sky/examples/raw/painting.dart
new file mode 100644
index 0000000000000000000000000000000000000000..6b24922fb5064517bae6ae8fa903b285230c0838
--- /dev/null
+++ b/sky/examples/raw/painting.dart
@@ -0,0 +1,91 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+import 'dart:sky' as sky;
+import 'dart:math' as math;
+import 'dart:typed_data';
+
+void beginFrame(double timeStamp) {
+ sky.PictureRecorder context = new sky.PictureRecorder(sky.view.width, 200.0);
+
+ sky.Paint paint = new sky.Paint();
+ sky.Point mid = new sky.Point(context.width / 2.0, context.height / 2.0);
+ double radius = math.min(mid.x, mid.y);
+
+ context.drawPaint(new sky.Paint()..color = const sky.Color(0xFFFFFFFF));
+
+ context.save();
+
+ context.translate(-mid.x/2.0, context.height*2.0);
+ context.clipRect(
+ new sky.Rect.fromLTRB(0.0, -context.height, context.width, radius));
+
+ context.translate(mid.x, mid.y);
+ paint.color = const sky.Color.fromARGB(128, 255, 0, 255);
+ context.rotate(math.PI/4.0);
+
+ sky.Gradient yellowBlue = new sky.Gradient.linear(
+ [new sky.Point(-radius, -radius), new sky.Point(0.0, 0.0)],
+ [const sky.Color(0xFFFFFF00), const sky.Color(0xFF0000FF)]);
+ context.drawRect(new sky.Rect.fromLTRB(-radius, -radius, radius, radius),
+ new sky.Paint()..setShader(yellowBlue));
+
+ // Scale x and y by 0.5.
+ var scaleMatrix = new Float32List.fromList([
+ 0.5, 0.0, 0.0, 0.0,
+ 0.0, 0.5, 0.0, 0.0,
+ 0.0, 0.0, 0.0, 0.0,
+ 0.0, 0.0, 0.0, 1.0,
+ ]);
+ context.concat(scaleMatrix);
+ paint.color = const sky.Color.fromARGB(128, 0, 255, 0);
+ context.drawCircle(0.0, 0.0, radius, paint);
+
+ context.restore();
+
+ context.translate(0.0, 50.0);
+ var builder = new sky.LayerDrawLooperBuilder()
+ ..addLayerOnTop(
+ new sky.DrawLooperLayerInfo()
+ ..setOffset(const sky.Point(150.0, 0.0))
+ ..setColorMode(sky.TransferMode.src)
+ ..setPaintBits(sky.PaintBits.all),
+ (sky.Paint layerPaint) {
+ layerPaint.color = const sky.Color.fromARGB(128, 255, 255, 0);
+ layerPaint.setColorFilter(new sky.ColorFilter.mode(
+ const sky.Color.fromARGB(128, 0, 0, 255), sky.TransferMode.srcIn));
+ layerPaint.setMaskFilter(new sky.MaskFilter.blur(
+ sky.BlurStyle.normal, 3.0, highQuality: true));
+ })
+ ..addLayerOnTop(
+ new sky.DrawLooperLayerInfo()
+ ..setOffset(const sky.Point(75.0, 75.0))
+ ..setColorMode(sky.TransferMode.src)
+ ..setPaintBits(sky.PaintBits.shader),
+ (sky.Paint layerPaint) {
+ sky.Gradient redYellow = new sky.Gradient.radial(
+ new sky.Point(0.0, 0.0), radius/3.0,
+ [const sky.Color(0xFFFFFF00), const sky.Color(0xFFFF0000)],
+ null, sky.TileMode.mirror);
+ layerPaint.setShader(redYellow);
+ // Since we're don't set sky.PaintBits.maskFilter, this has no effect.
+ layerPaint.setMaskFilter(new sky.MaskFilter.blur(
+ sky.BlurStyle.normal, 50.0, highQuality: true));
+ })
+ ..addLayerOnTop(
+ new sky.DrawLooperLayerInfo()..setOffset(const sky.Point(225.0, 75.0)),
+ (sky.Paint layerPaint) {
+ // Since this layer uses a DST color mode, this has no effect.
+ layerPaint.color = const sky.Color.fromARGB(128, 255, 0, 0);
+ });
+ paint.setDrawLooper(builder.build());
+ context.drawCircle(0.0, 0.0, radius, paint);
+
+ sky.view.picture = context.endRecording();
+}
+
+void main() {
+ sky.view.setBeginFrameCallback(beginFrame);
+ sky.view.scheduleFrame();
+}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698